forked from cloudfoundry/gosigar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigar_windows_test.go
98 lines (82 loc) · 2.32 KB
/
sigar_windows_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package sigar
import (
"os"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("SigarWindows", func() {
Describe("Uptime", func() {
It("returns the uptime", func() {
var u Uptime
Expect(u.Get()).To(Succeed())
Expect(u.Length).To(BeNumerically(">", 0))
})
})
Describe("Memory", func() {
It("gets the total memory", func() {
var mem Mem
Expect(mem.Get()).To(Succeed())
Expect(mem.Total).To(BeNumerically(">", 0))
Expect(mem.Free).To(BeNumerically(">", 0))
Expect(mem.ActualFree).To(BeNumerically(">", 0))
Expect(mem.Used).To(BeNumerically(">", 0))
})
})
Describe("Disk", func() {
It("gets the total disk space", func() {
var usage FileSystemUsage
Expect(usage.Get(os.TempDir())).To(Succeed())
Expect(usage.Total).To(BeNumerically(">", 0))
Expect(usage.Free).To(BeNumerically(">", 0))
Expect(usage.Used).To(BeNumerically(">", 0))
})
})
Describe("CPU", func() {
It("gets the cumulative number of cpu ticks", func() {
var old Cpu
Expect(old.Get()).To(Succeed())
var cpu Cpu
Eventually(func() uint64 {
cpu.Get()
return cpu.Idle
}, time.Second*10).Should(BeNumerically(">", old.Idle))
Eventually(func() uint64 {
cpu.Get()
return cpu.User
}, time.Second*10).Should(BeNumerically(">", old.User))
Eventually(func() uint64 {
cpu.Get()
return cpu.Sys
}, time.Second*10).Should(BeNumerically(">", old.Sys))
})
})
Context("when parsing wmic output", func() {
It("should parse the output", func() {
res := strings.Join([]string{
`AllocatedBaseSize=4791`,
`CurrentUsage=393`,
`Description=C:\pagefile.sys`,
`InstallDate=20151221103329.285091-480`,
`Name=C:\pagefile.sys`,
`PeakUsage=2916`,
`Status=`,
`TempPageFile=FALSE`,
}, "\r\n")
out := []byte(res)
num, err := parseWmicOutput(out, []byte("CurrentUsage"))
Expect(err).To(BeNil())
Expect(num).To(Equal(uint64(393)))
num, err = parseWmicOutput(out, []byte("AllocatedBaseSize"))
Expect(err).To(BeNil())
Expect(num).To(Equal(uint64(4791)))
num, err = parseWmicOutput(out, []byte("Status"))
Expect(err).To(HaveOccurred())
Expect(num).To(Equal(uint64(0)))
num, err = parseWmicOutput(out, []byte("Current"))
Expect(err).To(HaveOccurred())
Expect(num).To(Equal(uint64(0)))
})
})
})