package inbox import ( "bytes" "context" "net/http" "net/http/httptest" "net/url" "strings" "testing" "time" ) func TestServer(t *testing.T) { handler := Server{CORS: true, Mailboxes: New(), MaxBodySize: 1 * 1024 * 1024} t.Run("GET", func(t *testing.T) { t.Run("without authorization", func(t *testing.T) { rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/inbox", nil) if err != nil { t.Fatal(err) } handler.ServeHTTP(rr, req) if status := rr.Code; status != http.StatusUnauthorized { t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusUnauthorized) } if header := rr.HeaderMap.Get("WWW-Authenticate"); header != "Basic" { t.Errorf("handler returned unexpected WWW-Authenticate header: got %v wanted Basic", header) } if rr.Body.String() != "" { t.Errorf("handler returned unexpected body: got %v wanted empty string", rr.Body.String()) } }) t.Run("wrong body format", func(t *testing.T) { rr := httptest.NewRecorder() req, err := http.NewRequest("GET", "/inbox", nil) req.URL.RawQuery = "someWeird%