Use dockerCmd when possible (#14603)

- integration-cli/docker_cli_attach_test.go
- integration-cli/docker_cli_attach_unix_test.go
- integration-cli/docker_cli_build_test.go
- integration-cli/docker_cli_build_unix_test.go
- integration-cli/docker_cli_by_digest_test.go
- integration-cli/docker_cli_commit_test.go
- integration-cli/docker_cli_config_test.go
- integration-cli/docker_cli_cp_test.go
- integration-cli/docker_cli_create_test.go
- integration-cli/docker_cli_pause_test.go
- integration-cli/docker_cli_port_test.go
- integration-cli/docker_cli_port_unix_test.go
- integration-cli/docker_cli_proxy_test.go
- integration-cli/docker_cli_ps_test.go
- integration-cli/docker_cli_pull_test.go
- integration-cli/docker_cli_push_test.go

- docker_api_attach_test.go
- docker_api_containers_test.go
- docker_api_events_test.go
- docker_api_exec_resize_test.go
- docker_api_exec_test.go
- docker_api_images_test.go
- docker_api_info_test.go

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2015-07-14 08:35:36 +02:00
parent 4290bdefab
commit 5c295460da
23 changed files with 326 additions and 1054 deletions

View File

@ -5,7 +5,6 @@ import (
"io" "io"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"os/exec"
"strings" "strings"
"time" "time"
@ -14,11 +13,7 @@ import (
) )
func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) { func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "cat") out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
rwc, err := sockConn(time.Duration(10 * time.Second)) rwc, err := sockConn(time.Duration(10 * time.Second))
if err != nil { if err != nil {
@ -102,9 +97,7 @@ func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) {
} }
func (s *DockerSuite) TestPostContainersAttach(c *check.C) { func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "cat") out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
r, w := io.Pipe() r, w := io.Pipe()
defer r.Close() defer r.Close()
@ -167,9 +160,7 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
} }
func (s *DockerSuite) TestPostContainersAttachStderr(c *check.C) { func (s *DockerSuite) TestPostContainersAttachStderr(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2") out, _ := dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
r, w := io.Pipe() r, w := io.Pipe()
defer r.Close() defer r.Close()

View File

@ -8,7 +8,6 @@ import (
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"os" "os"
"os/exec"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -26,11 +25,7 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
} }
name := "getall" name := "getall"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, body, err := sockRequest("GET", "/containers/json?all=1", nil) status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -54,9 +49,7 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
// regression test for empty json field being omitted #13691 // regression test for empty json field being omitted #13691
func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) { func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "busybox", "true") dockerCmd(c, "run", "busybox", "true")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
status, body, err := sockRequest("GET", "/containers/json?all=1", nil) status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -94,9 +87,7 @@ type containerPs struct {
func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) { func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
name := "pstest" name := "pstest"
port := 80 port := 80
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top") dockerCmd(c, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
status, body, err := sockRequest("GET", "/containers/json?all=1", nil) status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -126,11 +117,7 @@ func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
func (s *DockerSuite) TestContainerApiGetExport(c *check.C) { func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
name := "exportcontainer" name := "exportcontainer"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil) status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -158,11 +145,7 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) { func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
name := "changescontainer" name := "changescontainer"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd") dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil) status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -248,9 +231,7 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
volName := "voltst" volName := "voltst"
volPath := "/tmp" volPath := "/tmp"
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", volName, "-v", volPath, "busybox")); err != nil { dockerCmd(c, "run", "-d", "--name", volName, "-v", volPath, "busybox")
c.Fatal(out, err)
}
name := "TestContainerApiStartDupVolumeBinds" name := "TestContainerApiStartDupVolumeBinds"
config := map[string]interface{}{ config := map[string]interface{}{
@ -285,13 +266,10 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
func (s *DockerSuite) TestGetContainerStats(c *check.C) { func (s *DockerSuite) TestGetContainerStats(c *check.C) {
var ( var (
name = "statscontainer" name = "statscontainer"
runCmd = exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
) )
out, _, err := runCommandWithOutput(runCmd) dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
type b struct { type b struct {
status int status int
body []byte body []byte
@ -305,9 +283,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil { dockerCmd(c, "rm", "-f", name)
c.Fatal(err)
}
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -353,7 +329,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
// Now remove without `-f` and make sure we are still pulling stats // Now remove without `-f` and make sure we are still pulling stats
_, err = runCommand(exec.Command(dockerBinary, "rm", id)) _, _, err = dockerCmdWithError(c, "rm", id)
c.Assert(err, check.Not(check.IsNil), check.Commentf("rm should have failed but didn't")) c.Assert(err, check.Not(check.IsNil), check.Commentf("rm should have failed but didn't"))
_, err = buf.ReadTimeout(b, 2*time.Second) _, err = buf.ReadTimeout(b, 2*time.Second)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -368,9 +344,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
// stream false always return one stat) // stream false always return one stat)
func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) { func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
name := "statscontainer" name := "statscontainer"
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top") dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
type b struct { type b struct {
status int status int
@ -385,9 +359,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil { dockerCmd(c, "rm", "-f", name)
c.Fatal(err)
}
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -408,9 +380,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) { func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
name := "statscontainer" name := "statscontainer"
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top") dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
type b struct { type b struct {
status int status int
@ -425,9 +395,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil { dockerCmd(c, "rm", "-f", name)
c.Fatal(err)
}
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -449,13 +417,9 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) { func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
// TODO: this test does nothing because we are c.Assert'ing in goroutine // TODO: this test does nothing because we are c.Assert'ing in goroutine
var ( var (
name = "statscontainer" name = "statscontainer"
runCmd = exec.Command(dockerBinary, "create", "--name", name, "busybox", "top")
) )
out, _, err := runCommandWithOutput(runCmd) dockerCmd(c, "create", "--name", name, "busybox", "top")
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
go func() { go func() {
// We'll never get return for GET stats from sockRequest as of now, // We'll never get return for GET stats from sockRequest as of now,
@ -739,20 +703,14 @@ func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
// #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume // #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume
func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) { func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=one", "busybox")) dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
if err != nil {
c.Fatal(err, out)
}
fooDir, err := inspectFieldMap("one", "Volumes", "/foo") fooDir, err := inspectFieldMap("one", "Volumes", "/foo")
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
} }
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=two", "busybox")) dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
if err != nil {
c.Fatal(err, out)
}
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}} bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
status, _, err := sockRequest("POST", "/containers/two/start", bindSpec) status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
@ -771,12 +729,7 @@ func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
func (s *DockerSuite) TestContainerApiPause(c *check.C) { func (s *DockerSuite) TestContainerApiPause(c *check.C) {
defer unpauseAllContainers() defer unpauseAllContainers()
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "30") out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("failed to create a container: %s, %v", out, err)
}
ContainerID := strings.TrimSpace(out) ContainerID := strings.TrimSpace(out)
status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil) status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
@ -809,10 +762,7 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiTop(c *check.C) { func (s *DockerSuite) TestContainerApiTop(c *check.C) {
out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "top").CombinedOutput() out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top")
if err != nil {
c.Fatal(err, out)
}
id := strings.TrimSpace(string(out)) id := strings.TrimSpace(string(out))
if err := waitRun(id); err != nil { if err := waitRun(id); err != nil {
c.Fatal(err) c.Fatal(err)
@ -851,10 +801,7 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
func (s *DockerSuite) TestContainerApiCommit(c *check.C) { func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
cName := "testapicommit" cName := "testapicommit"
out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput() dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
if err != nil {
c.Fatal(err, out)
}
name := "TestContainerApiCommit" name := "TestContainerApiCommit"
status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil) status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
@ -877,18 +824,12 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
c.Fatalf("got wrong Cmd from commit: %q", cmd) c.Fatalf("got wrong Cmd from commit: %q", cmd)
} }
// sanity check, make sure the image is what we think it is // sanity check, make sure the image is what we think it is
out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput() dockerCmd(c, "run", img.Id, "ls", "/test")
if err != nil {
c.Fatalf("error checking committed image: %v - %q", err, string(out))
}
} }
func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) { func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
cName := "testapicommitwithconfig" cName := "testapicommitwithconfig"
out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput() dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
if err != nil {
c.Fatal(err, out)
}
config := map[string]interface{}{ config := map[string]interface{}{
"Labels": map[string]string{"key1": "value1", "key2": "value2"}, "Labels": map[string]string{"key1": "value1", "key2": "value2"},
@ -928,10 +869,7 @@ func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
} }
// sanity check, make sure the image is what we think it is // sanity check, make sure the image is what we think it is
out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput() dockerCmd(c, "run", img.Id, "ls", "/test")
if err != nil {
c.Fatalf("error checking committed image: %v - %q", err, string(out))
}
} }
func (s *DockerSuite) TestContainerApiCreate(c *check.C) { func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
@ -952,11 +890,8 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
out, err := exec.Command(dockerBinary, "start", "-a", container.Id).CombinedOutput() out, _ := dockerCmd(c, "start", "-a", container.Id)
if err != nil { if strings.TrimSpace(out) != "/test" {
c.Fatal(string(out), err)
}
if strings.TrimSpace(string(out)) != "/test" {
c.Fatalf("expected output `/test`, got %q", out) c.Fatalf("expected output `/test`, got %q", out)
} }
} }
@ -1241,10 +1176,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
} }
func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) { func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "busybox")) out, _ := dockerCmd(c, "create", "busybox")
if err != nil {
c.Fatal(err, out)
}
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
@ -1265,9 +1197,7 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiRename(c *check.C) { func (s *DockerSuite) TestContainerApiRename(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh") out, _ := dockerCmd(c, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
newName := "TestContainerApiRenameNew" newName := "TestContainerApiRenameNew"
@ -1284,11 +1214,7 @@ func (s *DockerSuite) TestContainerApiRename(c *check.C) {
func (s *DockerSuite) TestContainerApiKill(c *check.C) { func (s *DockerSuite) TestContainerApiKill(c *check.C) {
name := "test-api-kill" name := "test-api-kill"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top") dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil) status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1305,11 +1231,7 @@ func (s *DockerSuite) TestContainerApiKill(c *check.C) {
func (s *DockerSuite) TestContainerApiRestart(c *check.C) { func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
name := "test-api-restart" name := "test-api-restart"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top") dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil) status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1322,11 +1244,7 @@ func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
func (s *DockerSuite) TestContainerApiRestartNotimeoutParam(c *check.C) { func (s *DockerSuite) TestContainerApiRestartNotimeoutParam(c *check.C) {
name := "test-api-restart-no-timeout-param" name := "test-api-restart-no-timeout-param"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top") out, _ := dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
@ -1364,11 +1282,7 @@ func (s *DockerSuite) TestContainerApiStart(c *check.C) {
func (s *DockerSuite) TestContainerApiStop(c *check.C) { func (s *DockerSuite) TestContainerApiStop(c *check.C) {
name := "test-api-stop" name := "test-api-stop"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top") dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=1", nil) status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=1", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1386,11 +1300,7 @@ func (s *DockerSuite) TestContainerApiStop(c *check.C) {
func (s *DockerSuite) TestContainerApiWait(c *check.C) { func (s *DockerSuite) TestContainerApiWait(c *check.C) {
name := "test-api-wait" name := "test-api-wait"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sleep", "5") dockerCmd(c, "run", "--name", name, "busybox", "sleep", "5")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil) status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1412,9 +1322,7 @@ func (s *DockerSuite) TestContainerApiWait(c *check.C) {
func (s *DockerSuite) TestContainerApiCopy(c *check.C) { func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
name := "test-container-api-copy" name := "test-container-api-copy"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/test.txt", Resource: "/test.txt",
@ -1443,9 +1351,7 @@ func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) { func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
name := "test-container-api-copy-resource-empty" name := "test-container-api-copy-resource-empty"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt") dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "", Resource: "",
@ -1459,9 +1365,7 @@ func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) { func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
name := "test-container-api-copy-resource-not-found" name := "test-container-api-copy-resource-not-found"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox") dockerCmd(c, "run", "--name", name, "busybox")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/notexist", Resource: "/notexist",
@ -1484,16 +1388,12 @@ func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiDelete(c *check.C) { func (s *DockerSuite) TestContainerApiDelete(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
stopCmd := exec.Command(dockerBinary, "stop", id) dockerCmd(c, "stop", id)
_, err = runCommand(stopCmd)
c.Assert(err, check.IsNil)
status, _, err := sockRequest("DELETE", "/containers/"+id, nil) status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1508,9 +1408,7 @@ func (s *DockerSuite) TestContainerApiDeleteNotExist(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) { func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
@ -1521,16 +1419,12 @@ func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) { func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "tlink1", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
runCmd = exec.Command(dockerBinary, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top") out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id2 := strings.TrimSpace(out) id2 := strings.TrimSpace(out)
c.Assert(waitRun(id2), check.IsNil) c.Assert(waitRun(id2), check.IsNil)
@ -1555,9 +1449,7 @@ func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
} }
func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) { func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
@ -1570,9 +1462,7 @@ func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) { func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/testvolume", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "-v", "/testvolume", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), check.IsNil)
@ -1644,9 +1534,7 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
} }
func (s *DockerSuite) TestPostContainerStop(c *check.C) { func (s *DockerSuite) TestPostContainerStop(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), check.IsNil) c.Assert(waitRun(containerID), check.IsNil)

View File

@ -2,18 +2,13 @@ package main
import ( import (
"net/http" "net/http"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) { func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(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.Fatalf(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"

View File

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"os/exec"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -15,10 +14,7 @@ import (
// Regression test for #9414 // Regression test for #9414
func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) { func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
name := "exec_test" name := "exec_test"
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil}) status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
c.Assert(status, check.Equals, http.StatusInternalServerError) c.Assert(status, check.Equals, http.StatusInternalServerError)

View File

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/url" "net/url"
"os/exec"
"strings" "strings"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
@ -16,9 +15,7 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
name2 := "utest/docker:tag2" name2 := "utest/docker:tag2"
name3 := "utest:5000/docker:tag3" name3 := "utest:5000/docker:tag3"
for _, n := range []string{name, name2, name3} { for _, n := range []string{name, name2, name3} {
if out, err := exec.Command(dockerBinary, "tag", "busybox", n).CombinedOutput(); err != nil { dockerCmd(c, "tag", "busybox", n)
c.Fatal(err, out)
}
} }
type image types.Image type image types.Image
getImages := func(filter string) []image { getImages := func(filter string) []image {
@ -65,9 +62,7 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
defer body.Close() defer body.Close()
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil { dockerCmd(c, "rmi", id)
c.Fatal(err, out)
}
res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar") res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -75,10 +70,7 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
defer loadBody.Close() defer loadBody.Close()
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput() inspectOut, _ := dockerCmd(c, "inspect", "--format='{{ .Id }}'", id)
if err != nil {
c.Fatal(err, inspectOut)
}
if strings.TrimSpace(string(inspectOut)) != id { if strings.TrimSpace(string(inspectOut)) != id {
c.Fatal("load did not work properly") c.Fatal("load did not work properly")
} }
@ -93,9 +85,7 @@ func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
} }
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
if out, err := exec.Command(dockerBinary, "tag", name, "test:tag1").CombinedOutput(); err != nil { dockerCmd(c, "tag", name, "test:tag1")
c.Fatal(err, out)
}
status, _, err := sockRequest("DELETE", "/images/"+id, nil) status, _, err := sockRequest("DELETE", "/images/"+id, nil)
c.Assert(status, check.Equals, http.StatusConflict) c.Assert(status, check.Equals, http.StatusConflict)

View File

@ -3,18 +3,13 @@ package main
import ( import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) { func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("failed to create a container: %s, %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)

View File

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/http" "net/http"
"os/exec"
"strings" "strings"
"time" "time"
@ -46,10 +45,7 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) { func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
name := "logs_test" name := "logs_test"
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil) status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
c.Assert(status, check.Equals, http.StatusBadRequest) c.Assert(status, check.Equals, http.StatusBadRequest)
@ -65,10 +61,7 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) { func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) {
name := "logs_test" name := "logs_test"
t0 := time.Now() t0 := time.Now()
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "") _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
t1 := time.Now() t1 := time.Now()

View File

@ -2,18 +2,13 @@ package main
import ( import (
"net/http" "net/http"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestResizeApiResponse(c *check.C) { func (s *DockerSuite) TestResizeApiResponse(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.Fatalf(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
@ -23,11 +18,7 @@ func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
} }
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) { func (s *DockerSuite) TestResizeApiHeightWidthNoInt(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.Fatalf(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
@ -37,19 +28,11 @@ func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
} }
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) { func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
// make sure the exited container is not running // make sure the exited container is not running
runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID) dockerCmd(c, "wait", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
status, body, err := sockRequest("POST", endpoint, nil) status, body, err := sockRequest("POST", endpoint, nil)

View File

@ -76,10 +76,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
c.Fatalf("Attaches did not initialize properly") c.Fatalf("Attaches did not initialize properly")
} }
cmd := exec.Command(dockerBinary, "kill", "attacher") dockerCmd(c, "kill", "attacher")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
select { select {
case <-endDone: case <-endDone:
@ -90,11 +87,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
} }
func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) { func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox") out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("failed to start container: %v (%v)", out, err)
}
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
if err := waitRun(id); err != nil { if err := waitRun(id); err != nil {

View File

@ -16,11 +16,7 @@ import (
// #9860 // #9860
func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) { func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-dti", "busybox", "sleep", "2") out, _ := dockerCmd(c, "run", "-dti", "busybox", "sleep", "2")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("failed to start container: %v (%v)", out, err)
}
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
if err := waitRun(id); err != nil { if err := waitRun(id); err != nil {
@ -47,10 +43,8 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
} }
}() }()
waitCmd := exec.Command(dockerBinary, "wait", id) dockerCmd(c, "wait", id)
if out, _, err = runCommandWithOutput(waitCmd); err != nil {
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
}
select { select {
case err := <-errChan: case err := <-errChan:
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)

View File

@ -76,16 +76,7 @@ func (s *DockerSuite) TestBuildShCmdJSONEntrypoint(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput( out, _ := dockerCmd(c, "run", "--rm", name)
exec.Command(
dockerBinary,
"run",
"--rm",
name))
if err != nil {
c.Fatal(err)
}
if strings.TrimSpace(out) != "/bin/sh -c echo test" { if strings.TrimSpace(out) != "/bin/sh -c echo test" {
c.Fatal("CMD did not contain /bin/sh -c") c.Fatal("CMD did not contain /bin/sh -c")
@ -420,12 +411,12 @@ func (s *DockerSuite) TestBuildEnvEscapes(c *check.C) {
`, `,
true) true)
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name))
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
} }
out, _ := dockerCmd(c, "run", "-t", name)
if strings.TrimSpace(out) != "$" { if strings.TrimSpace(out) != "$" {
c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out)) c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
} }
@ -447,11 +438,7 @@ func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-e", "TEST=bar", "-t", name)) out, _ := dockerCmd(c, "run", "-e", "TEST=bar", "-t", name)
if err != nil {
c.Fatal(err)
}
if strings.TrimSpace(out) != "bar" { if strings.TrimSpace(out) != "bar" {
c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out)) c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
@ -462,21 +449,13 @@ func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) {
func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.C) { func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenmaintainerinsourceimage" name := "testbuildonbuildforbiddenmaintainerinsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") out, _ := dockerCmd(c, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"MAINTAINER docker.io\"]}", cleanedContainerID, "onbuild") dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"MAINTAINER docker.io\"]}", cleanedContainerID, "onbuild")
if _, err := runCommand(commitCmd); err != nil { _, err := buildImage(name,
c.Fatal(err)
}
_, err = buildImage(name,
`FROM onbuild`, `FROM onbuild`,
true) true)
if err != nil { if err != nil {
@ -492,21 +471,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.
func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) { func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenfrominsourceimage" name := "testbuildonbuildforbiddenfrominsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") out, _ := dockerCmd(c, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"FROM busybox\"]}", cleanedContainerID, "onbuild") dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"FROM busybox\"]}", cleanedContainerID, "onbuild")
if _, err := runCommand(commitCmd); err != nil { _, err := buildImage(name,
c.Fatal(err)
}
_, err = buildImage(name,
`FROM onbuild`, `FROM onbuild`,
true) true)
if err != nil { if err != nil {
@ -522,21 +493,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
func (s *DockerSuite) TestBuildOnBuildForbiddenChainedInSourceImage(c *check.C) { func (s *DockerSuite) TestBuildOnBuildForbiddenChainedInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenchainedinsourceimage" name := "testbuildonbuildforbiddenchainedinsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true") out, _ := dockerCmd(c, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
commitCmd := exec.Command(dockerBinary, "commit", "--run", "{\"OnBuild\":[\"ONBUILD RUN ls\"]}", cleanedContainerID, "onbuild") dockerCmd(c, "commit", "--run", "{\"OnBuild\":[\"ONBUILD RUN ls\"]}", cleanedContainerID, "onbuild")
if _, err := runCommand(commitCmd); err != nil { _, err := buildImage(name,
c.Fatal(err)
}
_, err = buildImage(name,
`FROM onbuild`, `FROM onbuild`,
true) true)
if err != nil { if err != nil {
@ -570,10 +533,7 @@ ONBUILD RUN ["true"]`,
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2)) out, _ := dockerCmd(c, "run", "-t", name2)
if err != nil {
c.Fatal(err)
}
if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) { if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
c.Fatal("did not get echo output from onbuild", out) c.Fatal("did not get echo output from onbuild", out)
@ -600,10 +560,7 @@ ONBUILD ENTRYPOINT ["echo"]`,
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2)) out, _ := dockerCmd(c, "run", "-t", name2)
if err != nil {
c.Fatal(err)
}
if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) { if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
c.Fatal("got malformed output from onbuild", out) c.Fatal("got malformed output from onbuild", out)
@ -1827,11 +1784,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) {
} }
defer ctx.Close() defer ctx.Close()
buildCmd := exec.Command(dockerBinary, "build", "-t", name, "--force-rm", ".") dockerCmdInDir(c, ctx.Dir, "build", "-t", name, "--force-rm", ".")
buildCmd.Dir = ctx.Dir
if out, _, err := runCommandWithOutput(buildCmd); err == nil {
c.Fatalf("failed to build the image: %s, %v", out, err)
}
containerCountAfter, err := getContainerCount() containerCountAfter, err := getContainerCount()
if err != nil { if err != nil {
@ -3100,11 +3053,7 @@ func (s *DockerSuite) TestBuildWithVolumeOwnership(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
cmd := exec.Command(dockerBinary, "run", "--rm", "testbuildimg", "ls", "-la", "/test") out, _ := dockerCmd(c, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(out, err)
}
if expected := "drw-------"; !strings.Contains(out, expected) { if expected := "drw-------"; !strings.Contains(out, expected) {
c.Fatalf("expected %s received %s", expected, out) c.Fatalf("expected %s received %s", expected, out)
@ -3349,6 +3298,9 @@ func (s *DockerSuite) TestBuildEscapeWhitespace(c *check.C) {
IO <io@\ IO <io@\
docker.com>" docker.com>"
`, true) `, true)
if err != nil {
c.Fatal(err)
}
res, err := inspectField(name, "Author") res, err := inspectField(name, "Author")
@ -3371,11 +3323,12 @@ func (s *DockerSuite) TestBuildVerifyIntString(c *check.C) {
MAINTAINER 123 MAINTAINER 123
`, true) `, true)
out, rc, err := runCommandWithOutput(exec.Command(dockerBinary, "inspect", name)) if err != nil {
if rc != 0 || err != nil { c.Fatal(err)
c.Fatalf("Unexpected error from inspect: rc: %v err: %v", rc, err)
} }
out, _ := dockerCmd(c, "inspect", name)
if !strings.Contains(out, "\"123\"") { if !strings.Contains(out, "\"123\"") {
c.Fatalf("Output does not contain the int as a string:\n%s", out) c.Fatalf("Output does not contain the int as a string:\n%s", out)
} }
@ -4030,6 +3983,7 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) {
if err := tw.Close(); err != nil { if err := tw.Close(); err != nil {
c.Fatalf("failed to close tar archive: %v", err) c.Fatalf("failed to close tar archive: %v", err)
} }
xzCompressCmd := exec.Command("xz", "-k", "test.tar") xzCompressCmd := exec.Command("xz", "-k", "test.tar")
xzCompressCmd.Dir = tmpDir xzCompressCmd.Dir = tmpDir
out, _, err := runCommandWithOutput(xzCompressCmd) out, _, err := runCommandWithOutput(xzCompressCmd)
@ -4389,9 +4343,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
status, _ := runCommand(exec.Command(dockerBinary, "run", "parent")) if _, status, _ := dockerCmdWithError(c, "run", "parent"); status != 130 {
if status != 130 {
c.Fatalf("expected exit code 130 but received %d", status) c.Fatalf("expected exit code 130 but received %d", status)
} }
@ -4402,9 +4354,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
status, _ = runCommand(exec.Command(dockerBinary, "run", "child")) if _, status, _ := dockerCmdWithError(c, "run", "child"); status != 5 {
if status != 5 {
c.Fatalf("expected exit code 5 but received %d", status) c.Fatalf("expected exit code 5 but received %d", status)
} }
@ -4434,10 +4384,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritanceInspect(c *check.C) {
c.Fatalf("Expected value %s not in Config.Entrypoint: %s", expected, res) c.Fatalf("Expected value %s not in Config.Entrypoint: %s", expected, res)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2)) out, _ := dockerCmd(c, "run", "-t", name2)
if err != nil {
c.Fatal(err, out)
}
expected = "quux" expected = "quux"
@ -4457,12 +4404,7 @@ func (s *DockerSuite) TestBuildRunShEntrypoint(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name)) dockerCmd(c, "run", "--rm", name)
if err != nil {
c.Fatal(err, out)
}
} }
func (s *DockerSuite) TestBuildExoticShellInterpolation(c *check.C) { func (s *DockerSuite) TestBuildExoticShellInterpolation(c *check.C) {
@ -4501,13 +4443,14 @@ func (s *DockerSuite) TestBuildVerifySingleQuoteFails(c *check.C) {
// it should barf on it. // it should barf on it.
name := "testbuildsinglequotefails" name := "testbuildsinglequotefails"
_, err := buildImage(name, if _, err := buildImage(name,
`FROM busybox `FROM busybox
CMD [ '/bin/sh', '-c', 'echo hi' ]`, CMD [ '/bin/sh', '-c', 'echo hi' ]`,
true) true); err != nil {
_, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name)) c.Fatal(err)
}
if err == nil { if _, _, err := dockerCmdWithError(c, "run", "--rm", name); err == nil {
c.Fatal("The image was not supposed to be able to run") c.Fatal("The image was not supposed to be able to run")
} }
@ -4771,10 +4714,7 @@ CMD cat /foo/file`,
c.Fatal(err) c.Fatal(err)
} }
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name)) out, _ := dockerCmd(c, "run", "--rm", name)
if err != nil {
c.Fatal(err)
}
if out != expected { if out != expected {
c.Fatalf("expected file contents for /foo/file to be %q but received %q", expected, out) c.Fatalf("expected file contents for /foo/file to be %q but received %q", expected, out)
} }
@ -5056,7 +4996,7 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) {
filepath.Join(ctx, "dockerfile1"), filepath.Join(ctx, "dockerfile1"),
filepath.Join(ctx, "dockerfile2"), filepath.Join(ctx, "dockerfile2"),
} { } {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "build", "-t", name, "--no-cache", "-f", dockerfilePath, ".")) out, _, err := dockerCmdWithError(c, "build", "-t", name, "--no-cache", "-f", dockerfilePath, ".")
if err == nil { if err == nil {
c.Fatalf("Expected error with %s. Out: %s", dockerfilePath, out) c.Fatalf("Expected error with %s. Out: %s", dockerfilePath, out)
} }
@ -5070,7 +5010,7 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) {
// Path to Dockerfile should be resolved relative to working directory, not relative to context. // Path to Dockerfile should be resolved relative to working directory, not relative to context.
// There is a Dockerfile in the context, but since there is no Dockerfile in the current directory, the following should fail // There is a Dockerfile in the context, but since there is no Dockerfile in the current directory, the following should fail
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "build", "-t", name, "--no-cache", "-f", "Dockerfile", ctx)) out, _, err := dockerCmdWithError(c, "build", "-t", name, "--no-cache", "-f", "Dockerfile", ctx)
if err == nil { if err == nil {
c.Fatalf("Expected error. Out: %s", out) c.Fatalf("Expected error. Out: %s", out)
} }
@ -5257,9 +5197,7 @@ func (s *DockerSuite) TestBuildNotVerbose(c *check.C) {
defer ctx.Close() defer ctx.Close()
// First do it w/verbose - baseline // First do it w/verbose - baseline
buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".") out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", "verbose", ".")
buildCmd.Dir = ctx.Dir
out, _, err := runCommandWithOutput(buildCmd)
if err != nil { if err != nil {
c.Fatalf("failed to build the image w/o -q: %s, %v", out, err) c.Fatalf("failed to build the image w/o -q: %s, %v", out, err)
} }
@ -5268,9 +5206,7 @@ func (s *DockerSuite) TestBuildNotVerbose(c *check.C) {
} }
// Now do it w/o verbose // Now do it w/o verbose
buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".") out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-q", "-t", "verbose", ".")
buildCmd.Dir = ctx.Dir
out, _, err = runCommandWithOutput(buildCmd)
if err != nil { if err != nil {
c.Fatalf("failed to build the image w/ -q: %s, %v", out, err) c.Fatalf("failed to build the image w/ -q: %s, %v", out, err)
} }
@ -5290,9 +5226,7 @@ RUN [ "/hello" ]`, map[string]string{})
} }
defer ctx.Close() defer ctx.Close()
buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", name, ".") out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", name, ".")
buildCmd.Dir = ctx.Dir
out, _, err := runCommandWithOutput(buildCmd)
if err != nil { if err != nil {
c.Fatalf("failed to build the image: %s, %v", out, err) c.Fatalf("failed to build the image: %s, %v", out, err)
} }

View File

@ -4,7 +4,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
@ -22,14 +21,9 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
cmd := exec.Command(dockerBinary, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".") dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".")
cmd.Dir = ctx.Dir
out, _, err := runCommandWithOutput(cmd) out, _ := dockerCmd(c, "ps", "-lq")
if err != nil {
c.Fatal(err, out)
}
out, _ = dockerCmd(c, "ps", "-lq")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
@ -57,7 +51,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
} }
// Make sure constraints aren't saved to image // Make sure constraints aren't saved to image
_, _ = dockerCmd(c, "run", "--name=test", name) dockerCmd(c, "run", "--name=test", name)
cfg, err = inspectFieldJSON("test", "HostConfig") cfg, err = inspectFieldJSON("test", "HostConfig")
if err != nil { if err != nil {

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os/exec"
"regexp" "regexp"
"strings" "strings"
@ -15,22 +14,18 @@ var (
digestRegex = regexp.MustCompile("Digest: ([^\n]+)") digestRegex = regexp.MustCompile("Digest: ([^\n]+)")
) )
func setupImage() (string, error) { func setupImage(c *check.C) (string, error) {
return setupImageWithTag("latest") return setupImageWithTag(c, "latest")
} }
func setupImageWithTag(tag string) (string, error) { func setupImageWithTag(c *check.C, tag string) (string, error) {
containerName := "busyboxbydigest" containerName := "busyboxbydigest"
cmd := exec.Command(dockerBinary, "run", "-d", "-e", "digest=1", "--name", containerName, "busybox") dockerCmd(c, "run", "-d", "-e", "digest=1", "--name", containerName, "busybox")
if _, err := runCommand(cmd); err != nil {
return "", err
}
// tag the image to upload it to the private registry // tag the image to upload it to the private registry
repoAndTag := utils.ImageReference(repoName, tag) repoAndTag := utils.ImageReference(repoName, tag)
cmd = exec.Command(dockerBinary, "commit", containerName, repoAndTag) if out, _, err := dockerCmdWithError(c, "commit", containerName, repoAndTag); err != nil {
if out, _, err := runCommandWithOutput(cmd); err != nil {
return "", fmt.Errorf("image tagging failed: %s, %v", out, err) return "", fmt.Errorf("image tagging failed: %s, %v", out, err)
} }
@ -40,16 +35,14 @@ func setupImageWithTag(tag string) (string, error) {
} }
// push the image // push the image
cmd = exec.Command(dockerBinary, "push", repoAndTag) out, _, err := dockerCmdWithError(c, "push", repoAndTag)
out, _, err := runCommandWithOutput(cmd)
if err != nil { if err != nil {
return "", fmt.Errorf("pushing the image to the private registry has failed: %s, %v", out, err) return "", fmt.Errorf("pushing the image to the private registry has failed: %s, %v", out, err)
} }
// delete our local repo that we previously tagged // delete our local repo that we previously tagged
cmd = exec.Command(dockerBinary, "rmi", repoAndTag) if rmiout, _, err := dockerCmdWithError(c, "rmi", repoAndTag); err != nil {
if out, _, err := runCommandWithOutput(cmd); err != nil { return "", fmt.Errorf("error deleting images prior to real test: %s, %v", rmiout, err)
return "", fmt.Errorf("error deleting images prior to real test: %s, %v", out, err)
} }
// the push output includes "Digest: <digest>", so find that // the push output includes "Digest: <digest>", so find that
@ -63,17 +56,13 @@ func setupImageWithTag(tag string) (string, error) {
} }
func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) { func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
pushDigest, err := setupImage() pushDigest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
// pull from the registry using the tag // pull from the registry using the tag
cmd := exec.Command(dockerBinary, "pull", repoName) out, _ := dockerCmd(c, "pull", repoName)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by tag: %s, %v", out, err)
}
// the pull output includes "Digest: <digest>", so find that // the pull output includes "Digest: <digest>", so find that
matches := digestRegex.FindStringSubmatch(out) matches := digestRegex.FindStringSubmatch(out)
@ -89,18 +78,14 @@ func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) { func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
pushDigest, err := setupImage() pushDigest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
cmd := exec.Command(dockerBinary, "pull", imageReference) out, _ := dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// the pull output includes "Digest: <digest>", so find that // the pull output includes "Digest: <digest>", so find that
matches := digestRegex.FindStringSubmatch(out) matches := digestRegex.FindStringSubmatch(out)
@ -118,15 +103,14 @@ func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) { func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName) imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName)
cmd := exec.Command(dockerBinary, "pull", imageReference) out, _, err := dockerCmdWithError(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err == nil || !strings.Contains(out, "pulling with digest reference failed from v2 registry") { if err == nil || !strings.Contains(out, "pulling with digest reference failed from v2 registry") {
c.Fatalf("expected non-zero exit status and correct error message when pulling non-existing image: %s", out) c.Fatalf("expected non-zero exit status and correct error message when pulling non-existing image: %s", out)
} }
} }
func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) { func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
pushDigest, err := setupImage() pushDigest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -134,11 +118,7 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
containerName := "createByDigest" containerName := "createByDigest"
cmd := exec.Command(dockerBinary, "create", "--name", containerName, imageReference) out, _ := dockerCmd(c, "create", "--name", containerName, imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error creating by digest: %s, %v", out, err)
}
res, err := inspectField(containerName, "Config.Image") res, err := inspectField(containerName, "Config.Image")
if err != nil { if err != nil {
@ -150,7 +130,7 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) { func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
pushDigest, err := setupImage() pushDigest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -158,11 +138,7 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
containerName := "runByDigest" containerName := "runByDigest"
cmd := exec.Command(dockerBinary, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest") out, _ := dockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error run by digest: %s, %v", out, err)
}
foundRegex := regexp.MustCompile("found=([^\n]+)") foundRegex := regexp.MustCompile("found=([^\n]+)")
matches := foundRegex.FindStringSubmatch(out) matches := foundRegex.FindStringSubmatch(out)
@ -183,7 +159,7 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) { func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
digest, err := setupImage() digest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -191,11 +167,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, digest) imageReference := fmt.Sprintf("%s@%s", repoName, digest)
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
cmd := exec.Command(dockerBinary, "pull", imageReference) dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// make sure inspect runs ok // make sure inspect runs ok
if _, err := inspectField(imageReference, "Id"); err != nil { if _, err := inspectField(imageReference, "Id"); err != nil {
@ -216,7 +188,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
digest, err := setupImage() digest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -224,11 +196,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, digest) imageReference := fmt.Sprintf("%s@%s", repoName, digest)
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
cmd := exec.Command(dockerBinary, "pull", imageReference) dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// get the image id // get the image id
imageID, err := inspectField(imageReference, "Id") imageID, err := inspectField(imageReference, "Id")
@ -258,7 +226,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) { func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
digest, err := setupImage() digest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -266,18 +234,11 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, digest) imageReference := fmt.Sprintf("%s@%s", repoName, digest)
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
cmd := exec.Command(dockerBinary, "pull", imageReference) dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// tag it // tag it
tag := "tagbydigest" tag := "tagbydigest"
cmd = exec.Command(dockerBinary, "tag", imageReference, tag) dockerCmd(c, "tag", imageReference, tag)
if _, err := runCommand(cmd); err != nil {
c.Fatalf("unexpected error tagging: %v", err)
}
expectedID, err := inspectField(imageReference, "Id") expectedID, err := inspectField(imageReference, "Id")
if err != nil { if err != nil {
@ -295,7 +256,7 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
} }
func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) { func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
digest, err := setupImage() digest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -303,17 +264,9 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
imageReference := fmt.Sprintf("%s@%s", repoName, digest) imageReference := fmt.Sprintf("%s@%s", repoName, digest)
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
cmd := exec.Command(dockerBinary, "pull", imageReference) dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
cmd = exec.Command(dockerBinary, "images") out, _ := dockerCmd(c, "images")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
if strings.Contains(out, "DIGEST") { if strings.Contains(out, "DIGEST") {
c.Fatalf("list output should not have contained DIGEST header: %s", out) c.Fatalf("list output should not have contained DIGEST header: %s", out)
@ -324,7 +277,7 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) { func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
// setup image1 // setup image1
digest1, err := setupImageWithTag("tag1") digest1, err := setupImageWithTag(c, "tag1")
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -332,18 +285,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
c.Logf("imageReference1 = %s", imageReference1) c.Logf("imageReference1 = %s", imageReference1)
// pull image1 by digest // pull image1 by digest
cmd := exec.Command(dockerBinary, "pull", imageReference1) dockerCmd(c, "pull", imageReference1)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// list images // list images
cmd = exec.Command(dockerBinary, "images", "--digests") out, _ := dockerCmd(c, "images", "--digests")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
// make sure repo shown, tag=<none>, digest = $digest1 // make sure repo shown, tag=<none>, digest = $digest1
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1 + `\s`) re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1 + `\s`)
@ -352,7 +297,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
} }
// setup image2 // setup image2
digest2, err := setupImageWithTag("tag2") digest2, err := setupImageWithTag(c, "tag2")
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
@ -360,25 +305,13 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
c.Logf("imageReference2 = %s", imageReference2) c.Logf("imageReference2 = %s", imageReference2)
// pull image1 by digest // pull image1 by digest
cmd = exec.Command(dockerBinary, "pull", imageReference1) dockerCmd(c, "pull", imageReference1)
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// pull image2 by digest // pull image2 by digest
cmd = exec.Command(dockerBinary, "pull", imageReference2) dockerCmd(c, "pull", imageReference2)
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// list images // list images
cmd = exec.Command(dockerBinary, "images", "--digests") out, _ = dockerCmd(c, "images", "--digests")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
// make sure repo shown, tag=<none>, digest = $digest1 // make sure repo shown, tag=<none>, digest = $digest1
if !re1.MatchString(out) { if !re1.MatchString(out) {
@ -392,18 +325,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
} }
// pull tag1 // pull tag1
cmd = exec.Command(dockerBinary, "pull", repoName+":tag1") dockerCmd(c, "pull", repoName+":tag1")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling tag1: %s, %v", out, err)
}
// list images // list images
cmd = exec.Command(dockerBinary, "images", "--digests") out, _ = dockerCmd(c, "images", "--digests")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest // make sure image 1 has repo, tag, <none> AND repo, <none>, digest
reWithTag1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*<none>\s`) reWithTag1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*<none>\s`)
@ -420,18 +345,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
} }
// pull tag 2 // pull tag 2
cmd = exec.Command(dockerBinary, "pull", repoName+":tag2") dockerCmd(c, "pull", repoName+":tag2")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling tag2: %s, %v", out, err)
}
// list images // list images
cmd = exec.Command(dockerBinary, "images", "--digests") out, _ = dockerCmd(c, "images", "--digests")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
// make sure image 1 has repo, tag, digest // make sure image 1 has repo, tag, digest
if !reWithTag1.MatchString(out) { if !reWithTag1.MatchString(out) {
@ -449,11 +366,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
} }
// list images // list images
cmd = exec.Command(dockerBinary, "images", "--digests") out, _ = dockerCmd(c, "images", "--digests")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error listing images: %s, %v", out, err)
}
// make sure image 1 has repo, tag, digest // make sure image 1 has repo, tag, digest
if !reWithTag1.MatchString(out) { if !reWithTag1.MatchString(out) {
@ -471,18 +384,14 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
} }
func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) { func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
pushDigest, err := setupImage() pushDigest, err := setupImage(c)
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
} }
// pull from the registry using the <name>@<digest> reference // pull from the registry using the <name>@<digest> reference
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
cmd := exec.Command(dockerBinary, "pull", imageReference) dockerCmd(c, "pull", imageReference)
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("error pulling by digest: %s, %v", out, err)
}
// just in case... // just in case...
imageID, err := inspectField(imageReference, "Id") imageID, err := inspectField(imageReference, "Id")
@ -490,8 +399,5 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C)
c.Fatalf("error inspecting image id: %v", err) c.Fatalf("error inspecting image id: %v", err)
} }
cmd = exec.Command(dockerBinary, "rmi", imageID) dockerCmd(c, "rmi", imageID)
if _, err := runCommand(cmd); err != nil {
c.Fatalf("error deleting image by id: %v", err)
}
} }

