-
Notifications
You must be signed in to change notification settings - Fork 13
/
cpu_test.go
50 lines (40 loc) · 1.13 KB
/
cpu_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
package main
import (
"sort"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestCpu(t *testing.T) {
Convey("MetricHandler", t, func() {
mh := &MetricHandler{}
stats, e := mh.Collect(&Cpu{})
So(e, ShouldBeNil)
So(len(stats), ShouldEqual, 25)
sort.Sort(stats)
So(stats[0].Key, ShouldEqual, "cpu.btime")
user := stats[23]
So(user.Key, ShouldEqual, "cpu.user")
So(user.Tags["total"], ShouldEqual, "")
So(user.Tags["cpu_id"], ShouldEqual, "0")
userCpu := stats[24]
So(userCpu.Key, ShouldEqual, "cpu.user")
So(userCpu.Tags["total"], ShouldEqual, "true")
So(userCpu.Tags["cpu_id"], ShouldEqual, "")
Convey("Load", func() {
c := &Cpu{}
b := mustRead(t, "proc/stat")
e := c.Load(b)
So(e, ShouldBeNil)
So(len(c.Cpus), ShouldEqual, 2)
So(c.Cpus[0].Id, ShouldEqual, "")
So(c.Cpus[0].User, ShouldEqual, 3700)
So(c.Cpus[1].Id, ShouldEqual, "0")
So(c.Cpus[1].User, ShouldEqual, 3701)
So(c.Ctxt, ShouldEqual, 957584)
So(c.Btime, ShouldEqual, 1372481686)
So(c.Processes, ShouldEqual, 42476)
So(c.ProcsRunning, ShouldEqual, 1)
So(c.ProcsBlocked, ShouldEqual, 3)
})
})
}