-
Notifications
You must be signed in to change notification settings - Fork 5
/
system_test.go
136 lines (111 loc) · 2.76 KB
/
system_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
package iopipe
import (
"testing"
"github.com/shirou/gopsutil/cpu"
. "github.com/smartystreets/goconvey/convey"
)
func BenchmarkSystem_ReadBootID(b *testing.B) {
for i := 0; i < b.N; i++ {
readBootID()
}
}
func TestSystem_readBootID(t *testing.T) {
Convey("readBootId should return the system boot ID", t, func() {
bootID := readBootID()
So(bootID, ShouldNotEqual, nil)
So(bootID, ShouldNotEqual, "")
})
}
func BenchmarkSystem_ReadDisk(b *testing.B) {
for i := 0; i < b.N; i++ {
readDisk()
}
}
func TestSystem_readDisk(t *testing.T) {
Convey("readDisk should return stats about /tmp", t, func() {
d := readDisk()
So(d.totalMiB, ShouldNotBeNil)
So(d.usedMiB, ShouldNotBeNil)
So(d.usedPercentage, ShouldNotBeNil)
})
}
func BenchmarkSystem_ReadHostname(b *testing.B) {
for i := 0; i < b.N; i++ {
readDisk()
}
}
func benchmarkReadHostname(b *testing.B) {
for i := 0; i < b.N; i++ {
readHostname()
}
}
func TestSystem_readHostname(t *testing.T) {
Convey("readHostname should return the system hostname", t, func() {
hostname := readHostname()
So(hostname, ShouldNotEqual, nil)
So(hostname, ShouldNotEqual, "")
})
}
func BenchmarkSystem_ReadMemInfo(b *testing.B) {
for i := 0; i < b.N; i++ {
readMemInfo()
}
}
func TestSystem_readMemInfo(t *testing.T) {
Convey("readMemInfo should return memory stats", t, func() {
m := readMemInfo()
So(m.available, ShouldNotBeNil)
So(m.free, ShouldNotBeNil)
So(m.total, ShouldNotBeNil)
So(m.totalMiB, ShouldNotBeNil)
So(m.used, ShouldNotBeNil)
So(m.usedMiB, ShouldNotBeNil)
So(m.usedPercentage, ShouldNotBeNil)
})
}
func BenchmarkSystem_ReadPIDStat(b *testing.B) {
for i := 0; i < b.N; i++ {
readPIDStat()
}
}
func TestSystem_readPIDStat(t *testing.T) {
Convey("readPIDStat should return process cpu times", t, func() {
p := readPIDStat()
So(p.cstime, ShouldNotBeNil)
So(p.cutime, ShouldNotBeNil)
So(p.stime, ShouldNotBeNil)
So(p.utime, ShouldNotBeNil)
})
}
func BenchmarkSystem_ReadPIDStatus(b *testing.B) {
for i := 0; i < b.N; i++ {
readPIDStatus()
}
}
func TestSystem_readPIDStatus(t *testing.T) {
Convey("readPIDStatus should reutrn fd, thread count and rss", t, func() {
p := readPIDStatus()
So(p.fdSize, ShouldNotBeNil)
So(p.threads, ShouldNotBeNil)
So(p.vmRss, ShouldNotBeNil)
})
}
func BenchmarkSystem_ReadSystemStat(b *testing.B) {
for i := 0; i < b.N; i++ {
readSystemStat()
}
}
func TestSystem_readSystemStat(t *testing.T) {
Convey("readSystemStat should read return system cpu times", t, func() {
s := readSystemStat()
c, _ := cpu.Counts(false)
So(len(s), ShouldEqual, c)
for _, t := range s {
So(t.idle, ShouldNotBeNil)
So(t.irq, ShouldNotBeNil)
So(t.nice, ShouldNotBeNil)
So(t.sys, ShouldNotBeNil)
So(t.user, ShouldNotBeNil)
}
})
}