(t *testing.T)
| 19 | return e |
| 20 | } |
| 21 | |
| 22 | func TestQueryDetailRoute(t *testing.T) { |
| 23 | live := &fakeLiveInfo{detail: &QueryDetail{ |
| 24 | Org: "acme", |
| 25 | User: "bob", |
| 26 | PID: 42, |
| 27 | WorkerID: 7, |
| 28 | State: "active", |
| 29 | Query: "SELECT 1", |
| 30 | }} |
| 31 | r := liveTestRouter(live, nil) |
| 32 | |
| 33 | // Hit (addressed by cluster-unique worker id): returns the detail JSON. |
| 34 | w := httptest.NewRecorder() |
| 35 | r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/queries/by-worker/7", nil)) |
| 36 | if w.Code != http.StatusOK { |
| 37 | t.Fatalf("expected 200, got %d (%s)", w.Code, w.Body.String()) |
| 38 | } |
| 39 | var got QueryDetail |
| 40 | if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil { |
| 41 | t.Fatalf("decode: %v", err) |
| 42 | } |
| 43 | if got.WorkerID != 7 || got.Query != "SELECT 1" || got.Org != "acme" { |
| 44 | t.Fatalf("unexpected body: %+v", got) |
| 45 | } |
| 46 | |
| 47 | // Miss (no fetcher): worker not owned by this replica → 404. |
| 48 | w = httptest.NewRecorder() |
| 49 | r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/queries/by-worker/99", nil)) |
| 50 | if w.Code != http.StatusNotFound { |
| 51 | t.Fatalf("expected 404 for unknown worker, got %d", w.Code) |
| 52 | } |
| 53 | |
| 54 | // Bad worker id → 400. |
| 55 | w = httptest.NewRecorder() |
| 56 | r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/queries/by-worker/notanint", nil)) |
| 57 | if w.Code != http.StatusBadRequest { |
| 58 | t.Fatalf("expected 400 for non-numeric worker id, got %d", w.Code) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // TestQueryDetailFansOutAcrossCPs proves /queries/by-worker/:wid scatter-gathers: |
nothing calls this directly
no test coverage detected