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

Function TestDeleteTenantRuleGroups

pkg/ruler/ruler_test.go:2532–2589  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2530}
2531
2532func TestDeleteTenantRuleGroups(t *testing.T) {
2533 ruleGroups := []ruleGroupKey{
2534 {user: "userA", namespace: "namespace", group: "group"},
2535 {user: "userB", namespace: "namespace1", group: "group"},
2536 {user: "userB", namespace: "namespace2", group: "group"},
2537 }
2538
2539 obj, rs := setupRuleGroupsStore(t, ruleGroups)
2540 require.Equal(t, 3, len(obj.Objects()))
2541
2542 api, err := NewRuler(Config{}, nil, nil, log.NewNopLogger(), rs, nil)
2543 require.NoError(t, err)
2544
2545 {
2546 req := &http.Request{}
2547 resp := httptest.NewRecorder()
2548 api.DeleteTenantConfiguration(resp, req)
2549
2550 require.Equal(t, http.StatusUnauthorized, resp.Code)
2551 }
2552
2553 {
2554 callDeleteTenantAPI(t, api, "user-with-no-rule-groups")
2555 require.Equal(t, 3, len(obj.Objects()))
2556
2557 verifyExpectedDeletedRuleGroupsForUser(t, api, "user-with-no-rule-groups", true) // Has no rule groups
2558 verifyExpectedDeletedRuleGroupsForUser(t, api, "userA", false)
2559 verifyExpectedDeletedRuleGroupsForUser(t, api, "userB", false)
2560 }
2561
2562 {
2563 callDeleteTenantAPI(t, api, "userA")
2564 require.Equal(t, 2, len(obj.Objects()))
2565
2566 verifyExpectedDeletedRuleGroupsForUser(t, api, "user-with-no-rule-groups", true) // Has no rule groups
2567 verifyExpectedDeletedRuleGroupsForUser(t, api, "userA", true) // Just deleted.
2568 verifyExpectedDeletedRuleGroupsForUser(t, api, "userB", false)
2569 }
2570
2571 // Deleting same user again works fine and reports no problems.
2572 {
2573 callDeleteTenantAPI(t, api, "userA")
2574 require.Equal(t, 2, len(obj.Objects()))
2575
2576 verifyExpectedDeletedRuleGroupsForUser(t, api, "user-with-no-rule-groups", true) // Has no rule groups
2577 verifyExpectedDeletedRuleGroupsForUser(t, api, "userA", true) // Already deleted before.
2578 verifyExpectedDeletedRuleGroupsForUser(t, api, "userB", false)
2579 }
2580
2581 {
2582 callDeleteTenantAPI(t, api, "userB")
2583 require.Equal(t, 0, len(obj.Objects()))
2584
2585 verifyExpectedDeletedRuleGroupsForUser(t, api, "user-with-no-rule-groups", true) // Has no rule groups
2586 verifyExpectedDeletedRuleGroupsForUser(t, api, "userA", true) // Deleted previously
2587 verifyExpectedDeletedRuleGroupsForUser(t, api, "userB", true) // Just deleted
2588 }
2589}

Callers

nothing calls this directly

Calls 6

setupRuleGroupsStoreFunction · 0.85
callDeleteTenantAPIFunction · 0.85
NewRulerFunction · 0.70
EqualMethod · 0.65

Tested by

no test coverage detected