github.com/resin-io/docker@v1.13.1/pkg/system/meminfo_unix_test.go (about) 1 // +build linux freebsd 2 3 package system 4 5 import ( 6 "strings" 7 "testing" 8 9 "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 SwapTotal: 3 kB 18 SwapFree: 4 kB 19 Malformed1: 20 Malformed2: 1 21 Malformed3: 2 MB 22 Malformed4: X kB 23 ` 24 meminfo, err := parseMemInfo(strings.NewReader(input)) 25 if err != nil { 26 t.Fatal(err) 27 } 28 if meminfo.MemTotal != 1*units.KiB { 29 t.Fatalf("Unexpected MemTotal: %d", meminfo.MemTotal) 30 } 31 if meminfo.MemFree != 2*units.KiB { 32 t.Fatalf("Unexpected MemFree: %d", meminfo.MemFree) 33 } 34 if meminfo.SwapTotal != 3*units.KiB { 35 t.Fatalf("Unexpected SwapTotal: %d", meminfo.SwapTotal) 36 } 37 if meminfo.SwapFree != 4*units.KiB { 38 t.Fatalf("Unexpected SwapFree: %d", meminfo.SwapFree) 39 } 40 }