This commit is contained in:
2026-10-15 00:13:06 -04:00
commit 097bfc0357
5 changed files with 178 additions and 0 deletions

56
main_test.go Normal file
View File

@@ -0,0 +1,56 @@
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestRedirectHandler(t *testing.T) {
targetURL := "https://venueaxe.com"
tests := []struct {
name string
requestPath string
}{
{
name: "Root request",
requestPath: "/",
},
{
name: "Nested path request",
requestPath: "/venues/123",
},
{
name: "Query params request",
requestPath: "/search?q=concert&location=nyc",
},
{
name: "Arbitrary sub-path with query",
requestPath: "/a/b/c/d?token=xyz#hash",
},
}
handler := redirectHandler(targetURL)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, tt.requestPath, nil)
w := httptest.NewRecorder()
handler(w, req)
resp := w.Result()
defer resp.Body.Close()
if resp.StatusCode != http.StatusMovedPermanently {
t.Fatalf("expected status %d, got %d", http.StatusMovedPermanently, resp.StatusCode)
}
location := resp.Header.Get("Location")
if location != targetURL {
t.Errorf("expected redirect location %q, got %q", targetURL, location)
}
})
}
}