From 071ccc44ec61f4f732698984c1367be1e7dbdf0f Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 02:26:25 +0000 Subject: [PATCH] test: Add ProcessQueuedNotification error path tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cover invalid config JSON for email, webhook, and apprise types, plus unknown notification type handling. Coverage: 63.3% → 83.3% --- internal/notifications/notifications_test.go | 72 ++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/internal/notifications/notifications_test.go b/internal/notifications/notifications_test.go index fccdde5..bb90c88 100644 --- a/internal/notifications/notifications_test.go +++ b/internal/notifications/notifications_test.go @@ -2709,3 +2709,75 @@ func TestSendNotificationsDirect_MultipleWebhooks(t *testing.T) { nm.sendNotificationsDirect(emailConfig, webhooks, appriseConfig, alertList) // Goroutines will fail but shouldn't panic } + +func TestProcessQueuedNotification_InvalidEmailConfig(t *testing.T) { + nm := &NotificationManager{} + notif := &QueuedNotification{ + ID: "test-1", + Type: "email", + Config: json.RawMessage(`{invalid json`), + Alerts: []*alerts.Alert{}, + } + + err := nm.ProcessQueuedNotification(notif) + if err == nil { + t.Error("expected error for invalid email config JSON") + } + if !strings.Contains(err.Error(), "failed to unmarshal email config") { + t.Errorf("expected 'failed to unmarshal email config' error, got: %v", err) + } +} + +func TestProcessQueuedNotification_InvalidWebhookConfig(t *testing.T) { + nm := &NotificationManager{} + notif := &QueuedNotification{ + ID: "test-2", + Type: "webhook", + Config: json.RawMessage(`{not valid`), + Alerts: []*alerts.Alert{}, + } + + err := nm.ProcessQueuedNotification(notif) + if err == nil { + t.Error("expected error for invalid webhook config JSON") + } + if !strings.Contains(err.Error(), "failed to unmarshal webhook config") { + t.Errorf("expected 'failed to unmarshal webhook config' error, got: %v", err) + } +} + +func TestProcessQueuedNotification_InvalidAppriseConfig(t *testing.T) { + nm := &NotificationManager{} + notif := &QueuedNotification{ + ID: "test-3", + Type: "apprise", + Config: json.RawMessage(`broken json`), + Alerts: []*alerts.Alert{}, + } + + err := nm.ProcessQueuedNotification(notif) + if err == nil { + t.Error("expected error for invalid apprise config JSON") + } + if !strings.Contains(err.Error(), "failed to unmarshal apprise config") { + t.Errorf("expected 'failed to unmarshal apprise config' error, got: %v", err) + } +} + +func TestProcessQueuedNotification_UnknownType(t *testing.T) { + nm := &NotificationManager{} + notif := &QueuedNotification{ + ID: "test-4", + Type: "unknown-type", + Config: json.RawMessage(`{}`), + Alerts: []*alerts.Alert{}, + } + + err := nm.ProcessQueuedNotification(notif) + if err == nil { + t.Error("expected error for unknown notification type") + } + if !strings.Contains(err.Error(), "unknown notification type") { + t.Errorf("expected 'unknown notification type' error, got: %v", err) + } +}