MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRuler_alerts

Function TestRuler_alerts

pkg/ruler/api_test.go:425–458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

423}
424
425func 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
460func TestRuler_Create(t *testing.T) {
461 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)

Callers

nothing calls this directly

Calls 10

PrometheusAlertsMethod · 0.95
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
NewAPIFunction · 0.70
StopAsyncMethod · 0.65
EqualMethod · 0.65
UnmarshalMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected