Revert "checker: reorder Status with negatives for good, JSON as string"

This reverts commit 6be3578c33.
This commit is contained in:
nemunaire 2026-04-16 00:47:17 +07:00
commit fa5198f78c
2 changed files with 18 additions and 57 deletions

View file

@ -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.

View file

@ -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)