service_test.go (997B)
1 package icinga 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 ) 8 9 // Tests the trickier parts of the custom Unmarshaller functionality. 10 func TestServiceUnmarshal(t *testing.T) { 11 f, err := os.Open("testdata/objects/services/9p.io!http") 12 if err != nil { 13 t.Fatal(err) 14 } 15 defer f.Close() 16 resp, err := parseResponse(f) 17 if err != nil { 18 t.Fatal(err) 19 } 20 svc := resp.Results[0].(Service) 21 if svc.LastCheck.IsZero() { 22 t.Error("zero time") 23 } 24 if !svc.Acknowledgement { 25 t.Error("should be acknowledged") 26 } 27 if t.Failed() { 28 t.Log(svc) 29 } 30 } 31 32 func TestServiceMarshalForCreate(t *testing.T) { 33 want := `{"attrs":{"check_command":"dummy","display_name":"test"}}` 34 service := Service{ 35 CheckCommand: "dummy", 36 DisplayName: "test", 37 LastCheck: time.Now(), 38 LastCheckResult: CheckResult{ 39 Output: "xxx", 40 CheckSource: "xxx", 41 Command: nil, 42 }, 43 } 44 got, err := jsonForCreate(service) 45 if err != nil { 46 t.Fatal(err) 47 } 48 if want != string(got) { 49 t.Error("not matching", string(got)) 50 } 51 }