package e2e import ( "context" "net/http" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/config" ) // probe fetches a path with no key, as a load balancer would. func probe(t *testing.T, url string) int { t.Helper() req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) if err != nil { t.Fatal(err) } resp, err := http.DefaultClient.Do(req) if err != nil { t.Fatal(err) } defer resp.Body.Close() return resp.StatusCode } func TestReadinessMeansSomethingHealthDoesNot(t *testing.T) { // A standby control plane is up, answers /health, and has no endpoints — // its reconciler placed nothing and it holds no agent streams to adopt // from. A load balancer checking /health would send it half the traffic, // and half the traffic would be a 503. h := start(t, 2) if code := probe(t, h.router.URL+"/health"); code != http.StatusOK { t.Errorf("/health with endpoints = %d", code) } if code := probe(t, h.router.URL+"/ready"); code != http.StatusOK { t.Errorf("/ready with endpoints = %d", code) } } func TestWithNothingToServeReadyRefusesAndHealthDoesNot(t *testing.T) { // The case the endpoint exists for. Both are true statements: the process // is alive, and it cannot serve. h := start(t, 0, func(c *config.Server) { c.Endpoints = nil }) if code := probe(t, h.router.URL+"/health"); code != http.StatusOK { t.Errorf("/health on a live process with no endpoints = %d, want 200", code) } if code := probe(t, h.router.URL+"/ready"); code != http.StatusServiceUnavailable { t.Errorf("/ready with nothing to serve = %d, want 503", code) } } func TestBothProbesWorkWithoutAKey(t *testing.T) { // A load balancer does not have one, and an endpoint it cannot reach is // an endpoint that reports every gateway as down. path, mint := provision(t) _ = mint(t, "somebody") h := start(t, 2, paidConfig(path)) for _, p := range []string{"/health", "/ready"} { if code := probe(t, h.router.URL+p); code != http.StatusOK { t.Errorf("%s on an authenticated gateway = %d", p, code) } } }