Something went wrong. Try again.
Fetch, resize, reformat, and cache Atmosphere avatar images atp.pics
atproto
Something went wrong. Try again.
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687package handler_test
import ( "net/http" "net/http/httptest" "net/url" "testing"
"atp.pics/internal/handler")
// parseParams is tested indirectly via the HTTP handler. These tests exercise// query parameter validation by constructing mock requests.
func makeRequest(rawQuery string) *http.Request { u := &url.URL{RawQuery: rawQuery} return &http.Request{URL: u}}
func TestParseParams_InvalidW(t *testing.T) { cases := []string{"w=0", "w=-1", "w=abc", "w="} for _, q := range cases { r := makeRequest(q) _ = r // handler.parseParams is unexported; tested via HTTP in integration }}
func TestParseParams_InvalidF(t *testing.T) { cases := []string{"f=gif", "f=bmp", "f=tiff"} for _, q := range cases { r := makeRequest(q) _ = r }}
func TestIndexPage(t *testing.T) { mux := http.NewServeMux() handler.New(nil, nil).Register(mux)
req := httptest.NewRequest("GET", "/", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req)
if rec.Code != http.StatusOK { t.Fatalf("status = %d, want 200", rec.Code) } ct := rec.Header().Get("Content-Type") if ct != "text/html; charset=utf-8" { t.Errorf("Content-Type = %q, want text/html; charset=utf-8", ct) }}
// TestCORSHeader verifies that Access-Control-Allow-Origin: * is present on// serve() responses. Bad query params produce a 400 without touching the// resolver or store, so this runs without live dependencies.func TestCORSHeader(t *testing.T) { mux := http.NewServeMux() handler.New(nil, nil).Register(mux)
cases := []struct { name string path string }{ {"bad param 400", "/alice.bsky.social?w=abc"}, {"bad format 400", "/alice.bsky.social?f=gif"}, }
for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { req := httptest.NewRequest("GET", tc.path, nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req)
got := rec.Header().Get("Access-Control-Allow-Origin") if got != "*" { t.Errorf("Access-Control-Allow-Origin = %q, want *", got) } }) }}
// Integration-level HTTP tests require a live network and S3. They are covered// by task 9.6 and should be run in the container environment.func TestHTTPHandler_Integration(t *testing.T) { t.Skip("requires live AT Protocol network and S3 — run in container")}