...
1
2
3 package mem
4
5 import (
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 )
10
11 const validFile = `swapfile dev swaplo blocks free
12 /dev/zvol/dsk/rpool/swap 256,1 16 1058800 1058800
13 /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528`
14
15 const invalidFile = `swapfile dev swaplo INVALID free
16 /dev/zvol/dsk/rpool/swap 256,1 16 1058800 1058800
17 /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528`
18
19 func TestParseSwapsCommandOutput_Valid(t *testing.T) {
20 assert := assert.New(t)
21 stats, err := parseSwapsCommandOutput(validFile)
22 assert.NoError(err)
23
24 assert.Equal(*stats[0], SwapDevice{
25 Name: "/dev/zvol/dsk/rpool/swap",
26 UsedBytes: 0,
27 FreeBytes: 1058800 * 512,
28 })
29
30 assert.Equal(*stats[1], SwapDevice{
31 Name: "/dev/dsk/c0t0d0s1",
32 UsedBytes: 38080 * 512,
33 FreeBytes: 1600528 * 512,
34 })
35 }
36
37 func TestParseSwapsCommandOutput_Invalid(t *testing.T) {
38 _, err := parseSwapsCommandOutput(invalidFile)
39 assert.Error(t, err)
40 }
41
42 func TestParseSwapsCommandOutput_Empty(t *testing.T) {
43 _, err := parseSwapsCommandOutput("")
44 assert.Error(t, err)
45 }
46
View as plain text