(t *testing.T)
| 248 | } |
| 249 | |
| 250 | func TestRuler_rules(t *testing.T) { |
| 251 | store := newMockRuleStore(mockRules, nil) |
| 252 | cfg := defaultRulerConfig(t) |
| 253 | |
| 254 | r := newTestRuler(t, cfg, store, nil) |
| 255 | defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck |
| 256 | |
| 257 | a := NewAPI(r, r.store, log.NewNopLogger()) |
| 258 | |
| 259 | req := requestFor(t, "GET", "https://localhost:8080/api/prom/api/v1/rules", nil, "user1") |
| 260 | w := httptest.NewRecorder() |
| 261 | a.PrometheusRules(w, req) |
| 262 | |
| 263 | resp := w.Result() |
| 264 | body, _ := io.ReadAll(resp.Body) |
| 265 | |
| 266 | // Check status code and status response |
| 267 | responseJSON := util_api.Response{} |
| 268 | err := json.Unmarshal(body, &responseJSON) |
| 269 | require.NoError(t, err) |
| 270 | require.Equal(t, http.StatusOK, resp.StatusCode) |
| 271 | require.Equal(t, responseJSON.Status, "success") |
| 272 | stripEvaluationFields(t, responseJSON) |
| 273 | actual, err := json.Marshal(responseJSON) |
| 274 | require.NoError(t, err) |
| 275 | |
| 276 | // Testing the running rules for user1 in the mock store |
| 277 | expectedResponse, _ := json.Marshal(util_api.Response{ |
| 278 | Status: "success", |
| 279 | Data: &RuleDiscovery{ |
| 280 | RuleGroups: []*RuleGroup{ |
| 281 | { |
| 282 | Name: "group1", |
| 283 | File: "namespace1", |
| 284 | Rules: []rule{ |
| 285 | &recordingRule{ |
| 286 | Name: "UP_RULE", |
| 287 | Query: "up", |
| 288 | Health: "unknown", |
| 289 | Type: "recording", |
| 290 | }, |
| 291 | &alertingRule{ |
| 292 | Name: "UP_ALERT", |
| 293 | Query: "up < 1", |
| 294 | State: "unknown", |
| 295 | Health: "unknown", |
| 296 | Type: "alerting", |
| 297 | Alerts: []*Alert{}, |
| 298 | }, |
| 299 | }, |
| 300 | Interval: 10, |
| 301 | }, |
| 302 | }, |
| 303 | }, |
| 304 | }) |
| 305 | |
| 306 | require.JSONEq(t, string(expectedResponse), string(actual)) |
| 307 | } |
nothing calls this directly
no test coverage detected