2014-07-17 12:29:52 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-01-23 15:17:05 +03:00
|
|
|
"fmt"
|
2014-07-17 12:29:52 +04:00
|
|
|
"os/exec"
|
2015-01-15 22:03:46 +03:00
|
|
|
"reflect"
|
2015-01-23 15:17:05 +03:00
|
|
|
"strconv"
|
2014-07-17 12:29:52 +04:00
|
|
|
"strings"
|
2014-09-12 11:45:50 +04:00
|
|
|
"time"
|
2015-04-18 19:46:47 +03:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-07-17 12:29:52 +04:00
|
|
|
)
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainers(c *check.C) {
|
2015-02-20 09:56:02 +03:00
|
|
|
|
2014-07-17 12:29:52 +04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
firstID := strings.TrimSpace(out)
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
secondID := strings.TrimSpace(out)
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
// not long running
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
thirdID := strings.TrimSpace(out)
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
fourthID := strings.TrimSpace(out)
|
2014-07-17 12:29:52 +04:00
|
|
|
|
2015-04-09 02:20:42 +03:00
|
|
|
// make sure the second is running
|
|
|
|
if err := waitRun(secondID); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("waiting for container failed: %v", err)
|
2015-04-09 02:20:42 +03:00
|
|
|
}
|
|
|
|
|
2014-07-17 12:29:52 +04:00
|
|
|
// make sure third one is not running
|
|
|
|
runCmd = exec.Command(dockerBinary, "wait", thirdID)
|
2014-10-15 00:04:37 +04:00
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
2015-04-09 02:20:42 +03:00
|
|
|
// make sure the forth is running
|
|
|
|
if err := waitRun(fourthID); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("waiting for container failed: %v", err)
|
2015-04-09 02:20:42 +03:00
|
|
|
}
|
|
|
|
|
2014-07-17 12:29:52 +04:00
|
|
|
// all
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// running
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// from here all flag '-a' is ignored
|
|
|
|
|
|
|
|
// limit
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-n=2", "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected := []string{fourthID, thirdID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-n=2")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// since
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{fourthID, thirdID, secondID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID)
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// before
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID, "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{secondID, firstID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID)
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// since & before
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{thirdID, secondID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID)
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// since & limit
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2", "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{fourthID, thirdID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// before & limit
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1", "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{thirdID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// since & before & limit
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
expected = []string{thirdID}
|
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-07-17 12:29:52 +04:00
|
|
|
|
|
|
|
if !assertContainerList(out, expected) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("Container list is not in the correct order: %s", out)
|
2014-07-17 12:29:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertContainerList(out string, expected []string) bool {
|
|
|
|
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
|
|
|
if len(lines)-1 != len(expected) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:26:55 +04:00
|
|
|
containerIDIndex := strings.Index(lines[0], "CONTAINER ID")
|
2014-07-17 12:29:52 +04:00
|
|
|
for i := 0; i < len(expected); i++ {
|
2014-10-06 18:26:55 +04:00
|
|
|
foundID := lines[i+1][containerIDIndex : containerIDIndex+12]
|
2014-07-17 12:29:52 +04:00
|
|
|
if foundID != expected[i][:12] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2014-09-12 11:45:50 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
2015-01-23 15:17:05 +03:00
|
|
|
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
|
|
|
|
runCommandWithOutput(cmd)
|
|
|
|
cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
2015-03-26 04:40:23 +03:00
|
|
|
baseOut, _, err := runCommandWithOutput(cmd)
|
|
|
|
baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n")
|
|
|
|
baseSizeIndex := strings.Index(baseLines[0], "SIZE")
|
|
|
|
baseFoundsize := baseLines[1][baseSizeIndex:]
|
|
|
|
baseBytes, err := strconv.Atoi(strings.Split(baseFoundsize, " ")[0])
|
2015-01-23 15:17:05 +03:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2015-01-23 15:17:05 +03:00
|
|
|
}
|
|
|
|
|
2014-09-12 11:45:50 +04:00
|
|
|
name := "test_size"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-09-12 11:45:50 +04:00
|
|
|
id, err := getIDByName(name)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-09-12 11:45:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
|
|
|
wait := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
close(wait)
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-wait:
|
|
|
|
case <-time.After(3 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Calling \"docker ps -s\" timed out!")
|
2014-09-12 11:45:50 +04:00
|
|
|
}
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-09-12 11:45:50 +04:00
|
|
|
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
2015-04-03 00:44:53 +03:00
|
|
|
if len(lines) != 2 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines))
|
2015-04-03 00:44:53 +03:00
|
|
|
}
|
2014-09-12 11:45:50 +04:00
|
|
|
sizeIndex := strings.Index(lines[0], "SIZE")
|
|
|
|
idIndex := strings.Index(lines[0], "CONTAINER ID")
|
|
|
|
foundID := lines[1][idIndex : idIndex+12]
|
|
|
|
if foundID != id[:12] {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s", id[:12], foundID)
|
2014-09-12 11:45:50 +04:00
|
|
|
}
|
2015-03-26 04:40:23 +03:00
|
|
|
expectedSize := fmt.Sprintf("%d B", (2 + baseBytes))
|
2014-09-12 11:45:50 +04:00
|
|
|
foundSize := lines[1][sizeIndex:]
|
|
|
|
if foundSize != expectedSize {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
|
2014-09-12 11:45:50 +04:00
|
|
|
}
|
2014-09-27 03:25:50 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
2014-09-27 03:25:50 +04:00
|
|
|
// FIXME: this should test paused, but it makes things hang and its wonky
|
|
|
|
// this is because paused containers can't be controlled by signals
|
2015-02-20 09:56:02 +03:00
|
|
|
|
2014-09-27 03:25:50 +04:00
|
|
|
// start exited container
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
firstID := strings.TrimSpace(out)
|
2014-09-27 03:25:50 +04:00
|
|
|
|
|
|
|
// make sure the exited cintainer is not running
|
|
|
|
runCmd = exec.Command(dockerBinary, "wait", firstID)
|
2014-10-15 00:04:37 +04:00
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-09-27 03:25:50 +04:00
|
|
|
|
|
|
|
// start running container
|
2015-01-20 03:32:29 +03:00
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-itd", "busybox")
|
2014-09-27 03:25:50 +04:00
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
secondID := strings.TrimSpace(out)
|
2014-09-27 03:25:50 +04:00
|
|
|
|
|
|
|
// filter containers by exited
|
2015-01-09 02:14:04 +03:00
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-q", "--filter=status=exited")
|
2014-09-27 03:25:50 +04:00
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-09-27 03:25:50 +04:00
|
|
|
containerOut := strings.TrimSpace(out)
|
|
|
|
if containerOut != firstID[:12] {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
2014-09-27 03:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=running")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
2014-10-15 00:04:37 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-15 00:04:37 +04:00
|
|
|
}
|
2014-09-27 03:25:50 +04:00
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
|
if containerOut != secondID[:12] {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
|
2014-09-27 03:25:50 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 11:45:50 +04:00
|
|
|
}
|
2014-10-13 10:12:44 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
2015-02-20 09:56:02 +03:00
|
|
|
|
2014-10-13 10:12:44 +04:00
|
|
|
// start container
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
firstID := strings.TrimSpace(out)
|
2014-10-13 10:12:44 +04:00
|
|
|
|
|
|
|
// start another container
|
2015-04-09 02:32:45 +03:00
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
2014-10-13 10:12:44 +04:00
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// filter containers by id
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=id="+firstID)
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
containerOut := strings.TrimSpace(out)
|
|
|
|
if containerOut != firstID[:12] {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
2015-02-20 09:56:02 +03:00
|
|
|
|
2014-10-13 10:12:44 +04:00
|
|
|
// start container
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "--name=a_name_to_match", "busybox")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
firstID := strings.TrimSpace(out)
|
2014-10-13 10:12:44 +04:00
|
|
|
|
|
|
|
// start another container
|
2015-04-09 02:32:45 +03:00
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "top")
|
2014-10-13 10:12:44 +04:00
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// filter containers by name
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=name=a_name_to_match")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
containerOut := strings.TrimSpace(out)
|
|
|
|
if containerOut != firstID[:12] {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
2014-10-13 10:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-11-03 21:50:16 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
2015-01-07 03:04:10 +03:00
|
|
|
// start container
|
2015-03-09 08:18:59 +03:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
|
2015-01-07 03:04:10 +03:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
firstID := strings.TrimSpace(out)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
|
|
|
// start another container
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "match=me too", "busybox")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
secondID := strings.TrimSpace(out)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
|
|
|
// start third container
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "nomatch=me", "busybox")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
thirdID := strings.TrimSpace(out)
|
2015-01-07 03:04:10 +03:00
|
|
|
|
|
|
|
// filter containers by exact match
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
|
|
|
containerOut := strings.TrimSpace(out)
|
|
|
|
if containerOut != firstID {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
|
|
|
|
2015-03-09 08:18:59 +03:00
|
|
|
// filter containers by two labels
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-03-09 08:18:59 +03:00
|
|
|
}
|
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
|
if containerOut != firstID {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
|
2015-03-09 08:18:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-03-09 08:18:59 +03:00
|
|
|
}
|
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
|
if containerOut != "" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)
|
2015-03-09 08:18:59 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 03:04:10 +03:00
|
|
|
// filter containers by exact key
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
|
if (!strings.Contains(containerOut, firstID) || !strings.Contains(containerOut, secondID)) || strings.Contains(containerOut, thirdID) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected ids %s,%s, got %s for exited filter, output: %q", firstID, secondID, containerOut, out)
|
2015-01-07 03:04:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
2015-01-09 01:51:47 +03:00
|
|
|
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
|
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-01-09 01:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
|
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
firstZero, err := getIDByName("zero1")
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
|
2015-01-09 01:51:47 +03:00
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
secondZero, err := getIDByName("zero2")
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
|
2015-01-09 01:51:47 +03:00
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err == nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("Should fail.", out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
firstNonZero, err := getIDByName("nonzero1")
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
|
2015-01-09 01:51:47 +03:00
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err == nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("Should fail.", out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
secondNonZero, err := getIDByName("nonzero2")
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// filter containers by exited=0
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
2015-01-09 01:51:47 +03:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-11-03 21:50:16 +03:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
ids := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
if len(ids) != 2 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Should be 2 zero exited containers got %d: %s", len(ids), out)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
if ids[0] != secondZero {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("First in list should be %q, got %q", secondZero, ids[0])
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
if ids[1] != firstZero {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
ids = strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
if len(ids) != 2 {
|
2015-04-27 23:33:30 +03:00
|
|
|
c.Fatalf("Should be 2 zero exited containers got %d", len(ids))
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
if ids[0] != secondNonZero {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("First in list should be %q, got %q", secondNonZero, ids[0])
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
|
|
|
if ids[1] != firstNonZero {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
2015-01-09 01:51:47 +03:00
|
|
|
|
2014-11-03 21:50:16 +03:00
|
|
|
}
|
2015-02-06 01:55:08 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
2015-02-06 01:55:08 +03:00
|
|
|
tag := "asybox:shmatest"
|
|
|
|
if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to tag image: %s, out: %q", err, out)
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var id1 string
|
|
|
|
if out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "top").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to run container: %s, out: %q", err, out)
|
2015-02-06 01:55:08 +03:00
|
|
|
} else {
|
|
|
|
id1 = strings.TrimSpace(string(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
var id2 string
|
|
|
|
if out, err := exec.Command(dockerBinary, "run", "-d", tag, "top").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to run container: %s, out: %q", err, out)
|
2015-02-06 01:55:08 +03:00
|
|
|
} else {
|
|
|
|
id2 = strings.TrimSpace(string(out))
|
|
|
|
}
|
2015-04-01 17:08:00 +03:00
|
|
|
|
|
|
|
var imageID string
|
|
|
|
if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
|
2015-04-01 17:08:00 +03:00
|
|
|
} else {
|
|
|
|
imageID = strings.TrimSpace(string(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
var id3 string
|
|
|
|
if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to run container: %s, out: %q", err, out)
|
2015-04-01 17:08:00 +03:00
|
|
|
} else {
|
|
|
|
id3 = strings.TrimSpace(string(out))
|
|
|
|
}
|
|
|
|
|
2015-02-06 01:55:08 +03:00
|
|
|
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
|
// skip header
|
|
|
|
lines = lines[1:]
|
2015-04-01 17:08:00 +03:00
|
|
|
if len(lines) != 3 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("There should be 3 running container, got %d", len(lines))
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
f := strings.Fields(line)
|
|
|
|
switch f[0] {
|
|
|
|
case id1:
|
2015-04-01 17:08:00 +03:00
|
|
|
if f[1] != "busybox" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected %s tag for id %s, got %s", "busybox", id1, f[1])
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
case id2:
|
|
|
|
if f[1] != tag {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected %s tag for id %s, got %s", tag, id2, f[1])
|
2015-04-01 17:08:00 +03:00
|
|
|
}
|
|
|
|
case id3:
|
|
|
|
if f[1] != imageID {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected %s imageID for id %s, got %s", tag, id3, f[1])
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
default:
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
|
2015-02-06 01:55:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 22:03:46 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
2015-01-15 22:03:46 +03:00
|
|
|
if out, err := exec.Command(dockerBinary, "run", "--name=first", "-d", "busybox", "top").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Output: %s, err: %s", out, err)
|
2015-01-15 22:03:46 +03:00
|
|
|
}
|
|
|
|
if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Output: %s, err: %s", out, err)
|
2015-01-15 22:03:46 +03:00
|
|
|
}
|
|
|
|
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Output: %s, err: %s", out, err)
|
2015-01-15 22:03:46 +03:00
|
|
|
}
|
|
|
|
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) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected array: %v, got: %v", expected, names)
|
2015-01-15 22:03:46 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 22:08:32 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
2015-02-16 22:08:32 +03:00
|
|
|
|
2015-04-02 18:26:29 +03:00
|
|
|
portRange := "3800-3900"
|
2015-02-16 22:08:32 +03:00
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top"))
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-02-16 22:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps"))
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(out, err)
|
2015-02-16 22:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// check that the port range is in the output
|
|
|
|
if !strings.Contains(string(out), portRange) {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("docker ps output should have had the port range %q: %s", portRange, string(out))
|
2015-02-16 22:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|