package handlers_test import ( "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" ) // TestRenderTemplateBuffersOutput verifies that successful template rendering // produces a complete HTML response (not partial/corrupt). func TestRenderTemplateBuffersOutput(t *testing.T) { t.Parallel() testCtx := setupTestHandlers(t) // The setup page is simple and has no DB dependencies request := httptest.NewRequest(http.MethodGet, "/setup", nil) recorder := httptest.NewRecorder() handler := testCtx.handlers.HandleSetupGET() handler.ServeHTTP(recorder, request) assert.Equal(t, http.StatusOK, recorder.Code) body := recorder.Body.String() // A properly buffered response should contain the closing tag, // proving the full template was rendered before being sent. assert.Contains(t, body, "") // Should NOT contain the error text that would be appended on failure assert.NotContains(t, body, "Internal Server Error") } // TestDashboardRenderTemplateBuffersOutput verifies the dashboard handler // also uses buffered template rendering. func TestDashboardRenderTemplateBuffersOutput(t *testing.T) { t.Parallel() testCtx := setupTestHandlers(t) request := httptest.NewRequest(http.MethodGet, "/", nil) recorder := httptest.NewRecorder() handler := testCtx.handlers.HandleDashboard() handler.ServeHTTP(recorder, request) assert.Equal(t, http.StatusOK, recorder.Code) body := recorder.Body.String() assert.Contains(t, body, "") assert.NotContains(t, body, "Internal Server Error") } // TestLoginRenderTemplateBuffersOutput verifies the login handler // uses buffered template rendering. func TestLoginRenderTemplateBuffersOutput(t *testing.T) { t.Parallel() testCtx := setupTestHandlers(t) request := httptest.NewRequest(http.MethodGet, "/login", nil) recorder := httptest.NewRecorder() handler := testCtx.handlers.HandleLoginGET() handler.ServeHTTP(recorder, request) assert.Equal(t, http.StatusOK, recorder.Code) body := recorder.Body.String() assert.Contains(t, body, "") assert.NotContains(t, body, "Internal Server Error") }