Skip to content

Commit 61c25c2

Browse files
committed
Use --no-alerts-state in PartialCheckResult
Now users can define what state is returned when there is an empty list.
1 parent 4fd604e commit 61c25c2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cmd/alert.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ inactive = 0`,
192192
// When there are no alerts we add an empty PartialResult just to have consistent output
193193
if len(overall.PartialResults) == 0 {
194194
sc := result.NewPartialResult()
195+
// We already make sure it's valid
196+
//nolint: errcheck
197+
sc.SetDefaultState(noAlertsState)
195198
sc.Output = "No alerts retrieved"
196199
overall.AddSubcheck(sc)
197200
}

cmd/alert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ exit status 2
165165
w.WriteHeader(http.StatusOK)
166166
w.Write(loadTestdata(alertTestDataSet2))
167167
})),
168-
args: []string{"run", "../main.go", "alert", "--name", "NoSuchAlert"},
168+
args: []string{"run", "../main.go", "alert", "--name", "NoSuchAlert", "-T", "3"},
169169
expected: `[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive
170170
\_ [UNKNOWN] No alerts retrieved
171171
|total=0 firing=0 pending=0 inactive=0
@@ -179,7 +179,7 @@ exit status 3
179179
w.WriteHeader(http.StatusOK)
180180
w.Write(loadTestdata(alertTestDataSet2))
181181
})),
182-
args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert", "--problems"},
182+
args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert", "--problems", "-T", "3"},
183183
expected: `[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive
184184
\_ [UNKNOWN] No alerts retrieved
185185
|total=0 firing=0 pending=0 inactive=0

0 commit comments

Comments
 (0)