Example #1
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("vitals construction", func() {
			_, service := buildVitalsService()
			vitals, err := service.Get()

			expectedVitals := map[string]interface{}{
				"cpu": map[string]string{
					"sys":  "10.0",
					"user": "******",
					"wait": "1.0",
				},
				"disk": map[string]interface{}{
					"system": map[string]string{
						"percent":       "50",
						"inode_percent": "10",
					},
					"ephemeral": map[string]string{
						"percent":       "75",
						"inode_percent": "20",
					},
					"persistent": map[string]string{
						"percent":       "100",
						"inode_percent": "75",
					},
				},
				"load": []string{"0.20", "4.55", "1.12"},
				"mem": map[string]string{
					"kb":      "700",
					"percent": "70",
				},
				"swap": map[string]string{
					"kb":      "600",
					"percent": "60",
				},
			}

			Expect(err).ToNot(HaveOccurred())

			boshassert.MatchesJSONMap(GinkgoT(), vitals, expectedVitals)
		})

		It("getting vitals when missing disks", func() {

			statsCollector, service := buildVitalsService()
			statsCollector.DiskStats = map[string]boshstats.DiskStats{
				"/": boshstats.DiskStats{
					DiskUsage:  boshstats.Usage{Used: 100, Total: 200},
					InodeUsage: boshstats.Usage{Used: 50, Total: 500},
				},
			}

			vitals, err := service.Get()
			Expect(err).ToNot(HaveOccurred())

			boshassert.LacksJSONKey(GinkgoT(), vitals.Disk, "ephemeral")
			boshassert.LacksJSONKey(GinkgoT(), vitals.Disk, "persistent")
		})
		It("get getting vitals on system disk error", func() {

			statsCollector, service := buildVitalsService()
			statsCollector.DiskStats = map[string]boshstats.DiskStats{}

			_, err := service.Get()
			Expect(err).To(HaveOccurred())
		})
	})
}
Example #2
0
						BoshProtocol: "1",
						VM:           boshsettings.VM{Name: "vm-abc-def"},
						Ntp: boshntp.Info{
							Offset:    "0.34958",
							Timestamp: "12 Oct 17:37:58",
						},
					}
					expectedSpec.Deployment = "fake-deployment"

					state, err := action.Run()
					Expect(err).ToNot(HaveOccurred())

					Expect(state.AgentID).To(Equal(expectedSpec.AgentID))
					Expect(state.JobState).To(Equal(expectedSpec.JobState))
					Expect(state.Deployment).To(Equal(expectedSpec.Deployment))
					boshassert.LacksJSONKey(GinkgoT(), state, "vitals")

					Expect(state).To(Equal(expectedSpec))
				})

				It("returns state in full format", func() {
					settingsService.Settings.AgentID = "my-agent-id"
					settingsService.Settings.VM.Name = "vm-abc-def"

					jobSupervisor.StatusStatus = "running"
					jobSupervisor.ProcessesStatus = []boshjobsuper.Process{
						boshjobsuper.Process{
							Name:  "fake-process-name-1",
							State: "running",
						},
						boshjobsuper.Process{
Example #3
0
		Expect(err).ToNot(HaveOccurred())

		boshassert.MatchesJSONMap(GinkgoT(), vitals, expectedVitals)
	})

	It("getting vitals when missing disks", func() {

		statsCollector, service := buildVitalsService()
		statsCollector.DiskStats = map[string]boshstats.DiskStats{
			"/": boshstats.DiskStats{
				DiskUsage:  boshstats.Usage{Used: 100, Total: 200},
				InodeUsage: boshstats.Usage{Used: 50, Total: 500},
			},
		}

		vitals, err := service.Get()
		Expect(err).ToNot(HaveOccurred())

		boshassert.LacksJSONKey(GinkgoT(), vitals.Disk, "ephemeral")
		boshassert.LacksJSONKey(GinkgoT(), vitals.Disk, "persistent")
	})
	It("get getting vitals on system disk error", func() {

		statsCollector, service := buildVitalsService()
		statsCollector.DiskStats = map[string]boshstats.DiskStats{}

		_, err := service.Get()
		Expect(err).To(HaveOccurred())
	})
})