|
@@ -282,3 +282,50 @@ func TestPsListContainersFilterStatus(t *testing.T) {
|
|
|
|
|
|
logDone("ps - test ps filter status")
|
|
logDone("ps - test ps filter status")
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestPsListContainersNames(t *testing.T) {
|
|
|
|
+ runCmd := exec.Command(dockerBinary, "run", "--name", "link_target", "-d", "busybox", "top")
|
|
|
|
+ out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
+ errorOut(err, t, out)
|
|
|
|
+
|
|
|
|
+ runCmd = exec.Command(dockerBinary, "run", "--name", "link_source", "--link", "link_target:link_alias", "-d", "busybox", "top")
|
|
|
|
+ out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
+ errorOut(err, t, out)
|
|
|
|
+
|
|
|
|
+ // non-truncated ps should return all names
|
|
|
|
+ runCmd = exec.Command(dockerBinary, "ps", "--no-trunc")
|
|
|
|
+ out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
+ errorOut(err, t, out)
|
|
|
|
+ lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
|
|
|
+ namesIndex := strings.Index(lines[0], "NAMES")
|
|
|
|
+ expectedNames := "link_source"
|
|
|
|
+ foundNames := strings.TrimSpace(lines[1][namesIndex:])
|
|
|
|
+ if foundNames != expectedNames {
|
|
|
|
+ t.Fatalf("Expected names %q, got %q", expectedNames, foundNames)
|
|
|
|
+ }
|
|
|
|
+ expectedNames = "link_source/link_alias,link_target"
|
|
|
|
+ foundNames = strings.TrimSpace(lines[2][namesIndex:])
|
|
|
|
+ if foundNames != expectedNames {
|
|
|
|
+ t.Fatalf("Expected names %q, got %q", expectedNames, foundNames)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // truncated ps should return canonical names only
|
|
|
|
+ runCmd = exec.Command(dockerBinary, "ps")
|
|
|
|
+ out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
+ errorOut(err, t, out)
|
|
|
|
+ lines = strings.Split(strings.Trim(out, "\n "), "\n")
|
|
|
|
+ namesIndex = strings.Index(lines[0], "NAMES")
|
|
|
|
+ expectedNames = "link_source"
|
|
|
|
+ foundNames = strings.TrimSpace(lines[1][namesIndex:])
|
|
|
|
+ if foundNames != expectedNames {
|
|
|
|
+ t.Fatalf("Expected names %q, got %q", expectedNames, foundNames)
|
|
|
|
+ }
|
|
|
|
+ expectedNames = "link_target"
|
|
|
|
+ foundNames = strings.TrimSpace(lines[2][namesIndex:])
|
|
|
|
+ if foundNames != expectedNames {
|
|
|
|
+ t.Fatalf("Expected names %q, got %q", expectedNames, foundNames)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deleteAllContainers()
|
|
|
|
+ logDone("ps - test ps names")
|
|
|
|
+}
|