File: mem_darwin_test.go

package info (click to toggle)
golang-github-shirou-gopsutil 4.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,824 kB
  • sloc: makefile: 76; ansic: 19; sh: 11
file content (48 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download
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
// SPDX-License-Identifier: BSD-3-Clause
//go:build darwin

package mem

import (
	"strconv"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestVirtualMemoryDarwin(t *testing.T) {
	v, err := VirtualMemory()
	require.NoError(t, err)

	outBytes, err := invoke.Command("/usr/sbin/sysctl", "hw.memsize")
	require.NoError(t, err)
	outString := string(outBytes)
	outString = strings.TrimSpace(outString)
	outParts := strings.Split(outString, " ")
	actualTotal, err := strconv.ParseInt(outParts[1], 10, 64)
	require.NoError(t, err)
	assert.Equal(t, uint64(actualTotal), v.Total)

	assert.Positive(t, v.Available)
	assert.Equal(t, v.Available, v.Free+v.Inactive, "%v", v)

	assert.Positive(t, v.Used)
	assert.Less(t, v.Used, v.Total)

	assert.Positive(t, v.UsedPercent)
	assert.Less(t, v.UsedPercent, 100.0)

	assert.Positive(t, v.Free)
	assert.Less(t, v.Free, v.Available)

	assert.Positive(t, v.Active)
	assert.Less(t, v.Active, v.Total)

	assert.Positive(t, v.Inactive)
	assert.Less(t, v.Inactive, v.Total)

	assert.Positive(t, v.Wired)
	assert.Less(t, v.Wired, v.Total)
}