(t *testing.T)
| 423 | } |
| 424 | |
| 425 | func TestRuler_alerts(t *testing.T) { |
| 426 | store := newMockRuleStore(mockRules, nil) |
| 427 | cfg := defaultRulerConfig(t) |
| 428 | |
| 429 | r := newTestRuler(t, cfg, store, nil) |
| 430 | defer r.StopAsync() |
| 431 | |
| 432 | a := NewAPI(r, r.store, log.NewNopLogger()) |
| 433 | |
| 434 | req := requestFor(t, http.MethodGet, "https://localhost:8080/api/prom/api/v1/alerts", nil, "user1") |
| 435 | w := httptest.NewRecorder() |
| 436 | a.PrometheusAlerts(w, req) |
| 437 | |
| 438 | resp := w.Result() |
| 439 | body, _ := io.ReadAll(resp.Body) |
| 440 | |
| 441 | // Check status code and status response |
| 442 | responseJSON := util_api.Response{} |
| 443 | err := json.Unmarshal(body, &responseJSON) |
| 444 | require.NoError(t, err) |
| 445 | require.Equal(t, http.StatusOK, resp.StatusCode) |
| 446 | require.Equal(t, responseJSON.Status, "success") |
| 447 | |
| 448 | // Currently there is not an easy way to mock firing alerts. The empty |
| 449 | // response case is tested instead. |
| 450 | expectedResponse, _ := json.Marshal(util_api.Response{ |
| 451 | Status: "success", |
| 452 | Data: &AlertDiscovery{ |
| 453 | Alerts: []*Alert{}, |
| 454 | }, |
| 455 | }) |
| 456 | |
| 457 | require.Equal(t, string(expectedResponse), string(body)) |
| 458 | } |
| 459 | |
| 460 | func TestRuler_Create(t *testing.T) { |
| 461 | store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil) |
nothing calls this directly
no test coverage detected