From 435047ad0c25cc268d55ae78e1b86a9e3bbff6a8 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sat, 29 Nov 2025 14:58:37 +0100 Subject: [PATCH] refactor: clean code --- ...ession_static_metadata_integration_test.go | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/integration/compression_static_metadata_integration_test.go b/internal/integration/compression_static_metadata_integration_test.go index 82a1bf0..5c5edc2 100644 --- a/internal/integration/compression_static_metadata_integration_test.go +++ b/internal/integration/compression_static_metadata_integration_test.go @@ -21,14 +21,14 @@ func TestIntegration_Compression(t *testing.T) { t.Run("Response_Compression_Gzip", func(t *testing.T) { req := httptest.NewRequest("GET", "/api/posts", nil) req.Header.Set("Accept-Encoding", "gzip") - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - contentEncoding := rec.Header().Get("Content-Encoding") + contentEncoding := recorder.Header().Get("Content-Encoding") if contentEncoding != "" && strings.Contains(contentEncoding, "gzip") { - assertHeaderContains(t, rec, "Content-Encoding", "gzip") - reader, err := gzip.NewReader(rec.Body) + assertHeaderContains(t, recorder, "Content-Encoding", "gzip") + reader, err := gzip.NewReader(recorder.Body) if err != nil { t.Fatalf("Failed to create gzip reader: %v", err) } @@ -50,12 +50,12 @@ func TestIntegration_Compression(t *testing.T) { t.Run("Compression_Headers_Present", func(t *testing.T) { req := httptest.NewRequest("GET", "/api/posts", nil) req.Header.Set("Accept-Encoding", "gzip, deflate") - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - if rec.Header().Get("Vary") != "" { - assertHeaderContains(t, rec, "Vary", "Accept-Encoding") + if recorder.Header().Get("Vary") != "" { + assertHeaderContains(t, recorder, "Vary", "Accept-Encoding") } else { t.Log("Vary header may not always be present") } @@ -68,24 +68,24 @@ func TestIntegration_StaticFiles(t *testing.T) { t.Run("Robots_Txt_Served", func(t *testing.T) { req := httptest.NewRequest("GET", "/robots.txt", nil) - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - assertStatus(t, rec, http.StatusOK) + assertStatus(t, recorder, http.StatusOK) - if !strings.Contains(rec.Body.String(), "User-agent") { + if !strings.Contains(recorder.Body.String(), "User-agent") { t.Error("Expected robots.txt content") } }) t.Run("Static_Files_Security_Headers", func(t *testing.T) { req := httptest.NewRequest("GET", "/robots.txt", nil) - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - if rec.Header().Get("X-Content-Type-Options") == "" { + if recorder.Header().Get("X-Content-Type-Options") == "" { t.Log("Security headers may not be applied to all static files") } }) @@ -111,22 +111,22 @@ func TestIntegration_URLMetadata(t *testing.T) { req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+user.Token) req = testutils.WithUserContext(req, middleware.UserIDKey, user.User.ID) - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - assertStatus(t, rec, http.StatusCreated) + assertStatus(t, recorder, http.StatusCreated) }) t.Run("URL_Metadata_Endpoint", func(t *testing.T) { ctx.Suite.TitleFetcher.SetTitle("Endpoint Title") req := httptest.NewRequest("GET", "/api/posts/title?url=https://example.com/test", nil) - rec := httptest.NewRecorder() + recorder := httptest.NewRecorder() - router.ServeHTTP(rec, req) + router.ServeHTTP(recorder, req) - response := assertJSONResponse(t, rec, http.StatusOK) + response := assertJSONResponse(t, recorder, http.StatusOK) if response != nil { if data, ok := response["data"].(map[string]any); ok { if _, exists := data["title"]; !exists {