-
Notifications
You must be signed in to change notification settings - Fork 13
/
memory_test.go
53 lines (43 loc) · 1005 Bytes
/
memory_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
package main
import (
"io/ioutil"
"sort"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func aggregateStats(stats []*Metric) map[string]int64 {
agg := map[string]int64{}
for _, stat := range stats {
agg[stat.Key] = stat.Value
}
return agg
}
func TestMemory(t *testing.T) {
Convey("Memory", t, func() {
m := &Memory{}
mh := &MetricHandler{}
stats, _ := mh.Collect(m)
So(len(stats) > 10, ShouldBeTrue)
So(len(stats), ShouldEqual, 42)
sort.Sort(stats)
So(stats[0].Key, ShouldEqual, "memory.active")
So(stats[0].Value, ShouldEqual, 61740)
agg := aggregateStats(stats)
So(agg["memory.committed_as"], ShouldEqual, 350856)
Convey("Load", func() {
b := mustRead(t, "proc/meminfo")
m := &Memory{}
e := m.Load(b)
So(e, ShouldBeNil)
So(m.MemTotal, ShouldEqual, 502976)
So(m.Cached, ShouldEqual, 31436)
})
})
}
func mustRead(t *testing.T, p string) []byte {
b, e := ioutil.ReadFile("fixtures/" + p)
if e != nil {
t.Fatal(e)
}
return b
}