refactor(pkg): move Status to a separate module

This commit is contained in:
Emmanuel BENOîT 2024-07-20 18:56:51 +02:00
parent 7209591e08
commit 3263d8c583
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
7 changed files with 51 additions and 44 deletions

21
pkg/status/status.go Normal file
View file

@ -0,0 +1,21 @@
// The status package contains the datatype that corresponds to monitoring
// plugin status values.
package status // import nocternity.net/gomonop/pkg/status
// Status represents the return status of the monitoring plugin. The
// corresponding integer value will be used as the program's exit code,
// to be interpreted by the monitoring system.
type Status int
// Plugin exit statuses.
const (
StatusOK Status = iota
StatusWarning
StatusCritical
StatusUnknown
)
// String representations of the plugin statuses.
func (s Status) String() string {
return [...]string{"OK", "WARNING", "ERROR", "UNKNOWN"}[s]
}

26
pkg/status/status_test.go Normal file
View file

@ -0,0 +1,26 @@
package status // import nocternity.net/gomonop/pkg/status
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStatusDefaultOK(t *testing.T) {
var s Status
assert.Equal(t, StatusOK, s)
}
func TestStatusToString(t *testing.T) {
assert.Equal(t, "OK", StatusOK.String())
assert.Equal(t, "WARNING", StatusWarning.String())
assert.Equal(t, "ERROR", StatusCritical.String())
assert.Equal(t, "UNKNOWN", StatusUnknown.String())
}
func TestStatusToInt(t *testing.T) {
assert.Equal(t, 0, int(StatusOK))
assert.Equal(t, 1, int(StatusWarning))
assert.Equal(t, 2, int(StatusCritical))
assert.Equal(t, 3, int(StatusUnknown))
}