From 0b084f44ae5e9f6a67bdaf86c303e0e20607565f Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 7 Dec 2023 10:37:05 -0600 Subject: [PATCH] cleanup handlers directory --- .gitignore | 1 + handlers/api.test.go | 44 ------------------ handlers/api_modifiers.go | 1 + handlers/{raw.go => api_raw.go} | 0 handlers/{ruleset.go => api_ruleset.go} | 0 handlers/raw.test.go | 60 ------------------------- 6 files changed, 2 insertions(+), 104 deletions(-) delete mode 100644 handlers/api.test.go create mode 100644 handlers/api_modifiers.go rename handlers/{raw.go => api_raw.go} (100%) rename handlers/{ruleset.go => api_ruleset.go} (100%) delete mode 100644 handlers/raw.test.go diff --git a/.gitignore b/.gitignore index 1e89ed7..f943b08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # dev binary ladder tmp/main +tmp VERSION output.css diff --git a/handlers/api.test.go b/handlers/api.test.go deleted file mode 100644 index 710a0b2..0000000 --- a/handlers/api.test.go +++ /dev/null @@ -1,44 +0,0 @@ -// BEGIN: 7d5e1f7c7d5e -package handlers - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/gofiber/fiber/v2" - "github.com/stretchr/testify/assert" -) - -func TestApi(t *testing.T) { - app := fiber.New() - app.Get("/api/*", Api) - - tests := []struct { - name string - url string - expectedStatus int - }{ - { - name: "valid url", - url: "https://www.google.com", - expectedStatus: http.StatusOK, - }, - { - name: "invalid url", - url: "invalid-url", - expectedStatus: http.StatusBadRequest, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - req := httptest.NewRequest(http.MethodGet, "/api/"+tt.url, nil) - resp, err := app.Test(req) - assert.NoError(t, err) - assert.Equal(t, tt.expectedStatus, resp.StatusCode) - }) - } -} - -// END: 7d5e1f7c7d5e diff --git a/handlers/api_modifiers.go b/handlers/api_modifiers.go new file mode 100644 index 0000000..5ac8282 --- /dev/null +++ b/handlers/api_modifiers.go @@ -0,0 +1 @@ +package handlers diff --git a/handlers/raw.go b/handlers/api_raw.go similarity index 100% rename from handlers/raw.go rename to handlers/api_raw.go diff --git a/handlers/ruleset.go b/handlers/api_ruleset.go similarity index 100% rename from handlers/ruleset.go rename to handlers/api_ruleset.go diff --git a/handlers/raw.test.go b/handlers/raw.test.go deleted file mode 100644 index 0fd96b6..0000000 --- a/handlers/raw.test.go +++ /dev/null @@ -1,60 +0,0 @@ -// BEGIN: 7f8d9e6d4b5c -package handlers - -import ( - "io" - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/gofiber/fiber/v2" -) - -func TestRaw(t *testing.T) { - app := fiber.New() - app.Get("/raw/*", NewRawProxySiteHandler(nil)) - - testCases := []struct { - name string - url string - expected string - }{ - { - name: "valid url", - url: "https://www.google.com", - expected: "", - }, - { - name: "invalid url", - url: "invalid-url", - expected: "parse invalid-url: invalid URI for request", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - req := httptest.NewRequest(http.MethodGet, "/raw/"+tc.url, nil) - resp, err := app.Test(req) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - t.Errorf("expected status OK; got %v", resp.Status) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - if !strings.Contains(string(body), tc.expected) { - t.Errorf("expected body to contain %q; got %q", tc.expected, string(body)) - } - }) - } -} - -// END: 7f8d9e6d4b5c