Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8818e42ecc |
@@ -1129,6 +1129,7 @@ type logRecord struct {
|
|||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseLog decodes each line of a JSON log.
|
// parseLog decodes each line of a JSON log.
|
||||||
@@ -1225,7 +1226,8 @@ func TestSendNotificationDebugLogOmitsWebhookURL(t *testing.T) {
|
|||||||
|
|
||||||
// TestSendNotificationErrorLogOmitsWebhookURL checks that a delivery
|
// TestSendNotificationErrorLogOmitsWebhookURL checks that a delivery
|
||||||
// to each endpoint that cannot connect logs the transport's error,
|
// to each endpoint that cannot connect logs the transport's error,
|
||||||
// on every attempt and at the end, without any part of the URL's
|
// which names the refused connection, on its retry line and on its
|
||||||
|
// final failure line, and that no line holds any part of the URL's
|
||||||
// path or query.
|
// path or query.
|
||||||
func TestSendNotificationErrorLogOmitsWebhookURL(t *testing.T) {
|
func TestSendNotificationErrorLogOmitsWebhookURL(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -1239,20 +1241,31 @@ func TestSendNotificationErrorLogOmitsWebhookURL(t *testing.T) {
|
|||||||
|
|
||||||
assertNoWebhookSecret(t, logs)
|
assertNoWebhookSecret(t, logs)
|
||||||
|
|
||||||
var failed []string
|
// For each endpoint, the messages of its lines whose error names
|
||||||
|
// the refused connection, in the order they were logged.
|
||||||
|
got := map[string][]string{}
|
||||||
|
|
||||||
for _, record := range parseLog(t, logs) {
|
for _, record := range parseLog(t, logs) {
|
||||||
if record.Msg == "failed to send notification after retries" {
|
if strings.Contains(record.Error, "connection refused") {
|
||||||
failed = append(failed, record.Endpoint)
|
got[record.Endpoint] = append(
|
||||||
|
got[record.Endpoint], record.Msg,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.Sort(failed)
|
lines := []string{
|
||||||
|
"notification delivery failed, retrying",
|
||||||
|
"failed to send notification after retries",
|
||||||
|
}
|
||||||
|
want := map[string][]string{
|
||||||
|
endpointNtfy: lines,
|
||||||
|
endpointSlack: lines,
|
||||||
|
endpointMattermost: lines,
|
||||||
|
}
|
||||||
|
|
||||||
want := []string{endpointMattermost, endpointNtfy, endpointSlack}
|
if !maps.EqualFunc(got, want, slices.Equal) {
|
||||||
if !slices.Equal(failed, want) {
|
t.Errorf("lines whose error names the refused connection = %v, "+
|
||||||
t.Errorf("endpoints that logged a failure = %v, want %v",
|
"want %v", got, want)
|
||||||
failed, want)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user