github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/system/meminfo_unix_test.go (about) 1 // +build linux freebsd 2 3 package system // import "github.com/demonoid81/moby/pkg/system" 4 5 import ( 6 "strings" 7 "testing" 8 9 units "github.com/docker/go-units" 10 ) 11 12 // TestMemInfo tests parseMemInfo with a static meminfo string 13 func TestMemInfo(t *testing.T) { 14 const input = ` 15 MemTotal: 1 kB 16 MemFree: 2 kB 17 MemAvailable: 3 kB 18 SwapTotal: 4 kB 19 SwapFree: 5 kB 20 Malformed1: 21 Malformed2: 1 22 Malformed3: 2 MB 23 Malformed4: X kB 24 ` 25 meminfo, err := parseMemInfo(strings.NewReader(input)) 26 if err != nil { 27 t.Fatal(err) 28 } 29 if meminfo.MemTotal != 1*units.KiB { 30 t.Fatalf("Unexpected MemTotal: %d", meminfo.MemTotal) 31 } 32 if meminfo.MemFree != 3*units.KiB { 33 t.Fatalf("Unexpected MemFree: %d", meminfo.MemFree) 34 } 35 if meminfo.SwapTotal != 4*units.KiB { 36 t.Fatalf("Unexpected SwapTotal: %d", meminfo.SwapTotal) 37 } 38 if meminfo.SwapFree != 5*units.KiB { 39 t.Fatalf("Unexpected SwapFree: %d", meminfo.SwapFree) 40 } 41 }