From fa5198f78c6bff1bc90d0df2c8a5f3ecdc31a386 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 16 Apr 2026 00:47:17 +0700 Subject: [PATCH] Revert "checker: reorder Status with negatives for good, JSON as string" This reverts commit 6be3578c334ec16fbef1def31f4bd7262edda261. --- checker/types.go | 18 +++++--------- checker/types_test.go | 57 +++++++++---------------------------------- 2 files changed, 18 insertions(+), 57 deletions(-) diff --git a/checker/types.go b/checker/types.go index bd048a5..9adced0 100644 --- a/checker/types.go +++ b/checker/types.go @@ -146,21 +146,15 @@ type CheckerOptionsDocumentation struct { } // Status represents the result status of a check evaluation. -// -// Numeric ordering is severity ordering: lower = better, higher = worse. -// StatusUnknown is intentionally the zero value, so an uninitialized -// CheckState reads as "no signal yet" rather than as a healthy OK. -// "Good" statuses are negative so that aggregators can simply take the -// max() of a set of statuses to compute the worst one. type Status int const ( - StatusOK Status = -2 - StatusInfo Status = -1 - StatusUnknown Status = 0 // zero value: not initialized / no signal yet - StatusWarn Status = 1 - StatusCrit Status = 2 - StatusError Status = 3 + StatusUnknown Status = iota + StatusOK + StatusInfo + StatusWarn + StatusCrit + StatusError ) // String returns the human-readable name of the status. diff --git a/checker/types_test.go b/checker/types_test.go index b2ee5db..74b57d0 100644 --- a/checker/types_test.go +++ b/checker/types_test.go @@ -24,12 +24,12 @@ func TestStatus_MarshalJSON(t *testing.T) { status Status want string }{ - {StatusOK, `"OK"`}, - {StatusInfo, `"INFO"`}, - {StatusUnknown, `"UNKNOWN"`}, - {StatusWarn, `"WARN"`}, - {StatusCrit, `"CRIT"`}, - {StatusError, `"ERROR"`}, + {StatusUnknown, `0`}, + {StatusOK, `1`}, + {StatusInfo, `2`}, + {StatusWarn, `3`}, + {StatusCrit, `4`}, + {StatusError, `5`}, } for _, tt := range tests { got, err := json.Marshal(tt.status) @@ -43,42 +43,17 @@ func TestStatus_MarshalJSON(t *testing.T) { } } -func TestStatus_UnmarshalJSON_String(t *testing.T) { +func TestStatus_UnmarshalJSON(t *testing.T) { tests := []struct { input string want Status }{ - {`"OK"`, StatusOK}, - {`"INFO"`, StatusInfo}, - {`"UNKNOWN"`, StatusUnknown}, - {`""`, StatusUnknown}, - {`"WARN"`, StatusWarn}, - {`"CRIT"`, StatusCrit}, - {`"ERROR"`, StatusError}, - } - for _, tt := range tests { - var got Status - if err := json.Unmarshal([]byte(tt.input), &got); err != nil { - t.Errorf("Unmarshal(%s) error: %v", tt.input, err) - continue - } - if got != tt.want { - t.Errorf("Unmarshal(%s) = %v, want %v", tt.input, got, tt.want) - } - } -} - -func TestStatus_UnmarshalJSON_LegacyInt(t *testing.T) { - tests := []struct { - input string - want Status - }{ - {`-2`, StatusOK}, - {`-1`, StatusInfo}, {`0`, StatusUnknown}, - {`1`, StatusWarn}, - {`2`, StatusCrit}, - {`3`, StatusError}, + {`1`, StatusOK}, + {`2`, StatusInfo}, + {`3`, StatusWarn}, + {`4`, StatusCrit}, + {`5`, StatusError}, } for _, tt := range tests { var got Status @@ -92,14 +67,6 @@ func TestStatus_UnmarshalJSON_LegacyInt(t *testing.T) { } } -func TestStatus_UnmarshalJSON_UnknownString(t *testing.T) { - var s Status - err := json.Unmarshal([]byte(`"BOGUS"`), &s) - if err == nil { - t.Error("Unmarshal(\"BOGUS\") should return error, got nil") - } -} - func TestStatus_RoundTrip(t *testing.T) { for _, s := range []Status{StatusOK, StatusInfo, StatusUnknown, StatusWarn, StatusCrit, StatusError} { data, err := json.Marshal(s)