refactor(pkg): move Status
to a separate module
This commit is contained in:
parent
7209591e08
commit
3263d8c583
7 changed files with 51 additions and 44 deletions
pkg/status
21
pkg/status/status.go
Normal file
21
pkg/status/status.go
Normal 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
26
pkg/status/status_test.go
Normal 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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue