Files
archie/internal/app/archied/alerts_settle_test.go

35 lines
1.1 KiB
Go

package archied
import (
"errors"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/alert"
"github.com/samcharles93/archie-core/internal/domain/org"
)
func TestSettleDeliveriesRetriesWhenSettingsAreUnavailable(t *testing.T) {
due := []alert.Due{
{ID: 1, Alert: alert.Alert{Key: alert.Key{Org: "acme"}}},
{ID: 2, Alert: alert.Alert{Key: alert.Key{Org: "acme"}}},
{ID: 3, Alert: alert.Alert{Key: alert.Key{Org: "beta"}}},
}
notifyFor := func(owner org.OrgID) (config.Notify, error) {
if owner == "acme" {
return config.Notify{}, errors.New("control plane unavailable")
}
return config.Notify{Webhook: "https://example.com"}, nil
}
send := func(d alert.Due, notify config.Notify) alert.Outcome {
return alert.Outcome{DeliveryID: d.ID, Skipped: notify.Webhook == ""}
}
outcomes := settleDeliveries(due, notifyFor, send)
for i, outcome := range outcomes {
failed := due[i].Alert.Org == "acme"
if outcome.Skipped || (outcome.Error != "") != failed {
t.Fatalf("delivery %d: outcome %+v, want a retryable failure only for acme", outcome.DeliveryID, outcome)
}
}
}