MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestAMConfigValidationAPI

Function TestAMConfigValidationAPI

pkg/alertmanager/api_test.go:33–1131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestAMConfigValidationAPI(t *testing.T) {
34 testCases := []struct {
35 name string
36 cfg string
37 maxConfigSize int
38 maxTemplates int
39 maxTemplateSize int
40
41 response string
42 err error
43 }{
44 {
45 name: "Should return error if the alertmanager config contains no receivers",
46 cfg: `
47alertmanager_config: |
48 route:
49 receiver: 'default-receiver'
50 group_wait: 30s
51 group_interval: 5m
52 repeat_interval: 4h
53 group_by: [cluster, alertname]
54`,
55 err: fmt.Errorf("error validating Alertmanager config: undefined receiver \"default-receiver\" used in route"),
56 },
57 {
58 name: "Should pass if the alertmanager config is valid",
59 cfg: `
60alertmanager_config: |
61 route:
62 receiver: 'default-receiver'
63 group_wait: 30s
64 group_interval: 5m
65 repeat_interval: 4h
66 group_by: [cluster, alertname]
67 receivers:
68 - name: default-receiver
69`,
70 },
71 {
72 name: "Should return error if the config is empty due to wrong indentation",
73 cfg: `
74alertmanager_config: |
75route:
76 receiver: 'default-receiver'
77 group_wait: 30s
78 group_interval: 5m
79 repeat_interval: 4h
80 group_by: [cluster, alertname]
81receivers:
82 - name: default-receiver
83template_files:
84 "good.tpl": "good-templ"
85 "not/very/good.tpl": "bad-template"
86`,
87 err: fmt.Errorf("error validating Alertmanager config: configuration provided is empty, if you'd like to remove your configuration please use the delete configuration endpoint"),
88 },
89 {
90 name: "Should return error if the alertmanager config is empty due to wrong key",

Callers

nothing calls this directly

Calls 7

SetUserConfigMethod · 0.95
WrapMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.65
ContextMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected