(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func 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: ` |
| 47 | alertmanager_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: ` |
| 60 | alertmanager_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: ` |
| 74 | alertmanager_config: | |
| 75 | route: |
| 76 | receiver: 'default-receiver' |
| 77 | group_wait: 30s |
| 78 | group_interval: 5m |
| 79 | repeat_interval: 4h |
| 80 | group_by: [cluster, alertname] |
| 81 | receivers: |
| 82 | - name: default-receiver |
| 83 | template_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", |
nothing calls this directly
no test coverage detected