Add configurable email notification digests
This commit is contained in:
40
email_test.go
Normal file
40
email_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFilterEmailAlerts(t *testing.T) {
|
||||
alerts := []Alert{
|
||||
{ID: "cpu", Severity: "critical", Source: "CPU"},
|
||||
{ID: "backup", Severity: "critical", Source: "Backups"},
|
||||
{ID: "info", Severity: "info", Source: "CPU"},
|
||||
}
|
||||
settings := EmailSettings{Severities: []string{"critical"}, Sources: []string{"CPU"}}
|
||||
filtered := filterEmailAlerts(alerts, settings)
|
||||
if len(filtered) != 1 || filtered[0].ID != "cpu" {
|
||||
t.Fatalf("unexpected filtered alerts: %+v", filtered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailPasswordIsPreserved(t *testing.T) {
|
||||
store, err := openStore(":memory:")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
settings := defaultEmailSettings()
|
||||
settings.Host, settings.From, settings.To, settings.Password = "smtp.example.com", "dash@example.com", "admin@example.com", "secret"
|
||||
if err := store.SaveEmailSettings(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
settings.Password = ""
|
||||
settings.IntervalMinutes = 120
|
||||
if err := store.SaveEmailSettings(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := store.EmailSettings(true); got.Password != "secret" || got.IntervalMinutes != 120 {
|
||||
t.Fatalf("unexpected settings: %+v", got)
|
||||
}
|
||||
if got := store.EmailSettings(false); got.Password != "" || !got.HasPassword {
|
||||
t.Fatalf("password leaked or marker lost: %+v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user