From 6a50ffd88a306bbb8c8c162ea7eed04e3443f909 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 30 Jun 2026 23:22:28 +0100 Subject: [PATCH] Use stdlib http.ServeMux instead of chi in cleanup_test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cleanup command test builds a self-contained mock HTTP server with only static routes (and {id} patterns read via r.URL.Path, not URLParam), so chi.NewRouter is unnecessary — http.NewServeMux (Go 1.22 routing) covers it. Independent of the main router; drops the chi import from app/cmd. go test -race and golangci-lint clean. --- backend/app/cmd/cleanup_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/app/cmd/cleanup_test.go b/backend/app/cmd/cleanup_test.go index f4145332..6e760c74 100644 --- a/backend/app/cmd/cleanup_test.go +++ b/backend/app/cmd/cleanup_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/go-chi/chi/v5" "github.com/jessevdk/go-flags" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -58,7 +57,7 @@ func TestCleanup_IsSpam(t *testing.T) { } func TestCleanup_postsInRange(t *testing.T) { - r := chi.NewRouter() + r := http.NewServeMux() cleanupRoutes(t, r, nil) ts := httptest.NewServer(r) defer ts.Close() @@ -81,7 +80,7 @@ func TestCleanup_postsInRange(t *testing.T) { } func TestCleanup_listComments(t *testing.T) { - r := chi.NewRouter() + r := http.NewServeMux() cleanupRoutes(t, r, nil) ts := httptest.NewServer(r) defer ts.Close() @@ -107,7 +106,7 @@ func TestCleanup_listComments(t *testing.T) { func TestCleanup_ExecuteSpam(t *testing.T) { cleaned := cleanedComments{} - r := chi.NewRouter() + r := http.NewServeMux() cleanupRoutes(t, r, &cleaned) ts := httptest.NewServer(r) defer ts.Close() @@ -126,7 +125,7 @@ func TestCleanup_ExecuteSpam(t *testing.T) { func TestCleanup_ExecuteTitle(t *testing.T) { titledComments := cleanedComments{} - r := chi.NewRouter() + r := http.NewServeMux() cleanupRoutes(t, r, &titledComments) ts := httptest.NewServer(r) defer ts.Close() @@ -142,7 +141,7 @@ func TestCleanup_ExecuteTitle(t *testing.T) { assert.Equal(t, []string{"/api/v1/admin/title/1", "/api/v1/admin/title/2", "/api/v1/admin/title/3", "/api/v1/admin/title/11"}, titledComments.ids) } -func cleanupRoutes(t *testing.T, r *chi.Mux, c *cleanedComments) { +func cleanupRoutes(t *testing.T, r *http.ServeMux, c *cleanedComments) { r.HandleFunc("/api/v1/list", func(w http.ResponseWriter, r *http.Request) { require.Equal(t, "GET", r.Method) require.Equal(t, "site=remark&limit=10000", r.URL.RawQuery)