-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanFree_test.go
101 lines (88 loc) · 2.37 KB
/
cleanFree_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
package main
import "testing"
func TestCanParseRAMCommandOutput(t *testing.T) {
raw := `
total used free shared buffers cache available
Mem: 15Gi 5.7Gi 5.9Gi 1.2Gi 434Mi 3.6Gi 8.6Gi
Swap: 15Gi 0B 15Gi`
mem, swap := cleanFree(raw)
if val, ok := mem["total"]; ok {
if val != "15Gi" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'total' was not set correctly")
}
if val, ok := mem["used"]; ok {
if val != "5.7Gi" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'used' was not set correctly")
}
if val, ok := mem["free"]; ok {
if val != "5.9Gi" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'free' was not set correctly")
}
if val, ok := mem["shared"]; ok {
if val != "1.2Gi" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'shared' was not set correctly")
}
if val, ok := swap["total"]; ok {
if val != "15Gi" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'total' was not set correctly")
}
}
func TestCanParseRAMCommandOutputFromCentOSOutput(t *testing.T) {
raw := `
total used free shared buffers cached
Mem: 3.7G 2.7G 1.0G 1.2M 220M 949M
-/+ buffers/cache: 1.6G 2.2G
Swap: 1.0G 41M 982M
`
mem, swap := cleanFree(raw)
if val, ok := mem["total"]; ok {
if val != "3.7G" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'total' was not set correctly")
}
if val, ok := mem["used"]; ok {
if val != "2.7G" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'used' was not set correctly")
}
if val, ok := mem["free"]; ok {
if val != "1.0G" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'free' was not set correctly")
}
if val, ok := mem["shared"]; ok {
if val != "1.2M" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'shared' was not set correctly")
}
if val, ok := swap["total"]; ok {
if val != "1.0G" {
t.Error("Parsed values for SWAP are incorrect")
}
} else {
t.Error("the key 'total' was not set correctly")
}
}