Blob


1 package icinga
3 import (
4 "encoding/json"
5 "reflect"
6 "testing"
7 )
9 func TestHostMarshal(t *testing.T) {
10 s := `{"attrs":{"address":"192.0.2.1","address6":"2001:db8::","groups":["test"],"check_command":"dummy","display_name":"Example host"}}`
11 want := make(map[string]interface{})
12 if err := json.Unmarshal([]byte(s), &want); err != nil {
13 t.Fatal(err)
14 }
16 p, err := json.Marshal(Host{
17 Name: "example.com",
18 Address: "192.0.2.1",
19 Address6: "2001:db8::",
20 Groups: []string{"test"},
21 State: HostDown,
22 StateType: StateSoft,
23 CheckCommand: "dummy",
24 DisplayName: "Example host",
25 })
26 if err != nil {
27 t.Fatal(err)
28 }
29 got := make(map[string]interface{})
30 if err := json.Unmarshal(p, &got); err != nil {
31 t.Fatal(err)
32 }
34 if !reflect.DeepEqual(want, got) {
35 t.Fail()
36 }
37 t.Log("want", want, "got", got)
38 }