9 dd0af5f7 2022-01-18 o func TestHostMarshal(t *testing.T) {
10 dd0af5f7 2022-01-18 o s := `{"attrs":{"address":"192.0.2.1","address6":"2001:db8::","groups":["test"],"check_command":"dummy","display_name":"Example host"}}`
11 dd0af5f7 2022-01-18 o want := make(map[string]interface{})
12 dd0af5f7 2022-01-18 o if err := json.Unmarshal([]byte(s), &want); err != nil {
16 dd0af5f7 2022-01-18 o p, err := json.Marshal(Host{
17 dd0af5f7 2022-01-18 o Name: "example.com",
18 dd0af5f7 2022-01-18 o Address: "192.0.2.1",
19 dd0af5f7 2022-01-18 o Address6: "2001:db8::",
20 dd0af5f7 2022-01-18 o Groups: []string{"test"},
21 dd0af5f7 2022-01-18 o State: HostDown,
22 dd0af5f7 2022-01-18 o StateType: StateSoft,
23 dd0af5f7 2022-01-18 o CheckCommand: "dummy",
24 dd0af5f7 2022-01-18 o DisplayName: "Example host",
26 dd0af5f7 2022-01-18 o if err != nil {
29 dd0af5f7 2022-01-18 o got := make(map[string]interface{})
30 dd0af5f7 2022-01-18 o if err := json.Unmarshal(p, &got); err != nil {
34 dd0af5f7 2022-01-18 o if !reflect.DeepEqual(want, got) {
37 dd0af5f7 2022-01-18 o t.Log("want", want, "got", got)