Alerting: Update alerting module to 20230428154802-ad53acfab07f (#67541)

This commit is contained in:
Yuri Tseretyan
2023-04-28 20:16:30 +03:00
committed by GitHub
parent bc6f19f130
commit 090ef70f95
3 changed files with 64 additions and 7 deletions
@@ -723,8 +723,13 @@ func TestIntegrationNotificationChannels(t *testing.T) {
mockEmail := &mockEmailHandler{}
// Set up responses
mockChannel.responses["slack_recv1"] = `{"ok": true}`
mockChannel.responses["slack_recvX"] = `{"ok": true}`
mockChannel.responses["slack_recv1"] = func(res http.ResponseWriter) {
res.Header().Set("Content-Type", "application/json")
fmt.Fprint(res, `{"ok": true}`)
}
mockChannel.responses["slack_recvX"] = func(res http.ResponseWriter) {
fmt.Fprint(res, `ok`)
}
// Overriding some URLs to send to the mock channel.
os, opa, ot, opu, ogb, ol, oth := alertingSlack.APIURL, alertingPagerduty.APIURL,
@@ -1009,7 +1014,7 @@ type mockNotificationChannel struct {
server *http.Server
receivedNotifications map[string][]string
responses map[string]string
responses map[string]func(res http.ResponseWriter)
notificationErrorCount int
notificationsMtx sync.RWMutex
}
@@ -1027,7 +1032,7 @@ func newMockNotificationChannel(t *testing.T, grafanaListedAddr string) *mockNot
Addr: listener.Addr().String(),
},
receivedNotifications: make(map[string][]string),
responses: make(map[string]string),
responses: make(map[string]func(res http.ResponseWriter)),
t: t,
}
@@ -1056,8 +1061,11 @@ func (nc *mockNotificationChannel) ServeHTTP(res http.ResponseWriter, req *http.
body := getBody(nc.t, req.Body)
nc.receivedNotifications[key] = append(nc.receivedNotifications[key], body)
res.WriteHeader(http.StatusOK)
fmt.Fprint(res, nc.responses[paths[0]])
if f, ok := nc.responses[paths[0]]; ok {
f(res)
} else {
res.WriteHeader(http.StatusOK)
}
}
func (nc *mockNotificationChannel) totalNotifications() int {