mirror of
https://github.com/Icinga/icingadb.git
synced 2026-06-09 08:56:54 -04:00
Test types.StateType#UnmarshalJSON()
This commit is contained in:
parent
277a61d30e
commit
e0e357bcc9
1 changed files with 36 additions and 0 deletions
36
pkg/icingadb/types/state_type_test.go
Normal file
36
pkg/icingadb/types/state_type_test.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStateType_UnmarshalJSON(t *testing.T) {
|
||||
subtests := []struct {
|
||||
name string
|
||||
input string
|
||||
output StateType
|
||||
error bool
|
||||
}{
|
||||
{name: "bad-json", input: "bad JSON", error: true},
|
||||
{name: "bool", input: "false", error: true},
|
||||
{name: "string", input: `"0"`, error: true},
|
||||
{name: "negative", input: "-1", error: true},
|
||||
{name: "fraction", input: "0.5", error: true},
|
||||
{name: "out-of-range", input: "2", error: true},
|
||||
{name: "soft", input: "0", output: StateSoft},
|
||||
{name: "hard", input: "1", output: StateHard},
|
||||
}
|
||||
|
||||
for _, st := range subtests {
|
||||
t.Run(st.name, func(t *testing.T) {
|
||||
var s StateType
|
||||
if err := s.UnmarshalJSON([]byte(st.input)); st.error {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, st.output, s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue