Merge pull request #18820 from vdemeester/oups-fix-api-ps-unit-tests

Fix the api/client/ps unit tests.
This commit is contained in:
Sebastiaan van Stijn 2015-12-21 14:01:27 +01:00
commit 67620bc028
1 changed files with 17 additions and 12 deletions

View File

@ -2,12 +2,17 @@ package ps
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
"time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
) )
func TestFormat(t *testing.T) { func TestFormat(t *testing.T) {
unixTime := time.Now().Add(-50 * time.Hour).Unix()
expectedTime := time.Unix(unixTime, 0).String()
contexts := []struct { contexts := []struct {
context Context context Context
expected string expected string
@ -33,8 +38,8 @@ func TestFormat(t *testing.T) {
Format: "table", Format: "table",
}, },
`CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
containerID1 ubuntu "" 45 years ago foobar_baz containerID1 ubuntu "" 2 days ago foobar_baz
containerID2 ubuntu "" 45 years ago foobar_bar containerID2 ubuntu "" 2 days ago foobar_bar
`, `,
}, },
{ {
@ -69,10 +74,10 @@ containerID2 ubuntu "" 45 years ago
Context{ Context{
Format: "raw", Format: "raw",
}, },
`container_id: containerID1 fmt.Sprintf(`container_id: containerID1
image: ubuntu image: ubuntu
command: "" command: ""
created_at: 1970-01-01 00:00:00 +0000 UTC created_at: %s
status: status:
names: foobar_baz names: foobar_baz
labels: labels:
@ -81,23 +86,23 @@ ports:
container_id: containerID2 container_id: containerID2
image: ubuntu image: ubuntu
command: "" command: ""
created_at: 1970-01-01 00:00:00 +0000 UTC created_at: %s
status: status:
names: foobar_bar names: foobar_bar
labels: labels:
ports: ports:
`, `, expectedTime, expectedTime),
}, },
{ {
Context{ Context{
Format: "raw", Format: "raw",
Size: true, Size: true,
}, },
`container_id: containerID1 fmt.Sprintf(`container_id: containerID1
image: ubuntu image: ubuntu
command: "" command: ""
created_at: 1970-01-01 00:00:00 +0000 UTC created_at: %s
status: status:
names: foobar_baz names: foobar_baz
labels: labels:
@ -107,14 +112,14 @@ size: 0 B
container_id: containerID2 container_id: containerID2
image: ubuntu image: ubuntu
command: "" command: ""
created_at: 1970-01-01 00:00:00 +0000 UTC created_at: %s
status: status:
names: foobar_bar names: foobar_bar
labels: labels:
ports: ports:
size: 0 B size: 0 B
`, `, expectedTime, expectedTime),
}, },
{ {
Context{ Context{
@ -141,8 +146,8 @@ size: 0 B
for _, context := range contexts { for _, context := range contexts {
containers := []types.Container{ containers := []types.Container{
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"}, {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime},
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime},
} }
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
context.context.Output = out context.context.Output = out