Blob
- Date:
- Message:
- Simplify service JSON marshalling We don't need to have a MarshalJSON method just so that it can be created ok. It's clearer to do stuff necessart for object creation at the time of object creation, not way earlier in some unrelated bit of the code. While here simplify the tests to actually test what we're worried about.
- Actions:
- History | Blame | Raw File
1 package icinga3 import (4 "os"5 "testing"6 "time"7 )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 }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 }