Browse Source

Test for links names in ps --no-trunc

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Alexander Morozov 10 năm trước cách đây
mục cha
commit
2a3225eb82

+ 27 - 0
integration-cli/docker_cli_ps_test.go

@@ -3,6 +3,7 @@ package main
 import (
 import (
 	"fmt"
 	"fmt"
 	"os/exec"
 	"os/exec"
+	"reflect"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -539,3 +540,29 @@ func TestPsRightTagName(t *testing.T) {
 	}
 	}
 	logDone("ps - right tags for containers")
 	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)
+	}
+}