forked from shirou/gopsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem_darwin_test.go
46 lines (34 loc) · 1.01 KB
/
mem_darwin_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
// +build darwin
package mem
import (
"strconv"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVirtualMemoryDarwin(t *testing.T) {
v, err := VirtualMemory()
assert.Nil(t, err)
outBytes, err := invoke.Command("/usr/sbin/sysctl", "hw.memsize")
assert.Nil(t, err)
outString := string(outBytes)
outString = strings.TrimSpace(outString)
outParts := strings.Split(outString, " ")
actualTotal, err := strconv.ParseInt(outParts[1], 10, 64)
assert.Nil(t, err)
assert.Equal(t, uint64(actualTotal), v.Total)
assert.True(t, v.Available > 0)
assert.Equal(t, v.Available, v.Free+v.Inactive, "%v", v)
assert.True(t, v.Used > 0)
assert.True(t, v.Used < v.Total)
assert.True(t, v.UsedPercent > 0)
assert.True(t, v.UsedPercent < 100)
assert.True(t, v.Free > 0)
assert.True(t, v.Free < v.Available)
assert.True(t, v.Active > 0)
assert.True(t, v.Active < v.Total)
assert.True(t, v.Inactive > 0)
assert.True(t, v.Inactive < v.Total)
assert.True(t, v.Wired > 0)
assert.True(t, v.Wired < v.Total)
}