View File

@ -1,91 +1,51 @@
package main package main
import ( import (
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) { func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %s, %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID) dockerCmd(c, "wait", cleanedContainerID)
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
}
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID) out, _ = dockerCmd(c, "commit", cleanedContainerID)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
cleanedImageID := strings.TrimSpace(out) cleanedImageID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID) dockerCmd(c, "inspect", cleanedImageID)
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
c.Fatalf("failed to inspect image: %s, %v", out, err)
}
} }
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) { func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %s, %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID) dockerCmd(c, "wait", cleanedContainerID)
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
}
commitCmd := exec.Command(dockerBinary, "commit", "-p=false", cleanedContainerID) out, _ = dockerCmd(c, "commit", "-p=false", cleanedContainerID)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
cleanedImageID := strings.TrimSpace(out) cleanedImageID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID) dockerCmd(c, "inspect", cleanedImageID)
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
c.Fatalf("failed to inspect image: %s, %v", out, err)
}
} }
//test commit a paused container should not unpause it after commit //test commit a paused container should not unpause it after commit
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) { func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
defer unpauseAllContainers() defer unpauseAllContainers()
cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox") out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
out, _, _, err := runCommandWithStdoutStderr(cmd)
if err != nil {
c.Fatalf("failed to run container: %v, output: %q", err, out)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
cmd = exec.Command(dockerBinary, "pause", cleanedContainerID)
out, _, _, err = runCommandWithStdoutStderr(cmd)
if err != nil {
c.Fatalf("failed to pause container: %v, output: %q", err, out)
}
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID) dockerCmd(c, "pause", cleanedContainerID)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
out, err = inspectField(cleanedContainerID, "State.Paused") out, _ = dockerCmd(c, "commit", cleanedContainerID)
out, err := inspectField(cleanedContainerID, "State.Paused")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
if !strings.Contains(out, "true") { if !strings.Contains(out, "true") {
c.Fatalf("commit should not unpause a paused container") c.Fatalf("commit should not unpause a paused container")
@ -94,24 +54,13 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
func (s *DockerSuite) TestCommitNewFile(c *check.C) { func (s *DockerSuite) TestCommitNewFile(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo") dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
cmd = exec.Command(dockerBinary, "commit", "commiter") imageID, _ := dockerCmd(c, "commit", "commiter")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
imageID = strings.Trim(imageID, "\r\n") imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo") out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err, out)
}
if actual := strings.Trim(out, "\r\n"); actual != "koye" { if actual := strings.Trim(out, "\r\n"); actual != "koye" {
c.Fatalf("expected output koye received %q", actual) c.Fatalf("expected output koye received %q", actual)
} }
@ -120,13 +69,9 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
func (s *DockerSuite) TestCommitHardlink(c *check.C) { func (s *DockerSuite) TestCommitHardlink(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2") firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
firstOuput, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
chunks := strings.Split(strings.TrimSpace(firstOuput), " ") chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
inode := chunks[0] inode := chunks[0]
found := false found := false
for _, chunk := range chunks[1:] { for _, chunk := range chunks[1:] {
@ -139,20 +84,12 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]) c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
} }
cmd = exec.Command(dockerBinary, "commit", "hardlinks", "hardlinks") imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(imageID, err)
}
imageID = strings.Trim(imageID, "\r\n") imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2") secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
secondOuput, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
chunks = strings.Split(strings.TrimSpace(secondOuput), " ") chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0] inode = chunks[0]
found = false found = false
for _, chunk := range chunks[1:] { for _, chunk := range chunks[1:] {
@ -169,56 +106,31 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
func (s *DockerSuite) TestCommitTTY(c *check.C) { func (s *DockerSuite) TestCommitTTY(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls") dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest") imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
imageID = strings.Trim(imageID, "\r\n") imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls") dockerCmd(c, "run", "ttytest", "/bin/ls")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
} }
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) { func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true") dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
cmd = exec.Command(dockerBinary, "commit", "bind-commit", "bindtest")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(imageID, err)
}
imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "bindtest", "true") dockerCmd(c, "run", "bindtest", "true")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
} }
func (s *DockerSuite) TestCommitChange(c *check.C) { func (s *DockerSuite) TestCommitChange(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "--name", "test", "busybox", "true") dockerCmd(c, "run", "--name", "test", "busybox", "true")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
cmd = exec.Command(dockerBinary, "commit", imageID, _ := dockerCmd(c, "commit",
"--change", "EXPOSE 8080", "--change", "EXPOSE 8080",
"--change", "ENV DEBUG true", "--change", "ENV DEBUG true",
"--change", "ENV test 1", "--change", "ENV test 1",
@ -231,11 +143,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
"--change", "VOLUME /var/lib/docker", "--change", "VOLUME /var/lib/docker",
"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src", "--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
"test", "test-commit") "test", "test-commit")
imageId, _, err := runCommandWithOutput(cmd) imageID = strings.Trim(imageID, "\r\n")
if err != nil {
c.Fatal(imageId, err)
}
imageId = strings.Trim(imageId, "\r\n")
expected := map[string]string{ expected := map[string]string{
"Config.ExposedPorts": "map[8080/tcp:{}]", "Config.ExposedPorts": "map[8080/tcp:{}]",
@ -250,7 +158,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
} }
for conf, value := range expected { for conf, value := range expected {
res, err := inspectField(imageId, conf) res, err := inspectField(imageID, conf)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
if res != value { if res != value {
c.Errorf("%s('%s'), expected %s", conf, res, value) c.Errorf("%s('%s'), expected %s", conf, res, value)

View File

@ -69,17 +69,16 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
cDir, _ := ioutil.TempDir("", "fake-home") cDir, _ := ioutil.TempDir("", "fake-home")
// First make sure pointing to empty dir doesn't generate an error // First make sure pointing to empty dir doesn't generate an error
cmd := exec.Command(dockerBinary, "--config", cDir, "ps") out, rc := dockerCmd(c, "--config", cDir, "ps")
out, rc, err := runCommandWithOutput(cmd)
if rc != 0 || err != nil { if rc != 0 {
c.Fatalf("ps1 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err) c.Fatalf("ps1 didn't work:\nrc:%d\nout%s", rc, out)
} }
// Test with env var too // Test with env var too
cmd = exec.Command(dockerBinary, "ps") cmd := exec.Command(dockerBinary, "ps")
cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir) cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
out, rc, err = runCommandWithOutput(cmd) out, rc, err := runCommandWithOutput(cmd)
if rc != 0 || err != nil { if rc != 0 || err != nil {
c.Fatalf("ps2 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err) c.Fatalf("ps2 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)

View File

@ -61,7 +61,7 @@ func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
path := path.Join("../../../../../../../../../../../../", cpFullPath) path := path.Join("../../../../../../../../../../../../", cpFullPath)
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir) dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname) file, _ := os.Open(tmpname)
defer file.Close() defer file.Close()
@ -126,7 +126,7 @@ func (s *DockerSuite) TestCpRelativePath(c *check.C) {
c.Fatalf("path %s was assumed to be an absolute path", cpFullPath) c.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
} }
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir) dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
file, _ := os.Open(tmpname) file, _ := os.Open(tmpname)
defer file.Close() defer file.Close()
@ -184,7 +184,7 @@ func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
path := cpFullPath path := cpFullPath
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir) dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname) file, _ := os.Open(tmpname)
defer file.Close() defer file.Close()
@ -243,7 +243,7 @@ func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
path := path.Join("/", "container_path") path := path.Join("/", "container_path")
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir) dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname) file, _ := os.Open(tmpname)
defer file.Close() defer file.Close()
@ -302,7 +302,7 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
path := path.Join("/", "container_path", cpTestName) path := path.Join("/", "container_path", cpTestName)
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir) dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname) file, _ := os.Open(tmpname)
defer file.Close() defer file.Close()
@ -380,7 +380,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
} }
// Copy actual /etc/resolv.conf // Copy actual /etc/resolv.conf
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir) dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf") expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf")
actual, err := ioutil.ReadFile(outDir + "/resolv.conf") actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
@ -390,7 +390,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
} }
// Copy actual /etc/hosts // Copy actual /etc/hosts
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir) dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts") expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts")
actual, err = ioutil.ReadFile(outDir + "/hosts") actual, err = ioutil.ReadFile(outDir + "/hosts")
@ -400,7 +400,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
} }
// Copy actual /etc/resolv.conf // Copy actual /etc/resolv.conf
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir) dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname") expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname")
actual, err = ioutil.ReadFile(outDir + "/hostname") actual, err = ioutil.ReadFile(outDir + "/hostname")
@ -442,7 +442,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
} }
// Copy actual volume path // Copy actual volume path
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir) dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
stat, err := os.Stat(outDir + "/foo") stat, err := os.Stat(outDir + "/foo")
if err != nil { if err != nil {
@ -460,7 +460,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
} }
// Copy file nested in volume // Copy file nested in volume
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir) dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
stat, err = os.Stat(outDir + "/bar") stat, err = os.Stat(outDir + "/bar")
if err != nil { if err != nil {
@ -471,7 +471,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
} }
// Copy Bind-mounted dir // Copy Bind-mounted dir
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir) dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
stat, err = os.Stat(outDir + "/baz") stat, err = os.Stat(outDir + "/baz")
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
@ -481,7 +481,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
} }
// Copy file nested in bind-mounted dir // Copy file nested in bind-mounted dir
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir) dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
fb, err := ioutil.ReadFile(outDir + "/baz/test") fb, err := ioutil.ReadFile(outDir + "/baz/test")
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
@ -495,7 +495,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
} }
// Copy bind-mounted file // Copy bind-mounted file
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", outDir) dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
fb, err = ioutil.ReadFile(outDir + "/test") fb, err = ioutil.ReadFile(outDir + "/test")
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
@ -536,7 +536,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
if err := os.Chdir(tmpdir); err != nil { if err := os.Chdir(tmpdir); err != nil {
c.Fatal(err) c.Fatal(err)
} }
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", ".") dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
content, err := ioutil.ReadFile("./test") content, err := ioutil.ReadFile("./test")
if string(content) != "lololol\n" { if string(content) != "lololol\n" {
c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n") c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
@ -589,7 +589,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir) dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
content, err := ioutil.ReadFile(tmpdir + "/te:s:t") content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
if string(content) != "lololol\n" { if string(content) != "lololol\n" {
c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n") c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
@ -598,17 +598,12 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
func (s *DockerSuite) TestCopyAndRestart(c *check.C) { func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
expectedMsg := "hello" expectedMsg := "hello"
out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", expectedMsg).CombinedOutput() out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
if err != nil {
c.Fatal(string(out), err)
}
id := strings.TrimSpace(string(out)) id := strings.TrimSpace(string(out))
if out, err = exec.Command(dockerBinary, "wait", id).CombinedOutput(); err != nil { out, _ = dockerCmd(c, "wait", id)
c.Fatalf("unable to wait for container: %s", err)
}
status := strings.TrimSpace(string(out)) status := strings.TrimSpace(out)
if status != "0" { if status != "0" {
c.Fatalf("container exited with status %s", status) c.Fatalf("container exited with status %s", status)
} }
@ -619,33 +614,23 @@ func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
if _, err = exec.Command(dockerBinary, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir).CombinedOutput(); err != nil { dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir)
c.Fatalf("unable to copy from busybox container: %s", err)
}
if out, err = exec.Command(dockerBinary, "start", "-a", id).CombinedOutput(); err != nil { out, _ = dockerCmd(c, "start", "-a", id)
c.Fatalf("unable to start busybox container after copy: %s - %s", err, out)
}
msg := strings.TrimSpace(string(out)) msg := strings.TrimSpace(out)
if msg != expectedMsg { if msg != expectedMsg {
c.Fatalf("expected %q but got %q", expectedMsg, msg) c.Fatalf("expected %q but got %q", expectedMsg, msg)
} }
} }
func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) { func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
out, err := exec.Command(dockerBinary, "create", "--name", "test_cp", "-v", "/test", "busybox").CombinedOutput() dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
if err != nil {
c.Fatalf(string(out), err)
}
tmpDir, err := ioutil.TempDir("", "test") tmpDir, err := ioutil.TempDir("", "test")
if err != nil { if err != nil {
c.Fatalf("unable to make temporary directory: %s", err) c.Fatalf("unable to make temporary directory: %s", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
out, err = exec.Command(dockerBinary, "cp", "test_cp:/bin/sh", tmpDir).CombinedOutput() dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
if err != nil {
c.Fatalf(string(out), err)
}
} }

View File

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"os/exec"
"reflect" "reflect"
"strings" "strings"
"time" "time"
@ -15,19 +14,11 @@ import (
// Make sure we can create a simple container with some args // Make sure we can create a simple container with some args
func (s *DockerSuite) TestCreateArgs(c *check.C) { func (s *DockerSuite) TestCreateArgs(c *check.C) {
runCmd := exec.Command(dockerBinary, "create", "busybox", "command", "arg1", "arg2", "arg with space") out, _ := dockerCmd(c, "create", "busybox", "command", "arg1", "arg2", "arg with space")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) out, _ = dockerCmd(c, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
c.Fatalf("out should've been a container id: %s, %v", out, err)
}
containers := []struct { containers := []struct {
ID string ID string
@ -65,19 +56,11 @@ func (s *DockerSuite) TestCreateArgs(c *check.C) {
// Make sure we can set hostconfig options too // Make sure we can set hostconfig options too
func (s *DockerSuite) TestCreateHostConfig(c *check.C) { func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
runCmd := exec.Command(dockerBinary, "create", "-P", "busybox", "echo") out, _ := dockerCmd(c, "create", "-P", "busybox", "echo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) out, _ = dockerCmd(c, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
c.Fatalf("out should've been a container id: %s, %v", out, err)
}
containers := []struct { containers := []struct {
HostConfig *struct { HostConfig *struct {
@ -104,19 +87,11 @@ func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
func (s *DockerSuite) TestCreateWithPortRange(c *check.C) { func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
runCmd := exec.Command(dockerBinary, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo") out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) out, _ = dockerCmd(c, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
c.Fatalf("out should've been a container id: %s, %v", out, err)
}
containers := []struct { containers := []struct {
HostConfig *struct { HostConfig *struct {
@ -151,19 +126,11 @@ func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
func (s *DockerSuite) TestCreateWithiLargePortRange(c *check.C) { func (s *DockerSuite) TestCreateWithiLargePortRange(c *check.C) {
runCmd := exec.Command(dockerBinary, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo") out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) out, _ = dockerCmd(c, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
c.Fatalf("out should've been a container id: %s, %v", out, err)
}
containers := []struct { containers := []struct {
HostConfig *struct { HostConfig *struct {
@ -199,19 +166,11 @@ func (s *DockerSuite) TestCreateWithiLargePortRange(c *check.C) {
// "test123" should be printed by docker create + start // "test123" should be printed by docker create + start
func (s *DockerSuite) TestCreateEchoStdout(c *check.C) { func (s *DockerSuite) TestCreateEchoStdout(c *check.C) {
runCmd := exec.Command(dockerBinary, "create", "busybox", "echo", "test123") out, _ := dockerCmd(c, "create", "busybox", "echo", "test123")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "start", "-ai", cleanedContainerID) out, _ = dockerCmd(c, "start", "-ai", cleanedContainerID)
out, _, _, err = runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}
if out != "test123\n" { if out != "test123\n" {
c.Errorf("container should've printed 'test123', got %q", out) c.Errorf("container should've printed 'test123', got %q", out)
@ -223,9 +182,8 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)
name := "test_create_volume" name := "test_create_volume"
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-v", "/foo", "busybox")); err != nil { dockerCmd(c, "create", "--name", name, "-v", "/foo", "busybox")
c.Fatal(out, err)
}
dir, err := inspectFieldMap(name, "Volumes", "/foo") dir, err := inspectFieldMap(name, "Volumes", "/foo")
if err != nil { if err != nil {
c.Fatalf("Error getting volume host path: %q", err) c.Fatalf("Error getting volume host path: %q", err)
@ -243,9 +201,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
func (s *DockerSuite) TestCreateLabels(c *check.C) { func (s *DockerSuite) TestCreateLabels(c *check.C) {
name := "test_create_labels" name := "test_create_labels"
expected := map[string]string{"k1": "v1", "k2": "v2"} expected := map[string]string{"k1": "v1", "k2": "v2"}
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")); err != nil { dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
c.Fatal(out, err)
}
actual := make(map[string]string) actual := make(map[string]string)
err := inspectFieldAndMarshall(name, "Config.Labels", &actual) err := inspectFieldAndMarshall(name, "Config.Labels", &actual)
@ -270,9 +226,7 @@ func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
name := "test_create_labels_from_image" name := "test_create_labels_from_image"
expected := map[string]string{"k2": "x", "k3": "v3"} expected := map[string]string{"k2": "x", "k3": "v3"}
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)); err != nil { dockerCmd(c, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)
c.Fatal(out, err)
}
actual := make(map[string]string) actual := make(map[string]string)
err = inspectFieldAndMarshall(name, "Config.Labels", &actual) err = inspectFieldAndMarshall(name, "Config.Labels", &actual)
@ -297,47 +251,23 @@ func (s *DockerSuite) TestCreateRM(c *check.C) {
// "Created" state, and has ever been run. Test "rm -f" too. // "Created" state, and has ever been run. Test "rm -f" too.
// create a container // create a container
createCmd := exec.Command(dockerBinary, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
out, _, err := runCommandWithOutput(createCmd)
if err != nil {
c.Fatalf("Failed to create container:%s\n%s", out, err)
}
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
rmCmd := exec.Command(dockerBinary, "rm", cID) dockerCmd(c, "rm", cID)
out, _, err = runCommandWithOutput(rmCmd)
if err != nil {
c.Fatalf("Failed to rm container:%s\n%s", out, err)
}
// Now do it again so we can "rm -f" this time // Now do it again so we can "rm -f" this time
createCmd = exec.Command(dockerBinary, "create", "busybox") out, _ = dockerCmd(c, "create", "busybox")
out, _, err = runCommandWithOutput(createCmd)
if err != nil {
c.Fatalf("Failed to create 2nd container:%s\n%s", out, err)
}
cID = strings.TrimSpace(out) cID = strings.TrimSpace(out)
rmCmd = exec.Command(dockerBinary, "rm", "-f", cID) dockerCmd(c, "rm", "-f", cID)
out, _, err = runCommandWithOutput(rmCmd)
if err != nil {
c.Fatalf("Failed to rm -f container:%s\n%s", out, err)
}
} }
func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) { func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)
cmd := exec.Command(dockerBinary, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err, out)
}
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
cmd = exec.Command(dockerBinary, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox") dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("Create container with ipc mode container should success with non running container: %s\n%s", out, err)
}
} }

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
@ -27,8 +26,7 @@ func (s *DockerSuite) TestPause(c *check.C) {
dockerCmd(c, "unpause", name) dockerCmd(c, "unpause", name)
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
out, _, _ = runCommandWithOutput(eventsCmd)
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
if len(events) <= 1 { if len(events) <= 1 {
c.Fatalf("Missing expected event") c.Fatalf("Missing expected event")
@ -69,8 +67,7 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
dockerCmd(c, append([]string{"unpause"}, containers...)...) dockerCmd(c, append([]string{"unpause"}, containers...)...)
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
out, _, _ = runCommandWithOutput(eventsCmd)
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
if len(events) <= len(containers)*3-2 { if len(events) <= len(containers)*3-2 {
c.Fatalf("Missing expected event") c.Fatalf("Missing expected event")

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os/exec"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
@ -13,64 +12,37 @@ import (
func (s *DockerSuite) TestPortList(c *check.C) { func (s *DockerSuite) TestPortList(c *check.C) {
// one port // one port
runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "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, "port", firstID, "80") out, _ = dockerCmd(c, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) { if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "port", firstID) out, _ = dockerCmd(c, "port", firstID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{"80/tcp -> 0.0.0.0:9876"}) { if !assertPortList(c, out, []string{"80/tcp -> 0.0.0.0:9876"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) dockerCmd(c, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
// three port // three port
runCmd = exec.Command(dockerBinary, "run", "-d", out, _ = dockerCmd(c, "run", "-d",
"-p", "9876:80", "-p", "9876:80",
"-p", "9877:81", "-p", "9877:81",
"-p", "9878:82", "-p", "9878:82",
"busybox", "top") "busybox", "top")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
ID := strings.TrimSpace(out) ID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", ID, "80") out, _ = dockerCmd(c, "port", ID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) { if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "port", ID) out, _ = dockerCmd(c, "port", ID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{ if !assertPortList(c, out, []string{
"80/tcp -> 0.0.0.0:9876", "80/tcp -> 0.0.0.0:9876",
@ -78,40 +50,24 @@ func (s *DockerSuite) TestPortList(c *check.C) {
"82/tcp -> 0.0.0.0:9878"}) { "82/tcp -> 0.0.0.0:9878"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "rm", "-f", ID) dockerCmd(c, "rm", "-f", ID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
// more and one port mapped to the same container port // more and one port mapped to the same container port
runCmd = exec.Command(dockerBinary, "run", "-d", out, _ = dockerCmd(c, "run", "-d",
"-p", "9876:80", "-p", "9876:80",
"-p", "9999:80", "-p", "9999:80",
"-p", "9877:81", "-p", "9877:81",
"-p", "9878:82", "-p", "9878:82",
"busybox", "top") "busybox", "top")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
ID = strings.TrimSpace(out) ID = strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", ID, "80") out, _ = dockerCmd(c, "port", ID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{"0.0.0.0:9876", "0.0.0.0:9999"}) { if !assertPortList(c, out, []string{"0.0.0.0:9876", "0.0.0.0:9999"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "port", ID) out, _ = dockerCmd(c, "port", ID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{ if !assertPortList(c, out, []string{
"80/tcp -> 0.0.0.0:9876", "80/tcp -> 0.0.0.0:9876",
@ -120,10 +76,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
"82/tcp -> 0.0.0.0:9878"}) { "82/tcp -> 0.0.0.0:9878"}) {
c.Error("Port list is not correct\n", out) c.Error("Port list is not correct\n", out)
} }
runCmd = exec.Command(dockerBinary, "rm", "-f", ID) dockerCmd(c, "rm", "-f", ID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
} }
@ -148,9 +101,7 @@ func assertPortList(c *check.C, out string, expected []string) bool {
} }
func stopRemoveContainer(id string, c *check.C) { func stopRemoveContainer(id string, c *check.C) {
runCmd := exec.Command(dockerBinary, "rm", "-f", id) dockerCmd(c, "rm", "-f", id)
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
} }
func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) { func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
@ -159,31 +110,23 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
port2 := 443 port2 := 443
expose1 := fmt.Sprintf("--expose=%d", port1) expose1 := fmt.Sprintf("--expose=%d", port1)
expose2 := fmt.Sprintf("--expose=%d", port2) expose2 := fmt.Sprintf("--expose=%d", port2)
runCmd := exec.Command(dockerBinary, "run", "-d", expose1, expose2, "busybox", "sleep", "5") dockerCmd(c, "run", "-d", expose1, expose2, "busybox", "sleep", "5")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// Check docker ps o/p for last created container reports the unpublished ports // Check docker ps o/p for last created container reports the unpublished ports
unpPort1 := fmt.Sprintf("%d/tcp", port1) unpPort1 := fmt.Sprintf("%d/tcp", port1)
unpPort2 := fmt.Sprintf("%d/tcp", port2) unpPort2 := fmt.Sprintf("%d/tcp", port2)
runCmd = exec.Command(dockerBinary, "ps", "-n=1") out, _ := dockerCmd(c, "ps", "-n=1")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
if !strings.Contains(out, unpPort1) || !strings.Contains(out, unpPort2) { if !strings.Contains(out, unpPort1) || !strings.Contains(out, unpPort2) {
c.Errorf("Missing unpublished ports(s) (%s, %s) in docker ps output: %s", unpPort1, unpPort2, out) c.Errorf("Missing unpublished ports(s) (%s, %s) in docker ps output: %s", unpPort1, unpPort2, out)
} }
// Run the container forcing to publish the exposed ports // Run the container forcing to publish the exposed ports
runCmd = exec.Command(dockerBinary, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5") dockerCmd(c, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// Check docker ps o/p for last created container reports the exposed ports in the port bindings // Check docker ps o/p for last created container reports the exposed ports in the port bindings
expBndRegx1 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort1) expBndRegx1 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort1)
expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2) expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2)
runCmd = exec.Command(dockerBinary, "ps", "-n=1") out, _ = dockerCmd(c, "ps", "-n=1")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
if !expBndRegx1.MatchString(out) || !expBndRegx2.MatchString(out) { if !expBndRegx1.MatchString(out) || !expBndRegx2.MatchString(out) {
c.Errorf("Cannot find expected port binding ports(s) (0.0.0.0:xxxxx->%s, 0.0.0.0:xxxxx->%s) in docker ps output:\n%s", c.Errorf("Cannot find expected port binding ports(s) (0.0.0.0:xxxxx->%s, 0.0.0.0:xxxxx->%s) in docker ps output:\n%s",
unpPort1, unpPort2, out) unpPort1, unpPort2, out)
@ -193,17 +136,13 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
offset := 10000 offset := 10000
pFlag1 := fmt.Sprintf("%d:%d", offset+port1, port1) pFlag1 := fmt.Sprintf("%d:%d", offset+port1, port1)
pFlag2 := fmt.Sprintf("%d:%d", offset+port2, port2) pFlag2 := fmt.Sprintf("%d:%d", offset+port2, port2)
runCmd = exec.Command(dockerBinary, "run", "-d", "-p", pFlag1, "-p", pFlag2, expose1, expose2, "busybox", "sleep", "5") out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, expose1, expose2, "busybox", "sleep", "5")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
// Check docker ps o/p for last created container reports the specified port mappings // Check docker ps o/p for last created container reports the specified port mappings
expBnd1 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port1, unpPort1) expBnd1 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port1, unpPort1)
expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2) expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2)
runCmd = exec.Command(dockerBinary, "ps", "-n=1") out, _ = dockerCmd(c, "ps", "-n=1")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) { if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) {
c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out) c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out)
} }
@ -211,15 +150,11 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
stopRemoveContainer(id, c) stopRemoveContainer(id, c)
// Run the container with explicit port bindings and no exposed ports // Run the container with explicit port bindings and no exposed ports
runCmd = exec.Command(dockerBinary, "run", "-d", "-p", pFlag1, "-p", pFlag2, "busybox", "sleep", "5") out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, "busybox", "sleep", "5")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
id = strings.TrimSpace(out) id = strings.TrimSpace(out)
// Check docker ps o/p for last created container reports the specified port mappings // Check docker ps o/p for last created container reports the specified port mappings
runCmd = exec.Command(dockerBinary, "ps", "-n=1") out, _ = dockerCmd(c, "ps", "-n=1")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) { if !strings.Contains(out, expBnd1) || !strings.Contains(out, expBnd2) {
c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out) c.Errorf("Cannot find expected port binding(s) (%s, %s) in docker ps output: %s", expBnd1, expBnd2, out)
} }
@ -227,14 +162,10 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
stopRemoveContainer(id, c) stopRemoveContainer(id, c)
// Run the container with one unpublished exposed port and one explicit port binding // Run the container with one unpublished exposed port and one explicit port binding
runCmd = exec.Command(dockerBinary, "run", "-d", expose1, "-p", pFlag2, "busybox", "sleep", "5") dockerCmd(c, "run", "-d", expose1, "-p", pFlag2, "busybox", "sleep", "5")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// Check docker ps o/p for last created container reports the specified unpublished port and port mapping // Check docker ps o/p for last created container reports the specified unpublished port and port mapping
runCmd = exec.Command(dockerBinary, "ps", "-n=1") out, _ = dockerCmd(c, "ps", "-n=1")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
if !strings.Contains(out, unpPort1) || !strings.Contains(out, expBnd2) { if !strings.Contains(out, unpPort1) || !strings.Contains(out, expBnd2) {
c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out) c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out)
} }

View File

@ -4,63 +4,39 @@ package main
import ( import (
"net" "net"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestPortHostBinding(c *check.C) { func (s *DockerSuite) TestPortHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
"nc", "-l", "-p", "80") "nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out) firstID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", firstID, "80") out, _ = dockerCmd(c, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) { if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct") c.Error("Port list is not correct")
} }
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", "9876") "nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) dockerCmd(c, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", if _, _, err := dockerCmdWithError(c, "run", "--net=host", "busybox",
"nc", "localhost", "9876") "nc", "localhost", "9876"); err == nil {
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed") c.Error("Port is still bound after the Container is removed")
} }
} }
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) { func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox", out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
"nc", "-l", "-p", "80") "nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out) firstID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", firstID, "80") out, _ = dockerCmd(c, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
_, exposedPort, err := net.SplitHostPort(out) _, exposedPort, err := net.SplitHostPort(out)
@ -68,20 +44,13 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
c.Fatal(out, err) c.Fatal(out, err)
} }
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort)) "nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) dockerCmd(c, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", if _, _, err = dockerCmdWithError(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort)) "nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed") c.Error("Port is still bound after the Container is removed")
} }
} }

