9 a17d3f9d 2022-02-11 o // Tests the trickier parts of the custom Unmarshaller functionality.
10 f5fde32e 2022-01-18 o func TestServiceUnmarshal(t *testing.T) {
11 717a9e78 2022-02-02 o f, err := os.Open("testdata/objects/services/9p.io!http")
12 f5fde32e 2022-01-18 o if err != nil {
15 f5fde32e 2022-01-18 o defer f.Close()
16 f5fde32e 2022-01-18 o resp, err := parseResponse(f)
17 f5fde32e 2022-01-18 o if err != nil {
20 a17d3f9d 2022-02-11 o svc := resp.Results[0].(Service)
21 a17d3f9d 2022-02-11 o if svc.LastCheck.IsZero() {
22 a17d3f9d 2022-02-11 o t.Error("zero time")
24 a17d3f9d 2022-02-11 o if !svc.Acknowledgement {
25 a17d3f9d 2022-02-11 o t.Error("should be acknowledged")
27 a17d3f9d 2022-02-11 o if t.Failed() {
32 a17d3f9d 2022-02-11 o func TestServiceMarshalForCreate(t *testing.T) {
33 a17d3f9d 2022-02-11 o want := `{"attrs":{"check_command":"dummy","display_name":"test"}}`
34 a17d3f9d 2022-02-11 o service := Service{
35 a17d3f9d 2022-02-11 o CheckCommand: "dummy",
36 a17d3f9d 2022-02-11 o DisplayName: "test",
37 a17d3f9d 2022-02-11 o LastCheck: time.Now(),
38 a17d3f9d 2022-02-11 o LastCheckResult: CheckResult{
40 a17d3f9d 2022-02-11 o CheckSource: "xxx",
44 a17d3f9d 2022-02-11 o got, err := jsonForCreate(service)
45 a17d3f9d 2022-02-11 o if err != nil {
48 a17d3f9d 2022-02-11 o if want != string(got) {
49 a17d3f9d 2022-02-11 o t.Error("not matching", string(got))