package main import ( "net/http" "net/http/httptest" "testing" ) func TestRoutes(t *testing.T) { srv := httptest.NewServer(newMux()) defer srv.Close() for path, want := range map[string]int{"/healthz": 200, "/api/hello": 200, "/nope": 404} { resp, err := http.Get(srv.URL + path) if err != nil { t.Fatal(err) } resp.Body.Close() if resp.StatusCode != want { t.Errorf("%s = %d, want %d", path, resp.StatusCode, want) } } }