View File

@ -337,8 +337,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
runCmd := exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false") if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero1", "busybox", "false"); err == nil {
if out, _, err := runCommandWithOutput(runCmd); err == nil {
c.Fatal("Should fail.", out, err) c.Fatal("Should fail.", out, err)
} }
@ -347,8 +346,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false") if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero2", "busybox", "false"); err == nil {
if out, _, err := runCommandWithOutput(runCmd); err == nil {
c.Fatal("Should fail.", out, err) c.Fatal("Should fail.", out, err)
} }
secondNonZero, err := getIDByName("nonzero2") secondNonZero, err := getIDByName("nonzero2")
@ -385,42 +383,25 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
func (s *DockerSuite) TestPsRightTagName(c *check.C) { func (s *DockerSuite) TestPsRightTagName(c *check.C) {
tag := "asybox:shmatest" tag := "asybox:shmatest"
if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil { dockerCmd(c, "tag", "busybox", tag)
c.Fatalf("Failed to tag image: %s, out: %q", err, out)
}
var id1 string var id1 string
if out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "top").CombinedOutput(); err != nil { out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
c.Fatalf("Failed to run container: %s, out: %q", err, out) id1 = strings.TrimSpace(string(out))
} else {
id1 = strings.TrimSpace(string(out))
}
var id2 string var id2 string
if out, err := exec.Command(dockerBinary, "run", "-d", tag, "top").CombinedOutput(); err != nil { out, _ = dockerCmd(c, "run", "-d", tag, "top")
c.Fatalf("Failed to run container: %s, out: %q", err, out) id2 = strings.TrimSpace(string(out))
} else {
id2 = strings.TrimSpace(string(out))
}
var imageID string var imageID string
if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil { out, _ = dockerCmd(c, "inspect", "-f", "{{.Id}}", "busybox")
c.Fatalf("failed to get the image ID of busybox: %s, %v", out, err) imageID = strings.TrimSpace(string(out))
} else {
imageID = strings.TrimSpace(string(out))
}
var id3 string var id3 string
if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil { out, _ = dockerCmd(c, "run", "-d", imageID, "top")
c.Fatalf("Failed to run container: %s, out: %q", err, out) id3 = strings.TrimSpace(string(out))
} else {
id3 = strings.TrimSpace(string(out))
}
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput() out, _ = dockerCmd(c, "ps", "--no-trunc")
if err != nil {
c.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n") lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// skip header // skip header
lines = lines[1:] lines = lines[1:]
@ -449,16 +430,10 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
} }
func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) { func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
if out, err := exec.Command(dockerBinary, "run", "--name=first", "-d", "busybox", "top").CombinedOutput(); err != nil { dockerCmd(c, "run", "--name=first", "-d", "busybox", "top")
c.Fatalf("Output: %s, err: %s", out, err) dockerCmd(c, "run", "--name=second", "--link=first:first", "-d", "busybox", "top")
}
if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil { out, _ := dockerCmd(c, "ps", "--no-trunc")
c.Fatalf("Output: %s, err: %s", out, err)
}
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
if err != nil {
c.Fatalf("Output: %s, err: %s", out, err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n") lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// strip header // strip header
lines = lines[1:] lines = lines[1:]
@ -488,14 +463,9 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
} }
func (s *DockerSuite) TestPsWithSize(c *check.C) { func (s *DockerSuite) TestPsWithSize(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "sizetest", "busybox", "top")) dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
if err != nil {
c.Fatal(out, err) out, _ := dockerCmd(c, "ps", "--size")
}
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps", "--size"))
if err != nil {
c.Fatal(out, err)
}
if !strings.Contains(out, "virtual") { if !strings.Contains(out, "virtual") {
c.Fatalf("docker ps with --size should show virtual size of container") c.Fatalf("docker ps with --size should show virtual size of container")
} }
@ -503,28 +473,18 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) { func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
// create a container // create a container
createCmd := exec.Command(dockerBinary, "create", "busybox") out, _ := dockerCmd(c, "create", "busybox")
out, _, err := runCommandWithOutput(createCmd)
if err != nil {
c.Fatal(out, err)
}
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
shortCID := cID[:12] shortCID := cID[:12]
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps' // Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
runCmd := exec.Command(dockerBinary, "ps", "-q") out, _ = dockerCmd(c, "ps", "-q")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
if strings.Contains(out, shortCID) { if strings.Contains(out, shortCID) {
c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out) c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out)
} }
// Make sure it DOES show up as 'Created' for 'ps -a' // Make sure it DOES show up as 'Created' for 'ps -a'
runCmd = exec.Command(dockerBinary, "ps", "-a") out, _ = dockerCmd(c, "ps", "-a")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
hits := 0 hits := 0
for _, line := range strings.Split(out, "\n") { for _, line := range strings.Split(out, "\n") {
@ -542,10 +502,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
} }
// filter containers by 'create' - note, no -a needed // filter containers by 'create' - note, no -a needed
runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created") out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
containerOut := strings.TrimSpace(out) containerOut := strings.TrimSpace(out)
if !strings.HasPrefix(cID, containerOut) { if !strings.HasPrefix(cID, containerOut) {
c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out) c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os/exec"
"strings" "strings"
"github.com/go-check/check" "github.com/go-check/check"
@ -19,30 +18,19 @@ func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
// Tag and push the same image multiple times. // Tag and push the same image multiple times.
for _, repo := range repos { for _, repo := range repos {
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil { dockerCmd(c, "tag", "busybox", repo)
c.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out) dockerCmd(c, "push", repo)
}
if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
c.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
}
} }
// Clear local images store. // Clear local images store.
args := append([]string{"rmi"}, repos...) args := append([]string{"rmi"}, repos...)
if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil { dockerCmd(c, args...)
c.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
}
// Pull a single tag and verify it doesn't bring down all aliases. // Pull a single tag and verify it doesn't bring down all aliases.
pullCmd := exec.Command(dockerBinary, "pull", repos[0]) dockerCmd(c, "pull", repos[0])
if out, _, err := runCommandWithOutput(pullCmd); err != nil { dockerCmd(c, "inspect", repos[0])
c.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out)
}
if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil {
c.Fatalf("Image %v was not pulled down", repos[0])
}
for _, repo := range repos[1:] { for _, repo := range repos[1:] {
if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil { if _, _, err := dockerCmdWithError(c, "inspect", repo); err == nil {
c.Fatalf("Image %v shouldn't have been pulled down", repo) c.Fatalf("Image %v shouldn't have been pulled down", repo)
} }
} }
@ -59,8 +47,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
// pull it // pull it
expected := "The image you are pulling has been verified" expected := "The image you are pulling has been verified"
pullCmd := exec.Command(dockerBinary, "pull", verifiedName) if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || !strings.Contains(out, expected) {
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err)) c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
} }
@ -68,8 +55,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
} }
// pull it again // pull it again
pullCmd = exec.Command(dockerBinary, "pull", verifiedName) if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || strings.Contains(out, expected) {
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err)) c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
} }
@ -82,10 +68,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) { func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
testRequires(c, Network) testRequires(c, Network)
pullCmd := exec.Command(dockerBinary, "pull", "hello-world") dockerCmd(c, "pull", "hello-world")
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
c.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
}
} }
// pulling a non-existing image from the central registry should return a non-zero exit code // pulling a non-existing image from the central registry should return a non-zero exit code
@ -93,8 +76,7 @@ func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
testRequires(c, Network) testRequires(c, Network)
name := "sadfsadfasdf" name := "sadfsadfasdf"
pullCmd := exec.Command(dockerBinary, "pull", name) out, _, err := dockerCmdWithError(c, "pull", name)
out, _, err := runCommandWithOutput(pullCmd)
if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) { if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out) c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
@ -114,19 +96,15 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
"index.docker.io/library/hello-world", "index.docker.io/library/hello-world",
} }
for _, name := range names { for _, name := range names {
pullCmd := exec.Command(dockerBinary, "pull", name) out, exitCode, err := dockerCmdWithError(c, "pull", name)
out, exitCode, err := runCommandWithOutput(pullCmd)
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err) c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
continue continue
} }
// ensure we don't have multiple image names. // ensure we don't have multiple image names.
imagesCmd := exec.Command(dockerBinary, "images") out, _ = dockerCmd(c, "images")
out, _, err = runCommandWithOutput(imagesCmd) if strings.Contains(out, name) {
if err != nil {
c.Errorf("listing images failed with errors: %v", err)
} else if strings.Contains(out, name) {
c.Errorf("images should not have listed '%s'", name) c.Errorf("images should not have listed '%s'", name)
} }
} }
@ -135,8 +113,7 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) { func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
testRequires(c, Network) testRequires(c, Network)
pullCmd := exec.Command(dockerBinary, "pull", "scratch") out, exitCode, err := dockerCmdWithError(c, "pull", "scratch")
out, exitCode, err := runCommandWithOutput(pullCmd)
if err == nil { if err == nil {
c.Fatal("expected pull of scratch to fail, but it didn't") c.Fatal("expected pull of scratch to fail, but it didn't")
} }
@ -153,38 +130,24 @@ func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
// pulling an image with --all-tags=true // pulling an image with --all-tags=true
func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) { func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) {
//testRequires(c, Network) testRequires(c, Network)
pullCmd := exec.Command(dockerBinary, "pull", "busybox")
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
c.Fatalf("pulling the busybox image from the registry has failed: %s, %v", out, err)
}
ImageCmd := exec.Command(dockerBinary, "images", "busybox") dockerCmd(c, "pull", "busybox")
outImageCmd, _, err := runCommandWithOutput(ImageCmd)
c.Assert(err, check.IsNil) outImageCmd, _ := dockerCmd(c, "images", "busybox")
pullAllTagCmd := exec.Command(dockerBinary, "pull", "--all-tags=true", "busybox") dockerCmd(c, "pull", "--all-tags=true", "busybox")
if out, _, err := runCommandWithOutput(pullAllTagCmd); err != nil {
c.Fatalf("pulling the busybox image with all tags from the registry has failed: %s, %v", out, err)
}
ImageCmd1 := exec.Command(dockerBinary, "images", "busybox") outImageAllTagCmd, _ := dockerCmd(c, "images", "busybox")
outImageAllTagCmd, _, err := runCommandWithOutput(ImageCmd1)
c.Assert(err, check.IsNil)
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") { if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
c.Fatalf("Pulling with all tags should get more images") c.Fatalf("Pulling with all tags should get more images")
} }
pullAllTagCmd = exec.Command(dockerBinary, "pull", "-a", "busybox") // FIXME has probably no effect (tags already pushed)
if out, _, err := runCommandWithOutput(pullAllTagCmd); err != nil { dockerCmd(c, "pull", "-a", "busybox")
c.Fatalf("pulling the busybox image with all tags from the registry has failed: %s, %v", out, err)
}
ImageCmd2 := exec.Command(dockerBinary, "images", "busybox") outImageAllTagCmd, _ = dockerCmd(c, "images", "busybox")
outImageAllTagCmd, _, err = runCommandWithOutput(ImageCmd2)
c.Assert(err, check.IsNil)
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") { if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
c.Fatalf("Pulling with all tags should get more images") c.Fatalf("Pulling with all tags should get more images")

