From 7a63cf3be9c28ee3d0a023a12a2c747c29defd2f Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 02:21:46 +0000 Subject: [PATCH] test: Add sendNotificationsDirect tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cover disabled paths: all channels disabled, webhook disabled, multiple webhooks with mixed enabled state. Coverage: 44.4% → 66.7% --- internal/notifications/notifications_test.go | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/internal/notifications/notifications_test.go b/internal/notifications/notifications_test.go index c2506c8..fccdde5 100644 --- a/internal/notifications/notifications_test.go +++ b/internal/notifications/notifications_test.go @@ -2666,3 +2666,46 @@ func TestSendHTMLEmailWithError_ExistingEmailManager(t *testing.T) { t.Errorf("expected From to be updated to 'new@example.com', got %q", existingManager.config.EmailConfig.From) } } + +func TestSendNotificationsDirect_AllDisabled(t *testing.T) { + nm := &NotificationManager{} + + emailConfig := EmailConfig{Enabled: false} + webhooks := []WebhookConfig{} + appriseConfig := AppriseConfig{Enabled: false} + alertList := []*alerts.Alert{} + + // Should complete without panic - all notification channels disabled + nm.sendNotificationsDirect(emailConfig, webhooks, appriseConfig, alertList) +} + +func TestSendNotificationsDirect_WebhookDisabled(t *testing.T) { + nm := &NotificationManager{} + + emailConfig := EmailConfig{Enabled: false} + webhooks := []WebhookConfig{ + {Name: "test", Enabled: false, URL: "http://example.com"}, + } + appriseConfig := AppriseConfig{Enabled: false} + alertList := []*alerts.Alert{} + + // Should skip disabled webhook without panic + nm.sendNotificationsDirect(emailConfig, webhooks, appriseConfig, alertList) +} + +func TestSendNotificationsDirect_MultipleWebhooks(t *testing.T) { + nm := &NotificationManager{} + + emailConfig := EmailConfig{Enabled: false} + webhooks := []WebhookConfig{ + {Name: "enabled", Enabled: true, URL: "http://invalid.localhost.test/hook1"}, + {Name: "disabled", Enabled: false, URL: "http://invalid.localhost.test/hook2"}, + {Name: "also-enabled", Enabled: true, URL: "http://invalid.localhost.test/hook3"}, + } + appriseConfig := AppriseConfig{Enabled: false} + alertList := []*alerts.Alert{} + + // Should iterate all webhooks, launching goroutines for enabled ones + nm.sendNotificationsDirect(emailConfig, webhooks, appriseConfig, alertList) + // Goroutines will fail but shouldn't panic +}