From ca7da7c18fc2f3a2cedbd5121320b5ef06a97c56 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 02:58:10 +0000 Subject: [PATCH] test: Add CancelByAlertIDs empty input and no-match tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test early return for empty alertIDs and happy path with empty queue. Coverage: 62.9% → 65.7% --- internal/notifications/queue_test.go | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/notifications/queue_test.go b/internal/notifications/queue_test.go index d8255e5..5095984 100644 --- a/internal/notifications/queue_test.go +++ b/internal/notifications/queue_test.go @@ -201,3 +201,38 @@ func TestQueuedNotification_ZeroValues(t *testing.T) { t.Error("CompletedAt should be nil by default") } } + +func TestCancelByAlertIDs_EmptyInput(t *testing.T) { + // Create a temporary queue for testing + tempDir := t.TempDir() + nq, err := NewNotificationQueue(tempDir) + if err != nil { + t.Fatalf("Failed to create notification queue: %v", err) + } + + // Empty slice should return nil without error + err = nq.CancelByAlertIDs([]string{}) + if err != nil { + t.Errorf("CancelByAlertIDs with empty slice returned error: %v", err) + } + + // Nil slice should also return nil without error + err = nq.CancelByAlertIDs(nil) + if err != nil { + t.Errorf("CancelByAlertIDs with nil slice returned error: %v", err) + } +} + +func TestCancelByAlertIDs_NoMatchingNotifications(t *testing.T) { + tempDir := t.TempDir() + nq, err := NewNotificationQueue(tempDir) + if err != nil { + t.Fatalf("Failed to create notification queue: %v", err) + } + + // With an empty queue, no notifications should match + err = nq.CancelByAlertIDs([]string{"alert-1", "alert-2"}) + if err != nil { + t.Errorf("CancelByAlertIDs with no matching notifications returned error: %v", err) + } +}