-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmeminfo_test.go
59 lines (50 loc) · 1.47 KB
/
meminfo_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
package procmeminfo
import (
"testing"
)
func TestUpdate(t *testing.T) {
memInfo := &MemInfo{}
err := memInfo.Update()
if err != nil {
t.Fatal(err)
}
validKeys := []string{"MemTotal", "MemFree", "Buffers", "Cached",
"SwapCached", "Active", "Inactive", "Active(anon)", "Inactive(anon)",
"Active(file)", "Inactive(file)", "Unevictable", "Mlocked", "SwapTotal",
"SwapFree", "Dirty", "Writeback", "AnonPages", "Mapped", "Shmem", "Slab",
"SReclaimable", "SUnreclaim", "KernelStack", "PageTables", "NFS_Unstable",
"Bounce", "WritebackTmp", "CommitLimit", "Committed_AS", "VmallocTotal",
"VmallocUsed", "VmallocChunk", "HardwareCorrupted", "AnonHugePages",
"HugePages_Total", "HugePages_Free", "HugePages_Rsvd", "HugePages_Surp",
"Hugepagesize", "DirectMap4k", "DirectMap2M"}
for _, k := range validKeys {
_, ok := (*memInfo)[k]
if !ok {
t.Error("Missing the key:", k)
}
}
}
func TestTotal(t *testing.T) {
meminfo := &MemInfo{"MemTotal": 44}
if meminfo.Total() != 44 {
t.Error(meminfo.Total())
}
}
func TestAvailable(t *testing.T) {
meminfo := &MemInfo{"MemFree": 1, "Buffers": 1, "Cached": 1}
if meminfo.Available() != 3 {
t.Error(meminfo.Available())
}
}
func TestUsed(t *testing.T) {
meminfo := &MemInfo{"MemTotal": 10, "MemFree": 1, "Buffers": 1, "Cached": 1}
if meminfo.Used() != 7 {
t.Error(meminfo.Used())
}
}
func TestSwap(t *testing.T) {
meminfo := &MemInfo{"SwapTotal": 10, "SwapFree": 9}
if meminfo.Swap() != 10 {
t.Error(meminfo.Swap())
}
}