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

Function TestRuler_DeleteNamespace

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

Source from the content-addressed store, hash-verified

561}
562
563func TestRuler_DeleteNamespace(t *testing.T) {
564 store := newMockRuleStore(mockRulesNamespaces, nil)
565 cfg := defaultRulerConfig(t)
566
567 r := newTestRuler(t, cfg, store, nil)
568 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
569
570 a := NewAPI(r, r.store, log.NewNopLogger())
571
572 router := mux.NewRouter()
573 router.Path("/api/v1/rules/{namespace}").Methods(http.MethodDelete).HandlerFunc(a.DeleteNamespace)
574 router.Path("/api/v1/rules/{namespace}/{groupName}").Methods(http.MethodGet).HandlerFunc(a.GetRuleGroup)
575
576 // Verify namespace1 rules are there.
577 req := requestFor(t, http.MethodGet, "https://localhost:8080/api/v1/rules/namespace1/group1", nil, "user1")
578 w := httptest.NewRecorder()
579
580 router.ServeHTTP(w, req)
581 require.Equal(t, http.StatusOK, w.Code)
582 require.Equal(t, "name: group1\ninterval: 10s\nrules:\n - record: UP_RULE\n expr: up\n - alert: UP_ALERT\n expr: up < 1\n", w.Body.String())
583
584 // Delete namespace1
585 req = requestFor(t, http.MethodDelete, "https://localhost:8080/api/v1/rules/namespace1", nil, "user1")
586 w = httptest.NewRecorder()
587
588 router.ServeHTTP(w, req)
589 require.Equal(t, http.StatusAccepted, w.Code)
590 require.Equal(t, "{\"status\":\"success\"}", w.Body.String())
591
592 // On Partial failures
593 req = requestFor(t, http.MethodDelete, "https://localhost:8080/api/v1/rules/namespace2", nil, "user1")
594 w = httptest.NewRecorder()
595
596 router.ServeHTTP(w, req)
597 require.Equal(t, http.StatusInternalServerError, w.Code)
598 require.Equal(t, "{\"status\":\"error\",\"errorType\":\"server_error\",\"error\":\"unable to delete rg\"}", w.Body.String())
599}
600
601func TestRuler_LimitsPerGroup(t *testing.T) {
602 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)

Callers

nothing calls this directly

Calls 9

StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
NewAPIFunction · 0.70
EqualMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected