File: mem_solaris_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 (46 lines) | stat: -rw-r--r-- 1,178 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
// SPDX-License-Identifier: BSD-3-Clause
//go:build solaris

package mem

import (
	"testing"

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

const validFile = `swapfile                  dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,1      16 1058800 1058800
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528`

const invalidFile = `swapfile                  dev  swaplo INVALID   free
/dev/zvol/dsk/rpool/swap 256,1      16 1058800 1058800
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528`

func TestParseSwapsCommandOutput_Valid(t *testing.T) {
	stats, err := parseSwapsCommandOutput(validFile)
	require.NoError(t, err)

	assert.Equal(t, SwapDevice{
		Name:      "/dev/zvol/dsk/rpool/swap",
		UsedBytes: 0,
		FreeBytes: 1058800 * 512,
	}, *stats[0])

	assert.Equal(t, SwapDevice{
		Name:      "/dev/dsk/c0t0d0s1",
		UsedBytes: 38080 * 512,
		FreeBytes: 1600528 * 512,
	}, *stats[1])
}

func TestParseSwapsCommandOutput_Invalid(t *testing.T) {
	_, err := parseSwapsCommandOutput(invalidFile)
	assert.Error(t, err)
}

func TestParseSwapsCommandOutput_Empty(t *testing.T) {
	_, err := parseSwapsCommandOutput("")
	assert.Error(t, err)
}