10 dd0af5f7 2022-01-18 o func TestHostMarshal(t *testing.T) {
11 46ca0f68 2022-02-01 o b := []byte(`{"attrs":{"address":"192.0.2.1","address6":"2001:db8::","check_command":"dummy","display_name":"Example host","groups":["test"]}}`)
12 dd0af5f7 2022-01-18 o want := make(map[string]interface{})
13 46ca0f68 2022-02-01 o if err := json.Unmarshal(b, &want); err != nil {
17 dd0af5f7 2022-01-18 o p, err := json.Marshal(Host{
18 dd0af5f7 2022-01-18 o Name: "example.com",
19 dd0af5f7 2022-01-18 o Address: "192.0.2.1",
20 dd0af5f7 2022-01-18 o Address6: "2001:db8::",
21 dd0af5f7 2022-01-18 o Groups: []string{"test"},
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 46ca0f68 2022-02-01 o t.Log(string(p))
30 dd0af5f7 2022-01-18 o got := make(map[string]interface{})
31 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)
40 562d5c1e 2022-01-19 o func TestHostUnmarshal(t *testing.T) {
42 562d5c1e 2022-01-19 o Name: "example.com",
44 562d5c1e 2022-01-19 o Groups: []string{"example"},
45 562d5c1e 2022-01-19 o State: HostDown,
46 562d5c1e 2022-01-19 o StateType: StateSoft,
47 562d5c1e 2022-01-19 o CheckCommand: "hostalive",
48 562d5c1e 2022-01-19 o DisplayName: "example.com",
49 562d5c1e 2022-01-19 o Acknowledgement: false,
51 562d5c1e 2022-01-19 o f, err := os.Open("testdata/hosts.json")
52 562d5c1e 2022-01-19 o if err != nil {
55 562d5c1e 2022-01-19 o defer f.Close()
56 562d5c1e 2022-01-19 o resp, err := parseResponse(f)
57 562d5c1e 2022-01-19 o if err != nil {
61 562d5c1e 2022-01-19 o for _, r := range resp.Results {
63 562d5c1e 2022-01-19 o if h.Name == "example.com" {
68 562d5c1e 2022-01-19 o if !reflect.DeepEqual(want, got) {
71 562d5c1e 2022-01-19 o t.Logf("want %+v, got %+v", want, got)