forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartbeat_test.go
66 lines (56 loc) · 2.05 KB
/
heartbeat_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package agent_test
import (
"encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent"
boshvitals "github.com/cloudfoundry/bosh-agent/platform/vitals"
)
func init() {
Describe("Heartbeat", func() {
Context("when all information is available to the heartbeat", func() {
It("serializes heartbeat with all fields", func() {
name := "foo"
index := 0
hb := Heartbeat{
Deployment: "FakeDeployment",
Job: &name,
Index: &index,
JobState: "running",
Vitals: boshvitals.Vitals{
Disk: boshvitals.DiskVitals{
"system": boshvitals.SpecificDiskVitals{},
"ephemeral": boshvitals.SpecificDiskVitals{},
"persistent": boshvitals.SpecificDiskVitals{},
},
},
NodeID: "node-id",
}
expectedJSON := `{"deployment":"FakeDeployment","job":"foo","index":0,"job_state":"running","vitals":{"cpu":{},"disk":{"ephemeral":{},"persistent":{},"system":{}},"mem":{},"swap":{},"uptime":{}},"node_id":"node-id"}`
hbBytes, err := json.Marshal(hb)
Expect(err).ToNot(HaveOccurred())
Expect(string(hbBytes)).To(Equal(expectedJSON))
})
})
Context("when job name, index are not available", func() {
It("serializes job name and index as nulls to indicate that there is no job assigned to this agent", func() {
hb := Heartbeat{
Deployment: "FakeDeployment",
JobState: "running",
Vitals: boshvitals.Vitals{
Disk: boshvitals.DiskVitals{
"system": boshvitals.SpecificDiskVitals{},
"ephemeral": boshvitals.SpecificDiskVitals{},
"persistent": boshvitals.SpecificDiskVitals{},
},
},
NodeID: "node-id",
}
expectedJSON := `{"deployment":"FakeDeployment","job":null,"index":null,"job_state":"running","vitals":{"cpu":{},"disk":{"ephemeral":{},"persistent":{},"system":{}},"mem":{},"swap":{},"uptime":{}},"node_id":"node-id"}`
hbBytes, err := json.Marshal(hb)
Expect(err).ToNot(HaveOccurred())
Expect(string(hbBytes)).To(Equal(expectedJSON))
})
})
})
}