Merge pull request #14624 from vdemeester/14603-dockerCmd-integration-cli-1

Integration test refactors to use dockerCmd
This commit is contained in:
Brian Goff 2015-07-15 14:03:58 -04:00
commit e98a881570
24 changed files with 330 additions and 1054 deletions

View file

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

View file

@ -8,7 +8,6 @@ import (
"net/http"
"net/http/httputil"
"os"
"os/exec"
"strconv"
"strings"
"time"
@ -26,11 +25,7 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
}
name := "getall"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "--name", name, "busybox", "true")
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
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
func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "busybox", "true")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "busybox", "true")
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil)
@ -94,9 +87,7 @@ type containerPs struct {
func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
name := "pstest"
port := 80
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "top")
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil)
@ -126,11 +117,7 @@ func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
name := "exportcontainer"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
c.Assert(err, check.IsNil)
@ -158,11 +145,7 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
name := "changescontainer"
runCmd := exec.Command(dockerBinary, "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)
}
dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
c.Assert(err, check.IsNil)
@ -248,9 +231,7 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
volName := "voltst"
volPath := "/tmp"
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", volName, "-v", volPath, "busybox")); err != nil {
c.Fatal(out, err)
}
dockerCmd(c, "run", "-d", "--name", volName, "-v", volPath, "busybox")
name := "TestContainerApiStartDupVolumeBinds"
config := map[string]interface{}{
@ -285,13 +266,10 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
func (s *DockerSuite) TestGetContainerStats(c *check.C) {
var (
name = "statscontainer"
runCmd = exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
name = "statscontainer"
)
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
type b struct {
status int
body []byte
@ -305,9 +283,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
// allow some time to stream the stats from the container
time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
c.Fatal(err)
}
dockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail
// if the stream was not disconnected.
@ -353,7 +329,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
c.Assert(err, check.IsNil)
// 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"))
_, err = buf.ReadTimeout(b, 2*time.Second)
c.Assert(err, check.IsNil)
@ -368,9 +344,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
// stream false always return one stat)
func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
name := "statscontainer"
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
type b struct {
status int
@ -385,9 +359,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
// allow some time to stream the stats from the container
time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
c.Fatal(err)
}
dockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail
// if the stream was not disconnected.
@ -408,9 +380,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
name := "statscontainer"
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
type b struct {
status int
@ -425,9 +395,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
// allow some time to stream the stats from the container
time.Sleep(4 * time.Second)
if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
c.Fatal(err)
}
dockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail
// if the stream was not disconnected.
@ -449,13 +417,9 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
// TODO: this test does nothing because we are c.Assert'ing in goroutine
var (
name = "statscontainer"
runCmd = exec.Command(dockerBinary, "create", "--name", name, "busybox", "top")
name = "statscontainer"
)
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "create", "--name", name, "busybox", "top")
go func() {
// 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
func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=one", "busybox"))
if err != nil {
c.Fatal(err, out)
}
dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
fooDir, err := inspectFieldMap("one", "Volumes", "/foo")
if err != nil {
c.Fatal(err)
}
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=two", "busybox"))
if err != nil {
c.Fatal(err, out)
}
dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
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) {
defer unpauseAllContainers()
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "30")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("failed to create a container: %s, %v", out, err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
ContainerID := strings.TrimSpace(out)
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) {
out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "top").CombinedOutput()
if err != nil {
c.Fatal(err, out)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top")
id := strings.TrimSpace(string(out))
if err := waitRun(id); err != nil {
c.Fatal(err)
@ -851,10 +801,7 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
cName := "testapicommit"
out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
if err != nil {
c.Fatal(err, out)
}
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
name := "TestContainerApiCommit"
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)
}
// sanity check, make sure the image is what we think it is
out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
if err != nil {
c.Fatalf("error checking committed image: %v - %q", err, string(out))
}
dockerCmd(c, "run", img.Id, "ls", "/test")
}
func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
cName := "testapicommitwithconfig"
out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
if err != nil {
c.Fatal(err, out)
}
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
config := map[string]interface{}{
"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
out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
if err != nil {
c.Fatalf("error checking committed image: %v - %q", err, string(out))
}
dockerCmd(c, "run", img.Id, "ls", "/test")
}
func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
@ -952,11 +890,8 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
c.Fatal(err)
}
out, err := exec.Command(dockerBinary, "start", "-a", container.Id).CombinedOutput()
if err != nil {
c.Fatal(string(out), err)
}
if strings.TrimSpace(string(out)) != "/test" {
out, _ := dockerCmd(c, "start", "-a", container.Id)
if strings.TrimSpace(out) != "/test" {
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) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "busybox"))
if err != nil {
c.Fatal(err, out)
}
out, _ := dockerCmd(c, "create", "busybox")
containerID := strings.TrimSpace(out)
@ -1265,9 +1197,7 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
}
func (s *DockerSuite) TestContainerApiRename(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
containerID := strings.TrimSpace(out)
newName := "TestContainerApiRenameNew"
@ -1284,11 +1214,7 @@ func (s *DockerSuite) TestContainerApiRename(c *check.C) {
func (s *DockerSuite) TestContainerApiKill(c *check.C) {
name := "test-api-kill"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
c.Assert(err, check.IsNil)
@ -1305,11 +1231,7 @@ func (s *DockerSuite) TestContainerApiKill(c *check.C) {
func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
name := "test-api-restart"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
c.Assert(err, check.IsNil)
@ -1322,11 +1244,7 @@ func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
func (s *DockerSuite) TestContainerApiRestartNotimeoutParam(c *check.C) {
name := "test-api-restart-no-timeout-param"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
out, _ := dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
@ -1364,11 +1282,7 @@ func (s *DockerSuite) TestContainerApiStart(c *check.C) {
func (s *DockerSuite) TestContainerApiStop(c *check.C) {
name := "test-api-stop"
runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "-di", "--name", name, "busybox", "top")
status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=1", nil)
c.Assert(err, check.IsNil)
@ -1386,11 +1300,7 @@ func (s *DockerSuite) TestContainerApiStop(c *check.C) {
func (s *DockerSuite) TestContainerApiWait(c *check.C) {
name := "test-api-wait"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sleep", "5")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
dockerCmd(c, "run", "--name", name, "busybox", "sleep", "5")
status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
c.Assert(err, check.IsNil)
@ -1412,9 +1322,7 @@ func (s *DockerSuite) TestContainerApiWait(c *check.C) {
func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
name := "test-container-api-copy"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
postData := types.CopyConfig{
Resource: "/test.txt",
@ -1443,9 +1351,7 @@ func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
name := "test-container-api-copy-resource-empty"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
postData := types.CopyConfig{
Resource: "",
@ -1459,9 +1365,7 @@ func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
name := "test-container-api-copy-resource-not-found"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox")
_, err := runCommand(runCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "run", "--name", name, "busybox")
postData := types.CopyConfig{
Resource: "/notexist",
@ -1484,16 +1388,12 @@ func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
}
func (s *DockerSuite) TestContainerApiDelete(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
stopCmd := exec.Command(dockerBinary, "stop", id)
_, err = runCommand(stopCmd)
c.Assert(err, check.IsNil)
dockerCmd(c, "stop", id)
status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
c.Assert(err, check.IsNil)
@ -1508,9 +1408,7 @@ func (s *DockerSuite) TestContainerApiDeleteNotExist(c *check.C) {
}
func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
@ -1521,16 +1419,12 @@ func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
}
func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "tlink1", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
runCmd = exec.Command(dockerBinary, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
id2 := strings.TrimSpace(out)
c.Assert(waitRun(id2), check.IsNil)
@ -1555,9 +1449,7 @@ func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
}
func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
@ -1570,9 +1462,7 @@ func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
testRequires(c, SameHostDaemon)
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/testvolume", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "-v", "/testvolume", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
@ -1644,9 +1534,7 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
}
func (s *DockerSuite) TestPostContainerStop(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), check.IsNil)

View file

@ -2,18 +2,13 @@ package main
import (
"net/http"
"os/exec"
"strings"
"github.com/go-check/check"
)
func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"

View file

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

View file

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

View file

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

View file

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

View file

@ -2,18 +2,13 @@ package main
import (
"net/http"
"os/exec"
"strings"
"github.com/go-check/check"
)
func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)
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) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)
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) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out)
// make sure the exited container is not running
runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatalf(out, err)
}
dockerCmd(c, "wait", cleanedContainerID)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
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")
}
cmd := exec.Command(dockerBinary, "kill", "attacher")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "kill", "attacher")
select {
case <-endDone:
@ -90,11 +87,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
}
func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatalf("failed to start container: %v (%v)", out, err)
}
out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
id := strings.TrimSpace(out)
if err := waitRun(id); err != nil {

View file

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

View file

@ -76,16 +76,7 @@ func (s *DockerSuite) TestBuildShCmdJSONEntrypoint(c *check.C) {
c.Fatal(err)
}
out, _, err := runCommandWithOutput(
exec.Command(
dockerBinary,
"run",
"--rm",
name))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "--rm", name)
if strings.TrimSpace(out) != "/bin/sh -c echo test" {
c.Fatal("CMD did not contain /bin/sh -c")
@ -420,12 +411,12 @@ func (s *DockerSuite) TestBuildEnvEscapes(c *check.C) {
`,
true)
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "-t", name)
if 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)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-e", "TEST=bar", "-t", name))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "-e", "TEST=bar", "-t", name)
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))
@ -462,21 +449,13 @@ func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) {
func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenmaintainerinsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ := dockerCmd(c, "create", "busybox", "true")
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 {
c.Fatal(err)
}
_, err = buildImage(name,
_, err := buildImage(name,
`FROM onbuild`,
true)
if err != nil {
@ -492,21 +471,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenMaintainerInSourceImage(c *check.
func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenfrominsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ := dockerCmd(c, "create", "busybox", "true")
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 {
c.Fatal(err)
}
_, err = buildImage(name,
_, err := buildImage(name,
`FROM onbuild`,
true)
if err != nil {
@ -522,21 +493,13 @@ func (s *DockerSuite) TestBuildOnBuildForbiddenFromInSourceImage(c *check.C) {
func (s *DockerSuite) TestBuildOnBuildForbiddenChainedInSourceImage(c *check.C) {
name := "testbuildonbuildforbiddenchainedinsourceimage"
createCmd := exec.Command(dockerBinary, "create", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(createCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ := dockerCmd(c, "create", "busybox", "true")
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 {
c.Fatal(err)
}
_, err = buildImage(name,
_, err := buildImage(name,
`FROM onbuild`,
true)
if err != nil {
@ -570,10 +533,7 @@ ONBUILD RUN ["true"]`,
c.Fatal(err)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "-t", name2)
if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
c.Fatal("did not get echo output from onbuild", out)
@ -600,10 +560,7 @@ ONBUILD ENTRYPOINT ["echo"]`,
c.Fatal(err)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "-t", name2)
if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) {
c.Fatal("got malformed output from onbuild", out)
@ -1827,11 +1784,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) {
}
defer ctx.Close()
buildCmd := exec.Command(dockerBinary, "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)
}
dockerCmdInDir(c, ctx.Dir, "build", "-t", name, "--force-rm", ".")
containerCountAfter, err := getContainerCount()
if err != nil {
@ -3100,11 +3053,7 @@ func (s *DockerSuite) TestBuildWithVolumeOwnership(c *check.C) {
c.Fatal(err)
}
cmd := exec.Command(dockerBinary, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(out, err)
}
out, _ := dockerCmd(c, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
if expected := "drw-------"; !strings.Contains(out, expected) {
c.Fatalf("expected %s received %s", expected, out)
@ -3349,6 +3298,9 @@ func (s *DockerSuite) TestBuildEscapeWhitespace(c *check.C) {
IO <io@\
docker.com>"
`, true)
if err != nil {
c.Fatal(err)
}
res, err := inspectField(name, "Author")
@ -3371,11 +3323,12 @@ func (s *DockerSuite) TestBuildVerifyIntString(c *check.C) {
MAINTAINER 123
`, true)
out, rc, err := runCommandWithOutput(exec.Command(dockerBinary, "inspect", name))
if rc != 0 || err != nil {
c.Fatalf("Unexpected error from inspect: rc: %v err: %v", rc, err)
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "inspect", name)
if !strings.Contains(out, "\"123\"") {
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 {
c.Fatalf("failed to close tar archive: %v", err)
}
xzCompressCmd := exec.Command("xz", "-k", "test.tar")
xzCompressCmd.Dir = tmpDir
out, _, err := runCommandWithOutput(xzCompressCmd)
@ -4389,9 +4343,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
c.Fatal(err)
}
status, _ := runCommand(exec.Command(dockerBinary, "run", "parent"))
if status != 130 {
if _, status, _ := dockerCmdWithError(c, "run", "parent"); status != 130 {
c.Fatalf("expected exit code 130 but received %d", status)
}
@ -4402,9 +4354,7 @@ func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) {
c.Fatal(err)
}
status, _ = runCommand(exec.Command(dockerBinary, "run", "child"))
if status != 5 {
if _, status, _ := dockerCmdWithError(c, "run", "child"); status != 5 {
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)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name2))
if err != nil {
c.Fatal(err, out)
}
out, _ := dockerCmd(c, "run", "-t", name2)
expected = "quux"
@ -4457,12 +4404,7 @@ func (s *DockerSuite) TestBuildRunShEntrypoint(c *check.C) {
c.Fatal(err)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
if err != nil {
c.Fatal(err, out)
}
dockerCmd(c, "run", "--rm", name)
}
func (s *DockerSuite) TestBuildExoticShellInterpolation(c *check.C) {
@ -4501,13 +4443,14 @@ func (s *DockerSuite) TestBuildVerifySingleQuoteFails(c *check.C) {
// it should barf on it.
name := "testbuildsinglequotefails"
_, err := buildImage(name,
if _, err := buildImage(name,
`FROM busybox
CMD [ '/bin/sh', '-c', 'echo hi' ]`,
true)
_, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
true); err != nil {
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")
}
@ -4771,10 +4714,7 @@ CMD cat /foo/file`,
c.Fatal(err)
}
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
if err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "run", "--rm", name)
if out != expected {
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, "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 {
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.
// 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 {
c.Fatalf("Expected error. Out: %s", out)
}
@ -5257,9 +5197,7 @@ func (s *DockerSuite) TestBuildNotVerbose(c *check.C) {
defer ctx.Close()
// First do it w/verbose - baseline
buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".")
buildCmd.Dir = ctx.Dir
out, _, err := runCommandWithOutput(buildCmd)
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", "verbose", ".")
if err != nil {
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
buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".")
buildCmd.Dir = ctx.Dir
out, _, err = runCommandWithOutput(buildCmd)
out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-q", "-t", "verbose", ".")
if err != nil {
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()
buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", name, ".")
buildCmd.Dir = ctx.Dir
out, _, err := runCommandWithOutput(buildCmd)
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", name, ".")
if err != nil {
c.Fatalf("failed to build the image: %s, %v", out, err)
}

View file

@ -4,7 +4,6 @@ package main
import (
"encoding/json"
"os/exec"
"strings"
"github.com/go-check/check"
@ -22,14 +21,9 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
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, ".")
cmd.Dir = ctx.Dir
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, ".")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err, out)
}
out, _ = dockerCmd(c, "ps", "-lq")
out, _ := dockerCmd(c, "ps", "-lq")
cID := strings.TrimSpace(out)
@ -57,7 +51,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
}
// 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")
if err != nil {

View file

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

View file

@ -1,91 +1,51 @@
package main
import (
"os/exec"
"strings"
"github.com/go-check/check"
)
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %s, %v", out, err)
}
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
cleanedContainerID := strings.TrimSpace(out)
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
}
dockerCmd(c, "wait", cleanedContainerID)
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
out, _ = dockerCmd(c, "commit", cleanedContainerID)
cleanedImageID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
c.Fatalf("failed to inspect image: %s, %v", out, err)
}
dockerCmd(c, "inspect", cleanedImageID)
}
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %s, %v", out, err)
}
out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
cleanedContainerID := strings.TrimSpace(out)
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
}
dockerCmd(c, "wait", cleanedContainerID)
commitCmd := exec.Command(dockerBinary, "commit", "-p=false", cleanedContainerID)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
out, _ = dockerCmd(c, "commit", "-p=false", cleanedContainerID)
cleanedImageID := strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
c.Fatalf("failed to inspect image: %s, %v", out, err)
}
dockerCmd(c, "inspect", cleanedImageID)
}
//test commit a paused container should not unpause it after commit
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
defer unpauseAllContainers()
cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox")
out, _, _, err := runCommandWithStdoutStderr(cmd)
if err != nil {
c.Fatalf("failed to run container: %v, output: %q", err, out)
}
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
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)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
c.Fatalf("failed to commit container to image: %s, %v", out, err)
}
dockerCmd(c, "pause", cleanedContainerID)
out, err = inspectField(cleanedContainerID, "State.Paused")
out, _ = dockerCmd(c, "commit", cleanedContainerID)
out, err := inspectField(cleanedContainerID, "State.Paused")
c.Assert(err, check.IsNil)
if !strings.Contains(out, "true") {
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) {
cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
cmd = exec.Command(dockerBinary, "commit", "commiter")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
imageID, _ := dockerCmd(c, "commit", "commiter")
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" {
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) {
cmd := exec.Command(dockerBinary, "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)
}
firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
chunks := strings.Split(strings.TrimSpace(firstOuput), " ")
chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
inode := chunks[0]
found := false
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:])
}
cmd = exec.Command(dockerBinary, "commit", "hardlinks", "hardlinks")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(imageID, err)
}
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
secondOuput, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
chunks = strings.Split(strings.TrimSpace(secondOuput), " ")
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0]
found = false
for _, chunk := range chunks[1:] {
@ -169,56 +106,31 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
func (s *DockerSuite) TestCommitTTY(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err)
}
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "run", "ttytest", "/bin/ls")
}
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
cmd := exec.Command(dockerBinary, "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)
}
dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "run", "bindtest", "true")
}
func (s *DockerSuite) TestCommitChange(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "--name", "test", "busybox", "true")
if _, err := runCommand(cmd); err != nil {
c.Fatal(err)
}
dockerCmd(c, "run", "--name", "test", "busybox", "true")
cmd = exec.Command(dockerBinary, "commit",
imageID, _ := dockerCmd(c, "commit",
"--change", "EXPOSE 8080",
"--change", "ENV DEBUG true",
"--change", "ENV test 1",
@ -231,11 +143,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
"--change", "VOLUME /var/lib/docker",
"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
"test", "test-commit")
imageId, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(imageId, err)
}
imageId = strings.Trim(imageId, "\r\n")
imageID = strings.Trim(imageID, "\r\n")
expected := map[string]string{
"Config.ExposedPorts": "map[8080/tcp:{}]",
@ -250,7 +158,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
}
for conf, value := range expected {
res, err := inspectField(imageId, conf)
res, err := inspectField(imageID, conf)
c.Assert(err, check.IsNil)
if 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")
// First make sure pointing to empty dir doesn't generate an error
cmd := exec.Command(dockerBinary, "--config", cDir, "ps")
out, rc, err := runCommandWithOutput(cmd)
out, rc := dockerCmd(c, "--config", cDir, "ps")
if rc != 0 || err != nil {
c.Fatalf("ps1 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)
if rc != 0 {
c.Fatalf("ps1 didn't work:\nrc:%d\nout%s", rc, out)
}
// Test with env var too
cmd = exec.Command(dockerBinary, "ps")
cmd := exec.Command(dockerBinary, "ps")
cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
out, rc, err = runCommandWithOutput(cmd)
out, rc, err := runCommandWithOutput(cmd)
if rc != 0 || err != nil {
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)
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
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)
}
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
@ -184,7 +184,7 @@ func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
path := cpFullPath
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
@ -243,7 +243,7 @@ func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
path := path.Join("/", "container_path")
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
@ -302,7 +302,7 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
path := path.Join("/", "container_path", cpTestName)
_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
@ -380,7 +380,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
}
// 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")
actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
@ -390,7 +390,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
}
// 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")
actual, err = ioutil.ReadFile(outDir + "/hosts")
@ -400,7 +400,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
}
// 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")
actual, err = ioutil.ReadFile(outDir + "/hostname")
@ -442,7 +442,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
}
// Copy actual volume path
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
stat, err := os.Stat(outDir + "/foo")
if err != nil {
@ -460,7 +460,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
}
// 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")
if err != nil {
@ -471,7 +471,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
}
// Copy Bind-mounted dir
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
stat, err = os.Stat(outDir + "/baz")
if err != nil {
c.Fatal(err)
@ -481,7 +481,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
}
// 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")
if err != nil {
c.Fatal(err)
@ -495,7 +495,7 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
}
// Copy bind-mounted file
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
fb, err = ioutil.ReadFile(outDir + "/test")
if err != nil {
c.Fatal(err)
@ -536,7 +536,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
if err := os.Chdir(tmpdir); err != nil {
c.Fatal(err)
}
_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
content, err := ioutil.ReadFile("./test")
if string(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)
}
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")
if string(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) {
expectedMsg := "hello"
out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", expectedMsg).CombinedOutput()
if err != nil {
c.Fatal(string(out), err)
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
id := strings.TrimSpace(string(out))
if out, err = exec.Command(dockerBinary, "wait", id).CombinedOutput(); err != nil {
c.Fatalf("unable to wait for container: %s", err)
}
out, _ = dockerCmd(c, "wait", id)
status := strings.TrimSpace(string(out))
status := strings.TrimSpace(out)
if status != "0" {
c.Fatalf("container exited with status %s", status)
}
@ -619,33 +614,23 @@ func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
}
defer os.RemoveAll(tmpDir)
if _, err = exec.Command(dockerBinary, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir).CombinedOutput(); err != nil {
c.Fatalf("unable to copy from busybox container: %s", err)
}
dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir)
if out, err = exec.Command(dockerBinary, "start", "-a", id).CombinedOutput(); err != nil {
c.Fatalf("unable to start busybox container after copy: %s - %s", err, out)
}
out, _ = dockerCmd(c, "start", "-a", id)
msg := strings.TrimSpace(string(out))
msg := strings.TrimSpace(out)
if msg != expectedMsg {
c.Fatalf("expected %q but got %q", expectedMsg, msg)
}
}
func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
out, err := exec.Command(dockerBinary, "create", "--name", "test_cp", "-v", "/test", "busybox").CombinedOutput()
if err != nil {
c.Fatalf(string(out), err)
}
dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
tmpDir, err := ioutil.TempDir("", "test")
if err != nil {
c.Fatalf("unable to make temporary directory: %s", err)
}
defer os.RemoveAll(tmpDir)
out, err = exec.Command(dockerBinary, "cp", "test_cp:/bin/sh", tmpDir).CombinedOutput()
if err != nil {
c.Fatalf(string(out), err)
}
dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
}

View file

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

View file

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

View file

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

View file

@ -4,63 +4,39 @@ package main
import (
"net"
"os/exec"
"strings"
"github.com/go-check/check"
)
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")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ = dockerCmd(c, "port", firstID, "80")
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct")
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
dockerCmd(c, "rm", "-f", firstID)
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err == nil {
if _, _, err := dockerCmdWithError(c, "run", "--net=host", "busybox",
"nc", "localhost", "9876"); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}
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")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ = dockerCmd(c, "port", firstID, "80")
_, exposedPort, err := net.SplitHostPort(out)
@ -68,20 +44,13 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
dockerCmd(c, "rm", "-f", firstID)
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err == nil {
if _, _, err = dockerCmdWithError(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
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)
}
runCmd := exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
if out, _, err := runCommandWithOutput(runCmd); err == nil {
if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero1", "busybox", "false"); err == nil {
c.Fatal("Should fail.", out, err)
}
@ -347,8 +346,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
c.Fatal(err)
}
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
if out, _, err := runCommandWithOutput(runCmd); err == nil {
if out, _, err := dockerCmdWithError(c, "run", "--name", "nonzero2", "busybox", "false"); err == nil {
c.Fatal("Should fail.", out, err)
}
secondNonZero, err := getIDByName("nonzero2")
@ -385,42 +383,25 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
tag := "asybox:shmatest"
if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil {
c.Fatalf("Failed to tag image: %s, out: %q", err, out)
}
dockerCmd(c, "tag", "busybox", tag)
var id1 string
if out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "top").CombinedOutput(); err != nil {
c.Fatalf("Failed to run container: %s, out: %q", err, out)
} else {
id1 = strings.TrimSpace(string(out))
}
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id1 = strings.TrimSpace(string(out))
var id2 string
if out, err := exec.Command(dockerBinary, "run", "-d", tag, "top").CombinedOutput(); err != nil {
c.Fatalf("Failed to run container: %s, out: %q", err, out)
} else {
id2 = strings.TrimSpace(string(out))
}
out, _ = dockerCmd(c, "run", "-d", tag, "top")
id2 = strings.TrimSpace(string(out))
var imageID string
if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil {
c.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
} else {
imageID = strings.TrimSpace(string(out))
}
out, _ = dockerCmd(c, "inspect", "-f", "{{.Id}}", "busybox")
imageID = strings.TrimSpace(string(out))
var id3 string
if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil {
c.Fatalf("Failed to run container: %s, out: %q", err, out)
} else {
id3 = strings.TrimSpace(string(out))
}
out, _ = dockerCmd(c, "run", "-d", imageID, "top")
id3 = strings.TrimSpace(string(out))
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
if err != nil {
c.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
}
out, _ = dockerCmd(c, "ps", "--no-trunc")
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// skip header
lines = lines[1:]
@ -449,16 +430,10 @@ func (s *DockerSuite) TestPsRightTagName(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 {
c.Fatalf("Output: %s, err: %s", out, err)
}
if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil {
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)
}
dockerCmd(c, "run", "--name=first", "-d", "busybox", "top")
dockerCmd(c, "run", "--name=second", "--link=first:first", "-d", "busybox", "top")
out, _ := dockerCmd(c, "ps", "--no-trunc")
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// strip header
lines = lines[1:]
@ -488,14 +463,9 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
}
func (s *DockerSuite) TestPsWithSize(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "sizetest", "busybox", "top"))
if err != nil {
c.Fatal(out, err)
}
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps", "--size"))
if err != nil {
c.Fatal(out, err)
}
dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
out, _ := dockerCmd(c, "ps", "--size")
if !strings.Contains(out, "virtual") {
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) {
// create a container
createCmd := exec.Command(dockerBinary, "create", "busybox")
out, _, err := runCommandWithOutput(createCmd)
if err != nil {
c.Fatal(out, err)
}
out, _ := dockerCmd(c, "create", "busybox")
cID := strings.TrimSpace(out)
shortCID := cID[:12]
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
runCmd := exec.Command(dockerBinary, "ps", "-q")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
out, _ = dockerCmd(c, "ps", "-q")
if strings.Contains(out, shortCID) {
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'
runCmd = exec.Command(dockerBinary, "ps", "-a")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
out, _ = dockerCmd(c, "ps", "-a")
hits := 0
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
runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
containerOut := strings.TrimSpace(out)
if !strings.HasPrefix(cID, containerOut) {
c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)

View file

@ -2,7 +2,6 @@ package main
import (
"fmt"
"os/exec"
"strings"
"github.com/go-check/check"
@ -19,30 +18,19 @@ func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
// Tag and push the same image multiple times.
for _, repo := range repos {
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
c.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
}
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))
}
dockerCmd(c, "tag", "busybox", repo)
dockerCmd(c, "push", repo)
}
// Clear local images store.
args := append([]string{"rmi"}, repos...)
if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil {
c.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
}
dockerCmd(c, args...)
// Pull a single tag and verify it doesn't bring down all aliases.
pullCmd := exec.Command(dockerBinary, "pull", repos[0])
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
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])
}
dockerCmd(c, "pull", repos[0])
dockerCmd(c, "inspect", repos[0])
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)
}
}
@ -59,8 +47,7 @@ func (s *DockerSuite) TestPullVerified(c *check.C) {
// pull it
expected := "The image you are pulling has been verified"
pullCmd := exec.Command(dockerBinary, "pull", verifiedName)
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || !strings.Contains(out, expected) {
if err != nil || exitCode != 0 {
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
pullCmd = exec.Command(dockerBinary, "pull", verifiedName)
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || strings.Contains(out, expected) {
if err != nil || exitCode != 0 {
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) {
testRequires(c, Network)
pullCmd := exec.Command(dockerBinary, "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)
}
dockerCmd(c, "pull", "hello-world")
}
// 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)
name := "sadfsadfasdf"
pullCmd := exec.Command(dockerBinary, "pull", name)
out, _, err := runCommandWithOutput(pullCmd)
out, _, err := dockerCmdWithError(c, "pull", 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)
@ -114,19 +96,15 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
"index.docker.io/library/hello-world",
}
for _, name := range names {
pullCmd := exec.Command(dockerBinary, "pull", name)
out, exitCode, err := runCommandWithOutput(pullCmd)
out, exitCode, err := dockerCmdWithError(c, "pull", name)
if err != nil || exitCode != 0 {
c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
continue
}
// ensure we don't have multiple image names.
imagesCmd := exec.Command(dockerBinary, "images")
out, _, err = runCommandWithOutput(imagesCmd)
if err != nil {
c.Errorf("listing images failed with errors: %v", err)
} else if strings.Contains(out, name) {
out, _ = dockerCmd(c, "images")
if strings.Contains(out, 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) {
testRequires(c, Network)
pullCmd := exec.Command(dockerBinary, "pull", "scratch")
out, exitCode, err := runCommandWithOutput(pullCmd)
out, exitCode, err := dockerCmdWithError(c, "pull", "scratch")
if err == nil {
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
func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) {
//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)
}
testRequires(c, Network)
ImageCmd := exec.Command(dockerBinary, "images", "busybox")
outImageCmd, _, err := runCommandWithOutput(ImageCmd)
dockerCmd(c, "pull", "busybox")
c.Assert(err, check.IsNil)
outImageCmd, _ := dockerCmd(c, "images", "busybox")
pullAllTagCmd := exec.Command(dockerBinary, "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)
}
dockerCmd(c, "pull", "--all-tags=true", "busybox")
ImageCmd1 := exec.Command(dockerBinary, "images", "busybox")
outImageAllTagCmd, _, err := runCommandWithOutput(ImageCmd1)
c.Assert(err, check.IsNil)
outImageAllTagCmd, _ := dockerCmd(c, "images", "busybox")
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
c.Fatalf("Pulling with all tags should get more images")
}
pullAllTagCmd = exec.Command(dockerBinary, "pull", "-a", "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)
}
// FIXME has probably no effect (tags already pushed)
dockerCmd(c, "pull", "-a", "busybox")
ImageCmd2 := exec.Command(dockerBinary, "images", "busybox")
outImageAllTagCmd, _, err = runCommandWithOutput(ImageCmd2)
c.Assert(err, check.IsNil)
outImageAllTagCmd, _ = dockerCmd(c, "images", "busybox")
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
c.Fatalf("Pulling with all tags should get more images")

View file

@ -16,21 +16,14 @@ import (
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image to upload it to the private registry
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
c.Fatalf("image tagging failed: %s, %v", out, err)
}
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)
}
dockerCmd(c, "tag", "busybox", repoName)
// push the image to the registry
dockerCmd(c, "push", repoName)
}
// pushing an image without a prefix should throw an error
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
pushCmd := exec.Command(dockerBinary, "push", "busybox")
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
if out, _, err := dockerCmdWithError(c, "push", "busybox"); err == nil {
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)
expected := "Repository 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)
} else if !strings.Contains(out, expected) {
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)
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)
} else if !strings.Contains(out, expected) {
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)
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
// tag the image and upload it to the private registry
tagCmd1 := exec.Command(dockerBinary, "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)
}
dockerCmd(c, "tag", "busybox", repoTag1)
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)
}
dockerCmd(c, "tag", "busybox", repoTag2)
dockerCmd(c, "push", repoName)
}
func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image and upload it to the private registry
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil {
c.Fatalf("image tagging failed: %s, %v", out, err)
}
dockerCmd(c, "tag", "busybox", repoName)
pushCmd := exec.Command(dockerBinary, "push", repoName)
if err := pushCmd.Start(); err != nil {
@ -96,7 +78,7 @@ func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
if err := pushCmd.Process.Kill(); err != nil {
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)
if !strings.Contains(str, "already in progress") {
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
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 has failed: %s, %v", out, err)
}
}

View file

@ -550,6 +550,10 @@ func pullImageIfNotExist(image string) (err error) {
return
}
func dockerCmdWithError(c *check.C, args ...string) (string, int, error) {
return runCommandWithOutput(exec.Command(dockerBinary, args...))
}
func dockerCmd(c *check.C, args ...string) (string, int) {
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), out, err))