10 func TestHostMarshal(t *testing.T) {
11 s := `{"attrs":{"address":"192.0.2.1","address6":"2001:db8::","groups":["test"],"check_command":"dummy","display_name":"Example host"}}`
12 want := make(map[string]interface{})
13 if err := json.Unmarshal([]byte(s), &want); err != nil {
17 p, err := json.Marshal(Host{
20 Address6: "2001:db8::",
21 Groups: []string{"test"},
24 CheckCommand: "dummy",
25 DisplayName: "Example host",
30 got := make(map[string]interface{})
31 if err := json.Unmarshal(p, &got); err != nil {
35 if !reflect.DeepEqual(want, got) {
38 t.Log("want", want, "got", got)
41 func TestHostUnmarshal(t *testing.T) {
45 Groups: []string{"example"},
48 CheckCommand: "hostalive",
49 DisplayName: "example.com",
50 Acknowledgement: false,
52 f, err := os.Open("testdata/hosts.json")
57 resp, err := parseResponse(f)
62 for _, r := range resp.Results {
64 if h.Name == "example.com" {
69 if !reflect.DeepEqual(want, got) {
72 t.Logf("want %+v, got %+v", want, got)