mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12838 from fntlnz/test-cmd
Using dockerCmd when possible
This commit is contained in:
commit
6c42b3947a
3 changed files with 57 additions and 246 deletions
|
@ -76,13 +76,11 @@ func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {
|
||||||
|
|
||||||
out, _ := dockerCmd(c, "images", "-q")
|
out, _ := dockerCmd(c, "images", "-q")
|
||||||
image := strings.Split(out, "\n")[0]
|
image := strings.Split(out, "\n")[0]
|
||||||
eventsCmd := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg")
|
if err := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg").Run(); err == nil {
|
||||||
_, _, err := runCommandWithOutput(eventsCmd)
|
|
||||||
if err == nil {
|
|
||||||
c.Fatalf("Container run with command blerg should have failed, but it did not")
|
c.Fatalf("Container run with command blerg should have failed, but it did not")
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsCmd = exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
||||||
out, _, _ = runCommandWithOutput(eventsCmd)
|
out, _, _ = runCommandWithOutput(eventsCmd)
|
||||||
events := strings.Split(out, "\n")
|
events := strings.Split(out, "\n")
|
||||||
if len(events) <= 1 {
|
if len(events) <= 1 {
|
||||||
|
|
|
@ -13,33 +13,17 @@ import (
|
||||||
|
|
||||||
func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstID := strings.TrimSpace(out)
|
firstID := strings.TrimSpace(out)
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
secondID := strings.TrimSpace(out)
|
secondID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// not long running
|
// not long running
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
thirdID := strings.TrimSpace(out)
|
thirdID := strings.TrimSpace(out)
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
fourthID := strings.TrimSpace(out)
|
fourthID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// make sure the second is running
|
// make sure the second is running
|
||||||
|
@ -48,10 +32,7 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure third one is not running
|
// make sure third one is not running
|
||||||
runCmd = exec.Command(dockerBinary, "wait", thirdID)
|
dockerCmd(c, "wait", thirdID)
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure the forth is running
|
// make sure the forth is running
|
||||||
if err := waitRun(fourthID); err != nil {
|
if err := waitRun(fourthID); err != nil {
|
||||||
|
@ -59,23 +40,13 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// all
|
// all
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a")
|
out, _ = dockerCmd(c, "ps", "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
|
if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// running
|
// running
|
||||||
runCmd = exec.Command(dockerBinary, "ps")
|
out, _ = dockerCmd(c, "ps")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
|
if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
@ -83,154 +54,85 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
||||||
// from here all flag '-a' is ignored
|
// from here all flag '-a' is ignored
|
||||||
|
|
||||||
// limit
|
// limit
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-n=2", "-a")
|
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected := []string{fourthID, thirdID}
|
expected := []string{fourthID, thirdID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-n=2")
|
out, _ = dockerCmd(c, "ps", "-n=2")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// since
|
// since
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-a")
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{fourthID, thirdID, secondID}
|
expected = []string{fourthID, thirdID, secondID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID)
|
out, _ = dockerCmd(c, "ps", "--since", firstID)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// before
|
// before
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID, "-a")
|
out, _ = dockerCmd(c, "ps", "--before", thirdID, "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{secondID, firstID}
|
expected = []string{secondID, firstID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID)
|
out, _ = dockerCmd(c, "ps", "--before", thirdID)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// since & before
|
// since & before
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-a")
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{thirdID, secondID}
|
expected = []string{thirdID, secondID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID)
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// since & limit
|
// since & limit
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2", "-a")
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2", "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{fourthID, thirdID}
|
expected = []string{fourthID, thirdID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2")
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// before & limit
|
// before & limit
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1", "-a")
|
out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1", "-a")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{thirdID}
|
expected = []string{thirdID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1")
|
out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// since & before & limit
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
|
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
expected = []string{thirdID}
|
expected = []string{thirdID}
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1")
|
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !assertContainerList(out, expected) {
|
if !assertContainerList(out, expected) {
|
||||||
c.Errorf("Container list is not in the correct order: %s", out)
|
c.Errorf("Container list is not in the correct order: %s", out)
|
||||||
}
|
}
|
||||||
|
@ -255,10 +157,9 @@ func assertContainerList(out string, expected []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
||||||
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
|
dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
|
||||||
runCommandWithOutput(cmd)
|
|
||||||
cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
baseOut, _ := dockerCmd(c, "ps", "-s", "-n=1")
|
||||||
baseOut, _, err := runCommandWithOutput(cmd)
|
|
||||||
baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n")
|
baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n")
|
||||||
baseSizeIndex := strings.Index(baseLines[0], "SIZE")
|
baseSizeIndex := strings.Index(baseLines[0], "SIZE")
|
||||||
baseFoundsize := baseLines[1][baseSizeIndex:]
|
baseFoundsize := baseLines[1][baseSizeIndex:]
|
||||||
|
@ -268,17 +169,14 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
name := "test_size"
|
name := "test_size"
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
|
out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
id, err := getIDByName(name)
|
id, err := getIDByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
||||||
|
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
@ -315,43 +213,24 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
||||||
// this is because paused containers can't be controlled by signals
|
// this is because paused containers can't be controlled by signals
|
||||||
|
|
||||||
// start exited container
|
// start exited container
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
out, _ := dockerCmd(c, "run", "-d", "busybox")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstID := strings.TrimSpace(out)
|
firstID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// make sure the exited cintainer is not running
|
// make sure the exited cintainer is not running
|
||||||
runCmd = exec.Command(dockerBinary, "wait", firstID)
|
dockerCmd(c, "wait", firstID)
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// start running container
|
// start running container
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-itd", "busybox")
|
out, _ = dockerCmd(c, "run", "-itd", "busybox")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
secondID := strings.TrimSpace(out)
|
secondID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// filter containers by exited
|
// filter containers by exited
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-q", "--filter=status=exited")
|
out, _ = dockerCmd(c, "ps", "-q", "--filter=status=exited")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut := strings.TrimSpace(out)
|
containerOut := strings.TrimSpace(out)
|
||||||
if containerOut != firstID[:12] {
|
if containerOut != firstID[:12] {
|
||||||
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=running")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=status=running")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut = strings.TrimSpace(out)
|
containerOut = strings.TrimSpace(out)
|
||||||
if containerOut != secondID[:12] {
|
if containerOut != secondID[:12] {
|
||||||
c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
|
c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
|
||||||
|
@ -362,24 +241,14 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
||||||
func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
||||||
|
|
||||||
// start container
|
// start container
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
out, _ := dockerCmd(c, "run", "-d", "busybox")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstID := strings.TrimSpace(out)
|
firstID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// start another container
|
// start another container
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter containers by id
|
// filter containers by id
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=id="+firstID)
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut := strings.TrimSpace(out)
|
containerOut := strings.TrimSpace(out)
|
||||||
if containerOut != firstID[:12] {
|
if containerOut != firstID[:12] {
|
||||||
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
||||||
|
@ -390,24 +259,14 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
||||||
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
||||||
|
|
||||||
// start container
|
// start container
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name=a_name_to_match", "busybox")
|
out, _ := dockerCmd(c, "run", "-d", "--name=a_name_to_match", "busybox")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstID := strings.TrimSpace(out)
|
firstID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// start another container
|
// start another container
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name=b_name_to_match", "busybox", "top")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter containers by name
|
// filter containers by name
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=name=a_name_to_match")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut := strings.TrimSpace(out)
|
containerOut := strings.TrimSpace(out)
|
||||||
if containerOut != firstID[:12] {
|
if containerOut != firstID[:12] {
|
||||||
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
||||||
|
@ -417,62 +276,40 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
||||||
// start container
|
// start container
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
|
out, _ := dockerCmd(c, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstID := strings.TrimSpace(out)
|
firstID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// start another container
|
// start another container
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "match=me too", "busybox")
|
out, _ = dockerCmd(c, "run", "-d", "-l", "match=me too", "busybox")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
secondID := strings.TrimSpace(out)
|
secondID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// start third container
|
// start third container
|
||||||
runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "nomatch=me", "busybox")
|
out, _ = dockerCmd(c, "run", "-d", "-l", "nomatch=me", "busybox")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
thirdID := strings.TrimSpace(out)
|
thirdID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// filter containers by exact match
|
// filter containers by exact match
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut := strings.TrimSpace(out)
|
containerOut := strings.TrimSpace(out)
|
||||||
if containerOut != firstID {
|
if containerOut != firstID {
|
||||||
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter containers by two labels
|
// filter containers by two labels
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut = strings.TrimSpace(out)
|
containerOut = strings.TrimSpace(out)
|
||||||
if containerOut != firstID {
|
if containerOut != firstID {
|
||||||
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter containers by two labels, but expect not found because of AND behavior
|
// filter containers by two labels, but expect not found because of AND behavior
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut = strings.TrimSpace(out)
|
containerOut = strings.TrimSpace(out)
|
||||||
if containerOut != "" {
|
if containerOut != "" {
|
||||||
c.Fatalf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)
|
c.Fatalf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter containers by exact key
|
// filter containers by exact key
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
|
||||||
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
containerOut = strings.TrimSpace(out)
|
containerOut = strings.TrimSpace(out)
|
||||||
if (!strings.Contains(containerOut, firstID) || !strings.Contains(containerOut, secondID)) || strings.Contains(containerOut, thirdID) {
|
if (!strings.Contains(containerOut, firstID) || !strings.Contains(containerOut, secondID)) || strings.Contains(containerOut, thirdID) {
|
||||||
c.Fatalf("Expected ids %s,%s, got %s for exited filter, output: %q", firstID, secondID, containerOut, out)
|
c.Fatalf("Expected ids %s,%s, got %s for exited filter, output: %q", firstID, secondID, containerOut, out)
|
||||||
|
@ -481,33 +318,25 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
|
dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
firstZero, err := getIDByName("zero1")
|
firstZero, err := getIDByName("zero1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
|
dockerCmd(c, "run", "--name", "zero2", "busybox", "true")
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
secondZero, err := getIDByName("zero2")
|
secondZero, err := getIDByName("zero2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
|
runCmd := exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err == nil {
|
if out, _, err := runCommandWithOutput(runCmd); err == nil {
|
||||||
c.Fatal("Should fail.", out, err)
|
c.Fatal("Should fail.", out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
firstNonZero, err := getIDByName("nonzero1")
|
firstNonZero, err := getIDByName("nonzero1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
|
@ -523,11 +352,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter containers by exited=0
|
// filter containers by exited=0
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
ids := strings.Split(strings.TrimSpace(out), "\n")
|
ids := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
if len(ids) != 2 {
|
if len(ids) != 2 {
|
||||||
c.Fatalf("Should be 2 zero exited containers got %d: %s", len(ids), out)
|
c.Fatalf("Should be 2 zero exited containers got %d: %s", len(ids), out)
|
||||||
|
@ -539,11 +364,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
||||||
c.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
|
c.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
ids = strings.Split(strings.TrimSpace(out), "\n")
|
ids = strings.Split(strings.TrimSpace(out), "\n")
|
||||||
if len(ids) != 2 {
|
if len(ids) != 2 {
|
||||||
c.Fatalf("Should be 2 zero exited containers got %d", len(ids))
|
c.Fatalf("Should be 2 zero exited containers got %d", len(ids))
|
||||||
|
@ -650,15 +471,9 @@ func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
||||||
func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
||||||
|
|
||||||
portRange := "3800-3900"
|
portRange := "3800-3900"
|
||||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top"))
|
dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps"))
|
out, _ := dockerCmd(c, "ps")
|
||||||
if err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that the port range is in the output
|
// check that the port range is in the output
|
||||||
if !strings.Contains(string(out), portRange) {
|
if !strings.Contains(string(out), portRange) {
|
||||||
|
|
|
@ -552,9 +552,7 @@ func pullImageIfNotExist(image string) (err error) {
|
||||||
|
|
||||||
func dockerCmd(c *check.C, args ...string) (string, int) {
|
func dockerCmd(c *check.C, args ...string) (string, int) {
|
||||||
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
|
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), out, err))
|
||||||
c.Fatalf("%q failed with errors: %s, %v", strings.Join(args, " "), out, err)
|
|
||||||
}
|
|
||||||
return out, status
|
return out, status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue