Contexthandler: Remove code that is no longer used (#73101)

* Contexthandler: remove dead code

* Contexthandler: Add tests

* Update pkg/tests/api/alerting/api_alertmanager_test.go

Co-authored-by: Jo <joao.guerreiro@grafana.com>

---------

Co-authored-by: Jo <joao.guerreiro@grafana.com>
This commit is contained in:
Karl Persson
2023-08-09 15:17:59 +02:00
committed by GitHub
parent 5d8e6aa162
commit e53e22ef2a
14 changed files with 208 additions and 1757 deletions
@@ -101,7 +101,7 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "un-authenticated request should fail",
url: "http://%s/api/alertmanager/grafana/config/api/v1/alerts",
expStatus: http.StatusUnauthorized,
expBody: `{"message":"Unauthorized"}`,
expBody: `"message":"Unauthorized"`,
},
{
desc: "viewer request should fail",
@@ -171,7 +171,7 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "un-authenticated request should fail",
url: "http://%s/api/alertmanager/grafana/config/api/v1/alerts",
expStatus: http.StatusUnauthorized,
expBody: `{"message": "Unauthorized"}`,
expBody: `{"extra":null,"message":"Unauthorized","messageId":"auth.unauthorized","statusCode":401,"traceID":""}`,
},
{
desc: "viewer request should succeed",
@@ -235,7 +235,7 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "un-authenticated request should fail",
url: "http://%s/api/alertmanager/grafana/config/api/v2/silences",
expStatus: http.StatusUnauthorized,
expBody: `{"message":"Unauthorized"}`,
expBody: `"message":"Unauthorized"`,
},
{
desc: "viewer request should fail",
@@ -286,7 +286,7 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "un-authenticated request should fail",
url: "http://%s/api/alertmanager/grafana/api/v2/silences",
expStatus: http.StatusUnauthorized,
expBody: `{"message": "Unauthorized"}`,
expBody: `"message": "Unauthorized"`,
},
{
desc: "viewer request should succeed",
@@ -341,7 +341,7 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
desc: "un-authenticated request should fail",
url: "http://%s/api/alertmanager/grafana/api/v2/silence/%s",
expStatus: http.StatusUnauthorized,
expBody: `{"message":"Unauthorized"}`,
expBody: `"message":"Unauthorized"`,
},
{
desc: "viewer request should fail",
@@ -423,7 +423,7 @@ func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
require.JSONEq(t, `{"message": "Unauthorized"}`, string(b))
require.Contains(t, string(b), `"message":"Unauthorized"`)
}
// Create a user to make authenticated requests
@@ -447,11 +447,11 @@ func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
})
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
var res map[string]interface{}
require.NoError(t, json.Unmarshal(b, &res))
require.Equal(t, "invalid username or password", res["message"])
assert.Equal(t, "Invalid username or password", res["message"])
}
// When there are no alerts available, it returns an empty list.