Skip to content

Commit

Permalink
Fix api/v2/status integration tests for simplified routing
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobsonMT committed Mar 20, 2024
1 parent 07b9cba commit f6a7e75
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions pkg/tests/api/alerting/api_alertmanager_test.go
Expand Up @@ -145,13 +145,11 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
})

t.Run("when retrieve alertmanager configuration", func(t *testing.T) {
cfgBody := `
cfgTemplate := `
{
"template_files": null,
"alertmanager_config": {
"route": {
"receiver": "grafana-default-email"
},
"route": %s,
"templates": null,
"receivers": [{
"name": "grafana-default-email",
Expand All @@ -169,12 +167,10 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
}
}
`
cfgBodyWithAutogen := `
{
"template_files": null,
"alertmanager_config": {
"route": {
cfgWithoutAutogen := fmt.Sprintf(cfgTemplate, `{
"receiver": "grafana-default-email"
}`)
cfgWithAutogen := fmt.Sprintf(cfgTemplate, `{
"receiver": "grafana-default-email",
"routes": [{
"receiver": "grafana-default-email",
Expand All @@ -185,24 +181,8 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
"object_matchers": [["__grafana_receiver__", "=", "grafana-default-email"]]
}]
}]
},
"templates": null,
"receivers": [{
"name": "grafana-default-email",
"grafana_managed_receiver_configs": [{
"disableResolveMessage": false,
"uid": "",
"name": "email receiver",
"type": "email",
"secureFields": {},
"settings": {
"addresses": "<example@email.com>"
}
}]
}]
}
}
`
}`)

testCases := []testCase{
{
desc: "un-authenticated request should fail",
Expand All @@ -214,19 +194,19 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "viewer request should succeed",
url: "http://viewer:viewer@%s/api/alertmanager/grafana/config/api/v1/alerts",
expStatus: http.StatusOK,
expBody: cfgBody,
expBody: cfgWithoutAutogen,
},
{
desc: "editor request should succeed",
url: "http://editor:editor@%s/api/alertmanager/grafana/config/api/v1/alerts",
expStatus: http.StatusOK,
expBody: cfgBody,
expBody: cfgWithoutAutogen,
},
{
desc: "admin request should succeed",
url: "http://admin:admin@%s/api/alertmanager/grafana/config/api/v1/alerts",
expStatus: http.StatusOK,
expBody: cfgBodyWithAutogen,
expBody: cfgWithAutogen,
},
}

Expand Down Expand Up @@ -2064,17 +2044,14 @@ func TestIntegrationAlertmanagerStatus(t *testing.T) {
expBody string
}

cfgBody := `
cfgTemplate := `
{
"cluster": {
"peers": [],
"status": "disabled"
},
"config": {
"route": {
"receiver": "grafana-default-email",
"group_by": ["grafana_folder", "alertname"]
},
"route": %s,
"templates": null,
"receivers": [{
"name": "grafana-default-email",
Expand All @@ -2101,6 +2078,23 @@ func TestIntegrationAlertmanagerStatus(t *testing.T) {
}
}
`
cfgWithoutAutogen := fmt.Sprintf(cfgTemplate, `{
"receiver": "grafana-default-email",
"group_by": ["grafana_folder", "alertname"]
}`)
cfgWithAutogen := fmt.Sprintf(cfgTemplate, `{
"receiver": "grafana-default-email",
"routes": [{
"receiver": "grafana-default-email",
"object_matchers": [["__grafana_autogenerated__", "=", "true"]],
"routes": [{
"receiver": "grafana-default-email",
"group_by": ["grafana_folder", "alertname"],
"object_matchers": [["__grafana_receiver__", "=", "grafana-default-email"]]
}]
}],
"group_by": ["grafana_folder", "alertname"]
}`)

testCases := []testCase{
{
Expand All @@ -2113,19 +2107,19 @@ func TestIntegrationAlertmanagerStatus(t *testing.T) {
desc: "viewer request should succeed",
url: "http://viewer:viewer@%s/api/alertmanager/grafana/api/v2/status",
expStatus: http.StatusOK,
expBody: cfgBody,
expBody: cfgWithoutAutogen,
},
{
desc: "editor request should succeed",
url: "http://editor:editor@%s/api/alertmanager/grafana/api/v2/status",
expStatus: http.StatusOK,
expBody: cfgBody,
expBody: cfgWithoutAutogen,
},
{
desc: "admin request should succeed",
url: "http://admin:admin@%s/api/alertmanager/grafana/api/v2/status",
expStatus: http.StatusOK,
expBody: cfgBody,
expBody: cfgWithAutogen,
},
}

Expand Down

0 comments on commit f6a7e75

Please sign in to comment.