forked from cloudfoundry/gosigar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigar_interface_test.go
186 lines (156 loc) · 4.11 KB
/
sigar_interface_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package sigar
import (
"os"
"path/filepath"
"runtime"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Sigar", func() {
var invalidPid = 666666
It("cpu", func() {
cpu := Cpu{}
err := cpu.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
})
It("load average", func() {
avg := LoadAverage{}
err := avg.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
})
It("uptime", func() {
uptime := Uptime{}
err := uptime.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(uptime.Length).To(BeNumerically(">", 0))
})
It("mem", func() {
mem := Mem{}
err := mem.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(mem.Total).To(BeNumerically(">", 0))
Expect(mem.Used + mem.Free).To(BeNumerically("<=", mem.Total))
})
It("swap", func() {
swap := Swap{}
err := swap.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(swap.Used + swap.Free).To(BeNumerically("<=", swap.Total))
})
It("cpu list", func() {
cpulist := CpuList{}
err := cpulist.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
nsigar := len(cpulist.List)
numcpu := runtime.NumCPU()
Expect(nsigar).To(Equal(numcpu))
})
It("file system list", func() {
fslist := FileSystemList{}
err := fslist.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(len(fslist.List)).To(BeNumerically(">", 0))
})
It("file system usage", func() {
fsusage := FileSystemUsage{}
err := fsusage.Get("/")
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
err = fsusage.Get("T O T A L L Y B O G U S")
Expect(err).To(HaveOccurred())
})
It("proc list", func() {
pids := ProcList{}
err := pids.Get()
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(len(pids.List)).To(BeNumerically(">", 2))
err = pids.Get()
Expect(err).ToNot(HaveOccurred())
})
It("proc state", func() {
state := ProcState{}
err := state.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect([]RunState{RunStateRun, RunStateSleep}).To(ContainElement(state.State))
Expect([]string{"go", "ginkgo"}).To(ContainElement(state.Name))
err = state.Get(invalidPid)
Expect(err).To(HaveOccurred())
})
It("proc cpu", func() {
pCpu := ProcCpu{}
err := pCpu.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
err = pCpu.Get(invalidPid)
Expect(err).To(HaveOccurred())
})
It("proc mem", func() {
mem := ProcMem{}
err := mem.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
err = mem.Get(invalidPid)
Expect(err).To(HaveOccurred())
})
It("proc time", func() {
time := ProcTime{}
err := time.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
err = time.Get(invalidPid)
Expect(err).To(HaveOccurred())
})
It("proc args", func() {
args := ProcArgs{}
err := args.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect(len(args.List)).To(BeNumerically(">=", 1))
})
It("proc exe", func() {
exe := ProcExe{}
err := exe.Get(os.Getppid())
if err == ErrNotImplemented {
Skip("Not implemented on " + runtime.GOOS)
}
Expect(err).ToNot(HaveOccurred())
Expect([]string{"go", "ginkgo"}).To(ContainElement(filepath.Base(exe.Name)))
})
})