Test for links names in ps --no-trunc

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-01-15 11:03:46 -08:00
parent 10c3d9f80f
commit 2a3225eb82
1 changed files with 27 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os/exec"
"reflect"
"strconv"
"strings"
"testing"
@ -539,3 +540,29 @@ func TestPsRightTagName(t *testing.T) {
}
logDone("ps - right tags for containers")
}
func TestPsLinkedWithNoTrunc(t *testing.T) {
defer deleteAllContainers()
if out, err := exec.Command(dockerBinary, "run", "--name=first", "-d", "busybox", "top").CombinedOutput(); err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
if err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// strip header
lines = lines[1:]
expected := []string{"second", "first,second/first"}
var names []string
for _, l := range lines {
fields := strings.Fields(l)
names = append(names, fields[len(fields)-1])
}
if !reflect.DeepEqual(expected, names) {
t.Fatalf("Expected array: %v, got: %v", expected, names)
}
}