From 61c25c268e6c5e14a516def406c3d9de16c14700 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 21 Nov 2025 12:11:00 +0100 Subject: [PATCH] Use --no-alerts-state in PartialCheckResult Now users can define what state is returned when there is an empty list. --- cmd/alert.go | 3 +++ cmd/alert_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/alert.go b/cmd/alert.go index 1431b22..4e2bbd3 100644 --- a/cmd/alert.go +++ b/cmd/alert.go @@ -192,6 +192,9 @@ inactive = 0`, // When there are no alerts we add an empty PartialResult just to have consistent output if len(overall.PartialResults) == 0 { sc := result.NewPartialResult() + // We already make sure it's valid + //nolint: errcheck + sc.SetDefaultState(noAlertsState) sc.Output = "No alerts retrieved" overall.AddSubcheck(sc) } diff --git a/cmd/alert_test.go b/cmd/alert_test.go index c5f6157..cb40d5e 100644 --- a/cmd/alert_test.go +++ b/cmd/alert_test.go @@ -165,7 +165,7 @@ exit status 2 w.WriteHeader(http.StatusOK) w.Write(loadTestdata(alertTestDataSet2)) })), - args: []string{"run", "../main.go", "alert", "--name", "NoSuchAlert"}, + args: []string{"run", "../main.go", "alert", "--name", "NoSuchAlert", "-T", "3"}, expected: `[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive \_ [UNKNOWN] No alerts retrieved |total=0 firing=0 pending=0 inactive=0 @@ -179,7 +179,7 @@ exit status 3 w.WriteHeader(http.StatusOK) w.Write(loadTestdata(alertTestDataSet2)) })), - args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert", "--problems"}, + args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert", "--problems", "-T", "3"}, expected: `[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive \_ [UNKNOWN] No alerts retrieved |total=0 firing=0 pending=0 inactive=0