github.com/rentongzhang/docker@v1.8.2-rc1/api/client/stats_unit_test.go (about) 1 package client 2 3 import ( 4 "bytes" 5 "sync" 6 "testing" 7 ) 8 9 func TestDisplay(t *testing.T) { 10 c := &containerStats{ 11 Name: "app", 12 CPUPercentage: 30.0, 13 Memory: 100 * 1024 * 1024.0, 14 MemoryLimit: 2048 * 1024 * 1024.0, 15 MemoryPercentage: 100.0 / 2048.0 * 100.0, 16 NetworkRx: 100 * 1024 * 1024, 17 NetworkTx: 800 * 1024 * 1024, 18 mu: sync.RWMutex{}, 19 } 20 var b bytes.Buffer 21 if err := c.Display(&b); err != nil { 22 t.Fatalf("c.Display() gave error: %s", err) 23 } 24 got := b.String() 25 want := "app\t30.00%\t104.9 MB/2.147 GB\t4.88%\t104.9 MB/838.9 MB\n" 26 if got != want { 27 t.Fatalf("c.Display() = %q, want %q", got, want) 28 } 29 }