File: mem_plan9_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 (73 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: BSD-3-Clause
//go:build plan9

package mem

import (
	"reflect"
	"testing"
)

var virtualMemoryTests = []struct {
	mockedRootFS string
	stat         *VirtualMemoryStat
}{
	{
		"swap", &VirtualMemoryStat{
			Total:       1071185920,
			Available:   808370176,
			Used:        11436032,
			UsedPercent: 1.3949677238843257,
			Free:        808370176,
			SwapTotal:   655360000,
			SwapFree:    655360000,
		},
	},
}

func TestVirtualMemoryPlan9(t *testing.T) {
	for _, tt := range virtualMemoryTests {
		t.Run(tt.mockedRootFS, func(t *testing.T) {
			t.Setenv("HOST_ROOT", "testdata/plan9/virtualmemory/")

			stat, err := VirtualMemory()
			skipIfNotImplementedErr(t, err)
			if err != nil {
				t.Errorf("error %v", err)
			}
			if !reflect.DeepEqual(stat, tt.stat) {
				t.Errorf("got: %+v\nwant: %+v", stat, tt.stat)
			}
		})
	}
}

var swapMemoryTests = []struct {
	mockedRootFS string
	swap         *SwapMemoryStat
}{
	{
		"swap", &SwapMemoryStat{
			Total: 655360000,
			Used:  0,
			Free:  655360000,
		},
	},
}

func TestSwapMemoryPlan9(t *testing.T) {
	for _, tt := range swapMemoryTests {
		t.Run(tt.mockedRootFS, func(t *testing.T) {
			t.Setenv("HOST_ROOT", "testdata/plan9/virtualmemory/")

			swap, err := SwapMemory()
			skipIfNotImplementedErr(t, err)
			if err != nil {
				t.Errorf("error %v", err)
			}
			if !reflect.DeepEqual(swap, tt.swap) {
				t.Errorf("got: %+v\nwant: %+v", swap, tt.swap)
			}
		})
	}
}