package main import ( "encoding/json" "net/http" "net/http/httptest" "testing" ) func TestWorkerStatusReportsRecoveryOnlyWithoutExecutor(t *testing.T) { response := httptest.NewRecorder() workerStatusHandler(false).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/status", nil)) var value workerStatusResponse if err := json.NewDecoder(response.Body).Decode(&value); err != nil { t.Fatal(err) } if response.Code != http.StatusOK || value.Ready || value.Mode != "recovery-only" || value.ExecutorConfigured { t.Fatalf("unexpected status: code=%d value=%+v", response.Code, value) } } func TestWorkerReadyzRequiresExecutor(t *testing.T) { response := httptest.NewRecorder() workerStatusHandler(false).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/readyz", nil)) if response.Code != http.StatusServiceUnavailable { t.Fatalf("readyz status=%d", response.Code) } response = httptest.NewRecorder() workerStatusHandler(true).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/readyz", nil)) if response.Code != http.StatusOK { t.Fatalf("configured readyz status=%d", response.Code) } }