mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: enable e2e tests to run in production mode (#45073)
* Alerting: run e2e tests in production mode * adapt expected messages * switch expected and actual to have the right order
This commit is contained in:
committed by
GitHub
parent
a025109647
commit
4fef791c7c
@@ -36,6 +36,7 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
DisableAnonymous: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -100,7 +101,7 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
desc: "viewer request should fail",
|
||||
url: "http://viewer:viewer@%s/api/alertmanager/grafana/config/api/v1/alerts",
|
||||
expStatus: http.StatusForbidden,
|
||||
expBody: `{"message": "permission denied","error": "permission denied"}`,
|
||||
expBody: `{"message": "permission denied"}`,
|
||||
},
|
||||
{
|
||||
desc: "editor request should succeed",
|
||||
@@ -170,7 +171,7 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
desc: "viewer request should fail",
|
||||
url: "http://viewer:viewer@%s/api/alertmanager/grafana/config/api/v1/alerts",
|
||||
expStatus: http.StatusForbidden,
|
||||
expBody: `{"message": "permission denied","error": "permission denied"}`,
|
||||
expBody: `{"message": "permission denied"}`,
|
||||
},
|
||||
{
|
||||
desc: "editor request should succeed",
|
||||
@@ -233,7 +234,7 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
desc: "viewer request should fail",
|
||||
url: "http://viewer:viewer@%s/api/alertmanager/grafana/api/v2/silences",
|
||||
expStatus: http.StatusForbidden,
|
||||
expBody: `{"message": "permission denied","error": "permission denied"}`,
|
||||
expBody: `{"message": "permission denied"}`,
|
||||
},
|
||||
{
|
||||
desc: "editor request should succeed",
|
||||
@@ -339,7 +340,7 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
desc: "viewer request should fail",
|
||||
url: "http://viewer:viewer@%s/api/alertmanager/grafana/api/v2/silence/%s",
|
||||
expStatus: http.StatusForbidden,
|
||||
expBody: `{"message": "permission denied","error": "permission denied"}`,
|
||||
expBody: `{"message": "permission denied"}`,
|
||||
},
|
||||
{
|
||||
desc: "editor request should succeed",
|
||||
@@ -398,6 +399,7 @@ func TestAlertAndGroupsQuery(t *testing.T) {
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
DisableAnonymous: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -440,7 +442,7 @@ func TestAlertAndGroupsQuery(t *testing.T) {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
|
||||
require.JSONEq(t, `{"error": "invalid username or password","message": "invalid username or password"}`, string(b))
|
||||
require.JSONEq(t, `{"message": "invalid username or password"}`, string(b))
|
||||
}
|
||||
|
||||
// When there are no alerts available, it returns an empty list.
|
||||
@@ -568,6 +570,7 @@ func TestRulerAccess(t *testing.T) {
|
||||
EnableQuota: true,
|
||||
DisableAnonymous: true,
|
||||
ViewersCanEdit: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -612,7 +615,7 @@ func TestRulerAccess(t *testing.T) {
|
||||
desc: "viewer request should fail",
|
||||
url: "http://viewer:viewer@%s/api/ruler/grafana/api/v1/rules/default",
|
||||
expStatus: http.StatusForbidden,
|
||||
expectedResponse: `{"message": "user does not have permissions to edit the namespace: user does not have permissions to edit the namespace","error":"user does not have permissions to edit the namespace: user does not have permissions to edit the namespace"}`,
|
||||
expectedResponse: `{"message": "user does not have permissions to edit the namespace: user does not have permissions to edit the namespace"}`,
|
||||
},
|
||||
{
|
||||
desc: "editor request should succeed",
|
||||
@@ -697,6 +700,7 @@ func TestDeleteFolderWithRules(t *testing.T) {
|
||||
EnableQuota: true,
|
||||
DisableAnonymous: true,
|
||||
ViewersCanEdit: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -858,6 +862,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
EnableUnifiedAlerting: true,
|
||||
EnableQuota: true,
|
||||
DisableAnonymous: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -903,7 +908,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
Data: []ngmodels.AlertQuery{},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: no queries or expressions are found","error":"failed to update rule group: invalid alert rule: no queries or expressions are found"}`,
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: no queries or expressions are found"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with empty title",
|
||||
@@ -933,7 +938,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: title is empty","error":"failed to update rule group: invalid alert rule: title is empty"}`,
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: title is empty"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with too long name",
|
||||
@@ -963,7 +968,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: name length should not be greater than 190","error":"failed to update rule group: invalid alert rule: name length should not be greater than 190"}`,
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: name length should not be greater than 190"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with too long rulegroup",
|
||||
@@ -993,7 +998,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: rule group name length should not be greater than 190","error":"failed to update rule group: invalid alert rule: rule group name length should not be greater than 190"}`,
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: rule group name length should not be greater than 190"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with invalid interval",
|
||||
@@ -1024,7 +1029,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: interval (1s) should be non-zero and divided exactly by scheduler interval: 10s","error":"failed to update rule group: invalid alert rule: interval (1s) should be non-zero and divided exactly by scheduler interval: 10s"}`,
|
||||
expectedResponse: `{"message": "failed to update rule group: invalid alert rule: interval (1s) should be non-zero and divided exactly by scheduler interval: 10s"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with unknown datasource",
|
||||
@@ -1054,7 +1059,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to validate alert rule \"AlwaysFiring\": invalid query A: data source not found: unknown","error":"failed to validate alert rule \"AlwaysFiring\": invalid query A: data source not found: unknown"}`,
|
||||
expectedResponse: `{"message": "failed to validate alert rule \"AlwaysFiring\": invalid query A: data source not found: unknown"}`,
|
||||
},
|
||||
{
|
||||
desc: "alert rule with invalid condition",
|
||||
@@ -1084,7 +1089,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResponse: `{"message": "failed to validate alert rule \"AlwaysFiring\": condition B not found in any query or expression: it should be one of: [A]","error":"failed to validate alert rule \"AlwaysFiring\": condition B not found in any query or expression: it should be one of: [A]"}`,
|
||||
expectedResponse: `{"message": "failed to validate alert rule \"AlwaysFiring\": condition B not found in any query or expression: it should be one of: [A]"}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1374,7 +1379,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
require.JSONEq(t, `{"message": "failed to update rule group: failed to get alert rule unknown: could not find alert rule","error":"failed to update rule group: failed to get alert rule unknown: could not find alert rule"}`, string(b))
|
||||
require.JSONEq(t, `{"message": "failed to update rule group: failed to get alert rule unknown: could not find alert rule"}`, string(b))
|
||||
|
||||
// let's make sure that rule definitions are not affected by the failed POST request.
|
||||
u = fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)
|
||||
@@ -1493,7 +1498,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
require.JSONEq(t, fmt.Sprintf(`{"message": "failed to validate alert rule \"AlwaysAlerting\": conflicting UID \"%s\" found","error":"failed to validate alert rule \"AlwaysAlerting\": conflicting UID \"%s\" found"}`, ruleUID, ruleUID), string(b))
|
||||
require.JSONEq(t, fmt.Sprintf(`{"message": "failed to validate alert rule \"AlwaysAlerting\": conflicting UID \"%s\" found"}`, ruleUID), string(b))
|
||||
|
||||
// let's make sure that rule definitions are not affected by the failed POST request.
|
||||
u = fmt.Sprintf("http://grafana:password@%s/api/ruler/grafana/api/v1/rules/default", grafanaListedAddr)
|
||||
@@ -1898,7 +1903,7 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
require.JSONEq(t, `{"message": "failed to delete rule group: rule group not found under this namespace","error":"failed to delete rule group: rule group not found under this namespace"}`, string(b))
|
||||
require.JSONEq(t, `{"message": "failed to delete rule group: rule group not found under this namespace"}`, string(b))
|
||||
})
|
||||
|
||||
t.Run("succeed if the rule group name does exist", func(t *testing.T) {
|
||||
@@ -1925,6 +1930,7 @@ func TestAlertmanagerStatus(t *testing.T) {
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, _ := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -1990,6 +1996,7 @@ func TestQuota(t *testing.T) {
|
||||
EnableUnifiedAlerting: true,
|
||||
EnableQuota: true,
|
||||
DisableAnonymous: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -2108,7 +2115,7 @@ func TestQuota(t *testing.T) {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
require.JSONEq(t, `{"message": "quota reached","error":"quota reached"}`, string(b))
|
||||
require.JSONEq(t, `{"message": "quota reached"}`, string(b))
|
||||
})
|
||||
|
||||
t.Run("when quota limit exceed updating existing rule should succeed", func(t *testing.T) {
|
||||
@@ -2235,6 +2242,7 @@ func TestEval(t *testing.T) {
|
||||
EnableUnifiedAlerting: true,
|
||||
EnableQuota: true,
|
||||
DisableAnonymous: true,
|
||||
AppModeProduction: true,
|
||||
})
|
||||
|
||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
||||
@@ -2405,7 +2413,7 @@ func TestEval(t *testing.T) {
|
||||
}
|
||||
`,
|
||||
expectedStatusCode: http.StatusBadRequest,
|
||||
expectedResponse: `{"message": "invalid condition: condition B not found in any query or expression: it should be one of: [A]","error":"invalid condition: condition B not found in any query or expression: it should be one of: [A]"}`,
|
||||
expectedResponse: `{"message": "invalid condition: condition B not found in any query or expression: it should be one of: [A]"}`,
|
||||
},
|
||||
{
|
||||
desc: "unknown query datasource",
|
||||
@@ -2430,7 +2438,7 @@ func TestEval(t *testing.T) {
|
||||
}
|
||||
`,
|
||||
expectedStatusCode: http.StatusBadRequest,
|
||||
expectedResponse: `{"message": "invalid condition: invalid query A: data source not found: unknown","error":"invalid condition: invalid query A: data source not found: unknown"}`,
|
||||
expectedResponse: `{"message": "invalid condition: invalid query A: data source not found: unknown"}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2586,7 +2594,7 @@ func TestEval(t *testing.T) {
|
||||
}
|
||||
`,
|
||||
expectedStatusCode: http.StatusBadRequest,
|
||||
expectedResponse: `{"message": "invalid queries or expressions: invalid query A: data source not found: unknown","error":"invalid queries or expressions: invalid query A: data source not found: unknown"}`,
|
||||
expectedResponse: `{"message": "invalid queries or expressions: invalid query A: data source not found: unknown"}`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user