Files
felhom.eu/hub/internal/notify/r1295_pbsdr_failed_test.go
T

44 lines
1.7 KiB
Go

package notify
import (
"strings"
"testing"
)
// R-1295: a failed set-up of a box's whole-guest off-site tier reaches the OPERATOR — through the real dispatcher, with
// a subject that says what failed and what to do — and never the household, even when the household has every event
// switched on (the R-97c breaking configuration).
// RED-PROOF: drop "pbsdr_provision_failed" from operatorOnlyEvents → the household is mailed; drop the subject case in
// FormatOperatorEmail → the subject is the bare event type.
func TestR1295_TheFailedSetUpMailsTheOperatorOnly(t *testing.T) {
st := opOnlyStore(t)
if err := st.SaveNotificationPrefs("c1", "customer@example.com", []string{"pbsdr_provision_failed", "backup_failed"}, 6); err != nil {
t.Fatal(err)
}
var operatorSubjects []string
var to []string
d := opOnlyDispatcher(t, st, &sentTo{})
d.sendEmailFn = func(addr, subject, body string, headers map[string]string) error {
to = append(to, addr)
if addr == "operator@felhom.eu" {
operatorSubjects = append(operatorSubjects, subject)
}
return nil
}
d.ProcessEvent("c1", "pbsdr_provision_failed", "error",
"The whole-box off-site copy (PBS DR) for c1 could not be set up for host c1-01: … save the configuration …",
`{"host_id":"c1-01"}`, "hub")
for _, a := range to {
if a == "customer@example.com" {
t.Fatal("the household was mailed an operator-only set-up failure")
}
}
if len(operatorSubjects) != 1 {
t.Fatalf("the operator got %d mail(s), want 1 (to: %v)", len(operatorSubjects), to)
}
if s := operatorSubjects[0]; !strings.Contains(s, "could not be set up") || !strings.Contains(s, "save the customer config to retry") {
t.Fatalf("the subject must say what failed and what to do: %q", s)
}
}