2016-06-06 12:47:18 -04:00
|
|
|
package container
|
2015-04-08 00:25:41 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2015-08-19 23:46:21 -04:00
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-04-08 00:25:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDisplay(t *testing.T) {
|
|
|
|
c := &containerStats{
|
|
|
|
Name: "app",
|
|
|
|
CPUPercentage: 30.0,
|
|
|
|
Memory: 100 * 1024 * 1024.0,
|
|
|
|
MemoryLimit: 2048 * 1024 * 1024.0,
|
|
|
|
MemoryPercentage: 100.0 / 2048.0 * 100.0,
|
|
|
|
NetworkRx: 100 * 1024 * 1024,
|
|
|
|
NetworkTx: 800 * 1024 * 1024,
|
2015-07-26 04:14:00 -04:00
|
|
|
BlockRead: 100 * 1024 * 1024,
|
|
|
|
BlockWrite: 800 * 1024 * 1024,
|
2015-12-15 14:15:43 -05:00
|
|
|
PidsCurrent: 1,
|
2015-04-08 00:25:41 -04:00
|
|
|
}
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := c.Display(&b); err != nil {
|
|
|
|
t.Fatalf("c.Display() gave error: %s", err)
|
|
|
|
}
|
|
|
|
got := b.String()
|
2016-09-04 17:44:34 -04:00
|
|
|
want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t105 MB / 839 MB\t105 MB / 839 MB\t1\n"
|
2015-04-08 00:25:41 -04:00
|
|
|
if got != want {
|
|
|
|
t.Fatalf("c.Display() = %q, want %q", got, want)
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 23:46:21 -04:00
|
|
|
|
|
|
|
func TestCalculBlockIO(t *testing.T) {
|
|
|
|
blkio := types.BlkioStats{
|
|
|
|
IoServiceBytesRecursive: []types.BlkioStatEntry{{8, 0, "read", 1234}, {8, 1, "read", 4567}, {8, 0, "write", 123}, {8, 1, "write", 456}},
|
|
|
|
}
|
|
|
|
blkRead, blkWrite := calculateBlockIO(blkio)
|
|
|
|
if blkRead != 5801 {
|
|
|
|
t.Fatalf("blkRead = %d, want 5801", blkRead)
|
|
|
|
}
|
|
|
|
if blkWrite != 579 {
|
|
|
|
t.Fatalf("blkWrite = %d, want 579", blkWrite)
|
|
|
|
}
|
|
|
|
}
|