View File

@ -16,21 +16,14 @@ import (
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) { func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image to upload it to the private registry // tag the image to upload it to the private registry
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName) dockerCmd(c, "tag", "busybox", repoName)
if out, _, err := runCommandWithOutput(tagCmd); err != nil { // push the image to the registry
c.Fatalf("image tagging failed: %s, %v", out, err) dockerCmd(c, "push", repoName)
}
pushCmd := exec.Command(dockerBinary, "push", repoName)
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
}
} }
// pushing an image without a prefix should throw an error // pushing an image without a prefix should throw an error
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) { func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
pushCmd := exec.Command(dockerBinary, "push", "busybox") if out, _, err := dockerCmdWithError(c, "push", "busybox"); err == nil {
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out) c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
} }
} }
@ -39,8 +32,7 @@ func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
expected := "Repository does not exist" expected := "Repository does not exist"
pushCmd := exec.Command(dockerBinary, "push", repoName) if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
c.Fatalf("pushing the image to the private registry should have failed: output %q", out) c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
} else if !strings.Contains(out, expected) { } else if !strings.Contains(out, expected) {
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out) c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
@ -51,8 +43,8 @@ func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
expected := "does not exist" expected := "does not exist"
pushCmd := exec.Command(dockerBinary, "push", repoName)
if out, _, err := runCommandWithOutput(pushCmd); err == nil { if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
c.Fatalf("pushing the image to the private registry should have failed: output %q", out) c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
} else if !strings.Contains(out, expected) { } else if !strings.Contains(out, expected) {
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out) c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
@ -64,27 +56,17 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL) repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL) repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
// tag the image and upload it to the private registry // tag the image and upload it to the private registry
tagCmd1 := exec.Command(dockerBinary, "tag", "busybox", repoTag1) dockerCmd(c, "tag", "busybox", repoTag1)
if out, _, err := runCommandWithOutput(tagCmd1); err != nil {
c.Fatalf("image tagging failed: %s, %v", out, err)
}
tagCmd2 := exec.Command(dockerBinary, "tag", "busybox", repoTag2)
if out, _, err := runCommandWithOutput(tagCmd2); err != nil {
c.Fatalf("image tagging failed: %s, %v", out, err)
}
pushCmd := exec.Command(dockerBinary, "push", repoName) dockerCmd(c, "tag", "busybox", repoTag2)
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err) dockerCmd(c, "push", repoName)
}
} }
func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) { func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image and upload it to the private registry // tag the image and upload it to the private registry
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil { dockerCmd(c, "tag", "busybox", repoName)
c.Fatalf("image tagging failed: %s, %v", out, err)
}
pushCmd := exec.Command(dockerBinary, "push", repoName) pushCmd := exec.Command(dockerBinary, "push", repoName)
if err := pushCmd.Start(); err != nil { if err := pushCmd.Start(); err != nil {
@ -96,7 +78,7 @@ func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
if err := pushCmd.Process.Kill(); err != nil { if err := pushCmd.Process.Kill(); err != nil {
c.Fatalf("Failed to kill push process: %v", err) c.Fatalf("Failed to kill push process: %v", err)
} }
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repoName)); err == nil { if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
str := string(out) str := string(out)
if !strings.Contains(str, "already in progress") { if !strings.Contains(str, "already in progress") {
c.Fatalf("Push should be continued on daemon side, but seems ok: %v, %s", err, out) c.Fatalf("Push should be continued on daemon side, but seems ok: %v, %s", err, out)
@ -133,8 +115,7 @@ func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
} }
// Now verify we can push it // Now verify we can push it
pushCmd := exec.Command(dockerBinary, "push", repoName) if out, _, err := dockerCmdWithError(c, "push", repoName); err != nil {
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err) c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
} }
} }