package api_test import ( "context" "io" "net/http" "net/http/httptest" "strings" "testing" "time" ) // page fetches path and returns the final status, path and body. func (b *browser) page(path string) (int, string, string) { b.t.Helper() resp, err := b.hc.Get(b.base + path) if err != nil { b.t.Fatalf("GET %s failed: %v", path, err) } defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) return resp.StatusCode, resp.Request.URL.Path, string(body) } func TestConsolePages(t *testing.T) { e := newEnv(t) ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) go e.api.RunScheduler(ctx) target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadGateway) })) defer target.Close() tok, region := e.platformChecker(t, uniq("eu-")) e.startChecker(t, tok) owner := e.browser(t) owner.signup("o@"+uniq("p")+".test", uniq("pages-")) st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{ "name": "Checkout API", "type": "http", "target": target.URL, "interval_seconds": 60, "confirmations": 1, "regions": []string{region}, "config": map[string]any{"keyword": "ok"}, }) if st != http.StatusCreated { t.Fatalf("create monitor = %d %v", st, body) } id := body["id"].(string) waitFor(t, 10*time.Second, "incident opened", func() bool { _, body := owner.do("GET", "/api/v1/org/incidents", nil) return len(body["incidents"].([]any)) == 1 }) owner.do("POST", "/api/v1/org/channels", map[string]any{"name": "Hook", "type": "webhook", "url": "https://hooks.example.test/x"}) pages := map[string][]string{ "/": {"Checkout API", "