github.com/dougm/docker@v1.5.0/pkg/system/meminfo_linux_test.go (about)

     1  package system
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/pkg/units"
     8  )
     9  
    10  func TestMemInfo(t *testing.T) {
    11  	const input = `
    12  	MemTotal:      1 kB
    13  	MemFree:       2 kB
    14  	SwapTotal:     3 kB
    15  	SwapFree:      4 kB
    16  	Malformed1:
    17  	Malformed2:    1
    18  	Malformed3:    2 MB
    19  	Malformed4:    X kB
    20  	`
    21  	meminfo, err := parseMemInfo(strings.NewReader(input))
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  	if meminfo.MemTotal != 1*units.KiB {
    26  		t.Fatalf("Unexpected MemTotal: %d", meminfo.MemTotal)
    27  	}
    28  	if meminfo.MemFree != 2*units.KiB {
    29  		t.Fatalf("Unexpected MemFree: %d", meminfo.MemFree)
    30  	}
    31  	if meminfo.SwapTotal != 3*units.KiB {
    32  		t.Fatalf("Unexpected SwapTotal: %d", meminfo.SwapTotal)
    33  	}
    34  	if meminfo.SwapFree != 4*units.KiB {
    35  		t.Fatalf("Unexpected SwapFree: %d", meminfo.SwapFree)
    36  	}
    37  }