|
@@ -47,8 +47,6 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|
|
out, _ = dockerCmd(c, "ps")
|
|
|
c.Assert(assertContainerList(out, []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
- // from here all flag '-a' is ignored
|
|
|
-
|
|
|
// limit
|
|
|
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
|
|
|
expected := []string{fourthID, thirdID}
|
|
@@ -60,56 +58,138 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|
|
// filter since
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a")
|
|
|
expected = []string{fourthID, thirdID, secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID)
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE: Container list is not in the correct order: \n%s", out))
|
|
|
+ expected = []string{fourthID, secondID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter before
|
|
|
- out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID, "-a")
|
|
|
- expected = []string{secondID, firstID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a")
|
|
|
+ expected = []string{thirdID, secondID, firstID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
- out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE: Container list is not in the correct order: \n%s", out))
|
|
|
+ out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID)
|
|
|
+ expected = []string{secondID, firstID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & before
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a")
|
|
|
expected = []string{thirdID, secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID)
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE: Container list is not in the correct order: \n%s", out))
|
|
|
+ expected = []string{secondID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a")
|
|
|
expected = []string{fourthID, thirdID}
|
|
|
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter before & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a")
|
|
|
expected = []string{thirdID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & filter before & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a")
|
|
|
expected = []string{thirdID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// FIXME remove this for 1.12 as --since and --before are deprecated
|
|
|
+func (s *DockerSuite) TestPsListContainersDeprecatedSinceAndBefore(c *check.C) {
|
|
|
+ out, _ := runSleepingContainer(c, "-d")
|
|
|
+ firstID := strings.TrimSpace(out)
|
|
|
+
|
|
|
+ out, _ = runSleepingContainer(c, "-d")
|
|
|
+ secondID := strings.TrimSpace(out)
|
|
|
+
|
|
|
+ // not long running
|
|
|
+ out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
+ thirdID := strings.TrimSpace(out)
|
|
|
+
|
|
|
+ out, _ = runSleepingContainer(c, "-d")
|
|
|
+ fourthID := strings.TrimSpace(out)
|
|
|
+
|
|
|
+ // make sure the second is running
|
|
|
+ c.Assert(waitRun(secondID), checker.IsNil)
|
|
|
+
|
|
|
+ // make sure third one is not running
|
|
|
+ dockerCmd(c, "wait", thirdID)
|
|
|
+
|
|
|
+ // make sure the forth is running
|
|
|
+ c.Assert(waitRun(fourthID), checker.IsNil)
|
|
|
+
|
|
|
+ // since
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "-a")
|
|
|
+ expected := []string{fourthID, thirdID, secondID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID)
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ // before
|
|
|
+ out, _ = dockerCmd(c, "ps", "--before="+thirdID, "-a")
|
|
|
+ expected = []string{secondID, firstID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "ps", "--before="+thirdID)
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ // since & before
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-a")
|
|
|
+ expected = []string{thirdID, secondID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID)
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ // since & limit
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2", "-a")
|
|
|
+ expected = []string{fourthID, thirdID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2")
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ // before & limit
|
|
|
+ out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1", "-a")
|
|
|
+ expected = []string{thirdID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1")
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
+
|
|
|
+ // since & before & limit
|
|
|
+ out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-n=1", "-a")
|
|
|
+ expected = []string{thirdID}
|
|
|
+ c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
|
|
|
|
|
}
|
|
|
|
|
|
func assertContainerList(out string, expected []string) bool {
|
|
|
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
|
|
+ // FIXME remove this for 1.12 as --since and --before are deprecated
|
|
|
+ // This is here to remove potential Warning: lines (printed out with deprecated flags)
|
|
|
+ for i := 0; i < 2; i++ {
|
|
|
+ if strings.Contains(lines[0], "Warning:") {
|
|
|
+ lines = lines[1:]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if len(lines)-1 != len(expected) {
|
|
|
return false
|
|
|
}
|