shirou_gopsutil/mem/mem_plan9_test.go

74 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-12-23 05:54:41 +08:00
//go:build plan9
2021-10-09 06:07:03 +08:00
// +build plan9
package mem
import (
"reflect"
"testing"
)
var virtualMemoryTests = []struct {
mockedRootFS string
stat *VirtualMemoryStat
}{
2021-12-23 05:54:41 +08:00
{
"swap", &VirtualMemoryStat{
Total: 1071185920,
Available: 808370176,
Used: 11436032,
UsedPercent: 1.3949677238843257,
Free: 808370176,
SwapTotal: 655360000,
SwapFree: 655360000,
},
2021-10-09 06:07:03 +08:00
},
}
func TestVirtualMemoryPlan9(t *testing.T) {
for _, tt := range virtualMemoryTests {
t.Run(tt.mockedRootFS, func(t *testing.T) {
t.Setenv("HOST_ROOT", "testdata/plan9/virtualmemory/")
2021-10-09 06:07:03 +08:00
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
}{
2021-12-23 05:54:41 +08:00
{
"swap", &SwapMemoryStat{
Total: 655360000,
Used: 0,
Free: 655360000,
},
2021-10-09 06:07:03 +08:00
},
}
func TestSwapMemoryPlan9(t *testing.T) {
for _, tt := range swapMemoryTests {
t.Run(tt.mockedRootFS, func(t *testing.T) {
t.Setenv("HOST_ROOT", "testdata/plan9/virtualmemory/")
2021-10-09 06:07:03 +08:00
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)
}
})
}
}