|
@@ -1,7 +1,6 @@
|
|
package ps
|
|
package ps
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bytes"
|
|
|
|
"reflect"
|
|
"reflect"
|
|
"strings"
|
|
"strings"
|
|
"testing"
|
|
"testing"
|
|
@@ -24,8 +23,11 @@ func TestContainerPsContext(t *testing.T) {
|
|
call func() string
|
|
call func() string
|
|
}{
|
|
}{
|
|
{types.Container{ID: containerID}, true, stringid.TruncateID(containerID), idHeader, ctx.ID},
|
|
{types.Container{ID: containerID}, true, stringid.TruncateID(containerID), idHeader, ctx.ID},
|
|
|
|
+ {types.Container{ID: containerID}, false, containerID, idHeader, ctx.ID},
|
|
{types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", namesHeader, ctx.Names},
|
|
{types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", namesHeader, ctx.Names},
|
|
{types.Container{Image: "ubuntu"}, true, "ubuntu", imageHeader, ctx.Image},
|
|
{types.Container{Image: "ubuntu"}, true, "ubuntu", imageHeader, ctx.Image},
|
|
|
|
+ {types.Container{Image: "verylongimagename"}, true, "verylongimag", imageHeader, ctx.Image},
|
|
|
|
+ {types.Container{Image: "verylongimagename"}, false, "verylongimagename", imageHeader, ctx.Image},
|
|
{types.Container{Image: ""}, true, "<no image>", imageHeader, ctx.Image},
|
|
{types.Container{Image: ""}, true, "<no image>", imageHeader, ctx.Image},
|
|
{types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, commandHeader, ctx.Command},
|
|
{types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, commandHeader, ctx.Command},
|
|
{types.Container{Created: unix}, true, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt},
|
|
{types.Container{Created: unix}, true, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt},
|
|
@@ -33,7 +35,9 @@ func TestContainerPsContext(t *testing.T) {
|
|
{types.Container{Status: "RUNNING"}, true, "RUNNING", statusHeader, ctx.Status},
|
|
{types.Container{Status: "RUNNING"}, true, "RUNNING", statusHeader, ctx.Status},
|
|
{types.Container{SizeRw: 10}, true, "10 B", sizeHeader, ctx.Size},
|
|
{types.Container{SizeRw: 10}, true, "10 B", sizeHeader, ctx.Size},
|
|
{types.Container{SizeRw: 10, SizeRootFs: 20}, true, "10 B (virtual 20 B)", sizeHeader, ctx.Size},
|
|
{types.Container{SizeRw: 10, SizeRootFs: 20}, true, "10 B (virtual 20 B)", sizeHeader, ctx.Size},
|
|
|
|
+ {types.Container{}, true, "", labelsHeader, ctx.Labels},
|
|
{types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, true, "cpu=6,storage=ssd", labelsHeader, ctx.Labels},
|
|
{types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, true, "cpu=6,storage=ssd", labelsHeader, ctx.Labels},
|
|
|
|
+ {types.Container{Created: unix}, true, "Less than a second", runningForHeader, ctx.RunningFor},
|
|
}
|
|
}
|
|
|
|
|
|
for _, c := range cases {
|
|
for _, c := range cases {
|
|
@@ -68,8 +72,8 @@ func TestContainerPsContext(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- c := types.Container{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}}
|
|
|
|
- ctx = containerContext{c: c, trunc: true}
|
|
|
|
|
|
+ c1 := types.Container{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}}
|
|
|
|
+ ctx = containerContext{c: c1, trunc: true}
|
|
|
|
|
|
sid := ctx.Label("com.docker.swarm.swarm-id")
|
|
sid := ctx.Label("com.docker.swarm.swarm-id")
|
|
node := ctx.Label("com.docker.swarm.node_name")
|
|
node := ctx.Label("com.docker.swarm.node_name")
|
|
@@ -86,17 +90,19 @@ func TestContainerPsContext(t *testing.T) {
|
|
t.Fatalf("Expected %s, was %s\n", "SWARM ID\tNODE NAME", h)
|
|
t.Fatalf("Expected %s, was %s\n", "SWARM ID\tNODE NAME", h)
|
|
|
|
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
|
|
-func TestContainerPsFormatError(t *testing.T) {
|
|
|
|
- out := bytes.NewBufferString("")
|
|
|
|
- ctx := Context{
|
|
|
|
- Format: "{{InvalidFunction}}",
|
|
|
|
- Output: out,
|
|
|
|
|
|
+ c2 := types.Container{}
|
|
|
|
+ ctx = containerContext{c: c2, trunc: true}
|
|
|
|
+
|
|
|
|
+ label := ctx.Label("anything.really")
|
|
|
|
+ if label != "" {
|
|
|
|
+ t.Fatalf("Expected an empty string, was %s", label)
|
|
}
|
|
}
|
|
|
|
|
|
- customFormat(ctx, make([]types.Container, 0))
|
|
|
|
- if out.String() != "Template parsing error: template: :1: function \"InvalidFunction\" not defined\n" {
|
|
|
|
- t.Fatalf("Expected format error, got `%v`\n", out.String())
|
|
|
|
|
|
+ ctx = containerContext{c: c2, trunc: true}
|
|
|
|
+ fullHeader := ctx.fullHeader()
|
|
|
|
+ if fullHeader != "" {
|
|
|
|
+ t.Fatalf("Expected fullHeader to be empty, was %s", fullHeader)
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|