integration-cli: DockerAPISuite: replace dockerCmd and waitRun

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-27 13:13:00 +02:00
parent 908821d48a
commit 1baec48367
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
10 changed files with 174 additions and 191 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
@ -24,14 +25,14 @@ import (
) )
func (s *DockerAPISuite) TestGetContainersAttachWebsocket(c *testing.T) { func (s *DockerAPISuite) TestGetContainersAttachWebsocket(c *testing.T) {
out, _ := dockerCmd(c, "run", "-di", "busybox", "cat") cid := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Stdout()
cid = strings.TrimSpace(cid)
rwc, err := request.SockConn(10*time.Second, request.DaemonHost()) rwc, err := request.SockConn(10*time.Second, request.DaemonHost())
assert.NilError(c, err) assert.NilError(c, err)
cleanedContainerID := strings.TrimSpace(out)
config, err := websocket.NewConfig( config, err := websocket.NewConfig(
"/containers/"+cleanedContainerID+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1", "/containers/"+cid+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1",
"http://localhost", "http://localhost",
) )
assert.NilError(c, err) assert.NilError(c, err)
@ -136,7 +137,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
} }
// Create a container that only emits stdout. // Create a container that only emits stdout.
cid, _ := dockerCmd(c, "run", "-di", "busybox", "cat") cid := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Stdout()
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
// Attach to the container's stdout stream. // Attach to the container's stdout stream.
@ -152,7 +153,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
expectTimeout(wc, br, "stdout") expectTimeout(wc, br, "stdout")
// Test the similar functions of the stderr stream. // Test the similar functions of the stderr stream.
cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2") cid = cli.DockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2").Stdout()
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", request.DaemonHost()) wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", request.DaemonHost())
assert.NilError(c, err) assert.NilError(c, err)
@ -162,7 +163,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
expectTimeout(wc, br, "stderr") expectTimeout(wc, br, "stderr")
// Test with tty. // Test with tty.
cid, _ = dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2") cid = cli.DockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2").Stdout()
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
// Attach to stdout only. // Attach to stdout only.
wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", request.DaemonHost()) wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", request.DaemonHost())
@ -181,7 +182,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() defer apiClient.Close()
cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat") cid = cli.DockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat").Stdout()
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
// Make sure we don't see "hello" if Logs is false // Make sure we don't see "hello" if Logs is false

View file

@ -38,18 +38,17 @@ import (
func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) {
startCount := getContainerCount(c) startCount := getContainerCount(c)
name := "getall" const name = "getall"
dockerCmd(c, "run", "--name", name, "busybox", "true") cli.DockerCmd(c, "run", "--name", name, "busybox", "true")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() defer apiClient.Close()
options := container.ListOptions{
All: true,
}
ctx := testutil.GetContext(c) ctx := testutil.GetContext(c)
containers, err := apiClient.ContainerList(ctx, options) containers, err := apiClient.ContainerList(ctx, container.ListOptions{
All: true,
})
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, len(containers), startCount+1) assert.Equal(c, len(containers), startCount+1)
actual := containers[0].Names[0] actual := containers[0].Names[0]
@ -59,7 +58,7 @@ func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) {
// regression test for empty json field being omitted #13691 // regression test for empty json field being omitted #13691
func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
startCount := getContainerCount(c) startCount := getContainerCount(c)
dockerCmd(c, "run", "busybox", "true") cli.DockerCmd(c, "run", "busybox", "true")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -101,8 +100,8 @@ func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
// Not supported on Windows as Windows does not support docker export // Not supported on Windows as Windows does not support docker export
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "exportcontainer" const name = "exportcontainer"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test") cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -128,8 +127,8 @@ func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPIGetChanges(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIGetChanges(c *testing.T) {
// Not supported on Windows as Windows does not support docker diff (/containers/name/changes) // Not supported on Windows as Windows does not support docker diff (/containers/name/changes)
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "changescontainer" const name = "changescontainer"
dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd") cli.DockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -170,7 +169,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
dockerCmd(c, "rm", "-f", name) cli.DockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -187,8 +186,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
} }
func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) {
out := runSleepingContainer(c) id := runSleepingContainer(c)
id := strings.TrimSpace(out)
buf := &ChannelBuffer{C: make(chan []byte, 1)} buf := &ChannelBuffer{C: make(chan []byte, 1)}
defer buf.Close() defer buf.Close()
@ -218,7 +216,7 @@ func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) {
_, err = buf.ReadTimeout(b, 2*time.Second) _, err = buf.ReadTimeout(b, 2*time.Second)
assert.NilError(c, err) assert.NilError(c, err)
dockerCmd(c, "rm", "-f", id) cli.DockerCmd(c, "rm", "-f", id)
assert.Assert(c, <-chErr == nil) assert.Assert(c, <-chErr == nil)
} }
@ -254,7 +252,7 @@ func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
// previous test was just checking one stat entry so it didn't fail (stats with // previous test was just checking one stat entry so it didn't fail (stats with
// stream false always return one stat) // stream false always return one stat)
func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
name := "statscontainer" const name = "statscontainer"
runSleepingContainer(c, "--name", name) runSleepingContainer(c, "--name", name)
type b struct { type b struct {
@ -275,7 +273,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
dockerCmd(c, "rm", "-f", name) cli.DockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -295,7 +293,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
} }
func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) { func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
name := "statscontainer" const name = "statscontainer2"
runSleepingContainer(c, "--name", name) runSleepingContainer(c, "--name", name)
type b struct { type b struct {
@ -317,7 +315,7 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
dockerCmd(c, "rm", "-f", name) cli.DockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -335,8 +333,8 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
} }
func (s *DockerAPISuite) TestGetStoppedContainerStats(c *testing.T) { func (s *DockerAPISuite) TestGetStoppedContainerStats(c *testing.T) {
name := "statscontainer" const name = "statscontainer3"
dockerCmd(c, "create", "--name", name, "busybox", "ps") cli.DockerCmd(c, "create", "--name", name, "busybox", "ps")
chResp := make(chan error, 1) chResp := make(chan error, 1)
@ -394,9 +392,9 @@ func (s *DockerAPISuite) TestContainerAPIPause(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true") out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true").Stdout()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) cli.WaitRun(c, id)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -417,9 +415,8 @@ func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) { func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) {
testRequires(c, DaemonIsWindows) testRequires(c, DaemonIsWindows)
out := runSleepingContainer(c, "-d") id := runSleepingContainer(c, "-d")
id := strings.TrimSpace(out) cli.WaitRun(c, id)
assert.NilError(c, waitRun(id))
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -447,8 +444,8 @@ func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
cName := "testapicommit" const cName = "testapicommit"
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") cli.DockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -465,12 +462,12 @@ func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd)) assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
// sanity check, make sure the image is what we think it is // sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test") cli.DockerCmd(c, "run", img.ID, "ls", "/test")
} }
func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
cName := "testapicommitwithconfig" const cName = "testapicommitwithconfig"
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") cli.DockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -498,7 +495,7 @@ func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd)) assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
// sanity check, make sure the image is what we think it is // sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test") cli.DockerCmd(c, "run", img.ID, "ls", "/test")
} }
func (s *DockerAPISuite) TestContainerAPIBadPort(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIBadPort(c *testing.T) {
@ -542,7 +539,7 @@ func (s *DockerAPISuite) TestContainerAPICreate(c *testing.T) {
ctr, err := apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") ctr, err := apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "")
assert.NilError(c, err) assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", ctr.ID) out := cli.DockerCmd(c, "start", "-a", ctr.ID).Stdout()
assert.Equal(c, strings.TrimSpace(out), "/test") assert.Equal(c, strings.TrimSpace(out), "/test")
} }
@ -848,10 +845,9 @@ func (s *DockerAPISuite) TestCreateWithTooLowMemoryLimit(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) {
out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh") out := cli.DockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh").Stdout()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
newName := "TestContainerAPIRenameNew" const newName = "TestContainerAPIRenameNew"
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -865,7 +861,7 @@ func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) {
name := "test-api-kill" const name = "test-api-kill"
runSleepingContainer(c, "-i", "--name", name) runSleepingContainer(c, "-i", "--name", name)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
@ -880,7 +876,7 @@ func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) {
name := "test-api-restart" const name = "test-api-restart"
runSleepingContainer(c, "-di", "--name", name) runSleepingContainer(c, "-di", "--name", name)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -894,10 +890,9 @@ func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
name := "test-api-restart-no-timeout-param" const name = "test-api-restart-no-timeout-param"
out := runSleepingContainer(c, "-di", "--name", name) id := runSleepingContainer(c, "-di", "--name", name)
id := strings.TrimSpace(out) cli.WaitRun(c, id)
assert.NilError(c, waitRun(id))
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -910,7 +905,7 @@ func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
name := "testing-start" const name = "testing-start"
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
Cmd: append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...), Cmd: append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...),
@ -936,7 +931,7 @@ func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) {
name := "test-api-stop" const name = "test-api-stop"
runSleepingContainer(c, "-i", "--name", name) runSleepingContainer(c, "-i", "--name", name)
timeout := 30 timeout := 30
@ -959,13 +954,13 @@ func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) {
name := "test-api-wait" const name = "test-api-wait"
sleepCmd := "/bin/sleep" sleepCmd := "/bin/sleep"
if testEnv.DaemonInfo.OSType == "windows" { if testEnv.DaemonInfo.OSType == "windows" {
sleepCmd = "sleep" sleepCmd = "sleep"
} }
dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2") cli.DockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -982,8 +977,8 @@ func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
name := "test-container-api-copy" const name = "test-container-api-copy"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/test.txt", Resource: "/test.txt",
@ -996,8 +991,8 @@ func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy" const name = "test-container-api-copy"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/test.txt", Resource: "/test.txt",
@ -1026,8 +1021,8 @@ func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy-resource-empty" const name = "test-container-api-copy-resource-empty"
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "", Resource: "",
@ -1047,8 +1042,8 @@ func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.
func (s *DockerAPISuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) { func (s *DockerAPISuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
name := "test-container-api-copy-resource-not-found" const name = "test-container-api-copy-resource-not-found"
dockerCmd(c, "run", "--name", name, "busybox") cli.DockerCmd(c, "run", "--name", name, "busybox")
postData := types.CopyConfig{ postData := types.CopyConfig{
Resource: "/notexist", Resource: "/notexist",
@ -1078,12 +1073,9 @@ func (s *DockerAPISuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T
} }
func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) {
out := runSleepingContainer(c) id := runSleepingContainer(c)
cli.WaitRun(c, id)
id := strings.TrimSpace(out) cli.DockerCmd(c, "stop", id)
assert.NilError(c, waitRun(id))
dockerCmd(c, "stop", id)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -1103,9 +1095,8 @@ func (s *DockerAPISuite) TestContainerAPIDeleteNotExist(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
out := runSleepingContainer(c) id := runSleepingContainer(c)
id := strings.TrimSpace(out) cli.WaitRun(c, id)
assert.NilError(c, waitRun(id))
removeOptions := container.RemoveOptions{ removeOptions := container.RemoveOptions{
Force: true, Force: true,
@ -1122,15 +1113,13 @@ func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
// Windows does not support links // Windows does not support links
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top").Stdout()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) cli.WaitRun(c, id)
out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
out = cli.DockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top").Stdout()
id2 := strings.TrimSpace(out) id2 := strings.TrimSpace(out)
assert.Assert(c, waitRun(id2) == nil) cli.WaitRun(c, id2)
links := inspectFieldJSON(c, id2, "HostConfig.Links") links := inspectFieldJSON(c, id2, "HostConfig.Links")
assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers") assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers")
@ -1158,10 +1147,8 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
vol = `c:\testvolume` vol = `c:\testvolume`
} }
out := runSleepingContainer(c, "-v", vol) id := runSleepingContainer(c, "-v", vol)
cli.WaitRun(c, id)
id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id))
source, err := inspectMountSourceField(id, vol) source, err := inspectMountSourceField(id, vol)
assert.NilError(c, err) assert.NilError(c, err)
@ -1205,10 +1192,8 @@ func (s *DockerAPISuite) TestContainerAPIChunkedEncoding(c *testing.T) {
} }
func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) { func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) {
out := runSleepingContainer(c) containerID := runSleepingContainer(c)
cli.WaitRun(c, containerID)
containerID := strings.TrimSpace(out)
assert.Assert(c, waitRun(containerID) == nil)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -1233,7 +1218,7 @@ func (s *DockerAPISuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest") _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest")
assert.NilError(c, err) assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", "echotest") out := cli.DockerCmd(c, "start", "-a", "echotest").Combined()
assert.Equal(c, strings.TrimSpace(out), "hello world") assert.Equal(c, strings.TrimSpace(out), "hello world")
config2 := struct { config2 := struct {
@ -1243,7 +1228,7 @@ func (s *DockerAPISuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c
}{"busybox", "echo", []string{"hello", "world"}} }{"busybox", "echo", []string{"hello", "world"}}
_, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2)) _, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2))
assert.NilError(c, err) assert.NilError(c, err)
out, _ = dockerCmd(c, "start", "-a", "echotest2") out = cli.DockerCmd(c, "start", "-a", "echotest2").Combined()
assert.Equal(c, strings.TrimSpace(out), "hello world") assert.Equal(c, strings.TrimSpace(out), "hello world")
} }
@ -1260,7 +1245,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest") _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest")
assert.NilError(c, err) assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", "echotest") out := cli.DockerCmd(c, "start", "-a", "echotest").Combined()
assert.Equal(c, strings.TrimSpace(out), "hello world") assert.Equal(c, strings.TrimSpace(out), "hello world")
config2 := struct { config2 := struct {
@ -1270,7 +1255,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing
}{"busybox", "echo", "hello world"} }{"busybox", "echo", "hello world"}
_, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2)) _, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2))
assert.NilError(c, err) assert.NilError(c, err)
out, _ = dockerCmd(c, "start", "-a", "echotest2") out = cli.DockerCmd(c, "start", "-a", "echotest2").Combined()
assert.Equal(c, strings.TrimSpace(out), "hello world") assert.Equal(c, strings.TrimSpace(out), "hello world")
} }
@ -1364,7 +1349,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
CpusetCpus: "1-42,,", CpusetCpus: "1-42,,",
}, },
} }
name := "wrong-cpuset-cpus" const name = "wrong-cpuset-cpus"
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig1, &network.NetworkingConfig{}, nil, name) _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig1, &network.NetworkingConfig{}, nil, name)
expected := "Invalid value 1-42,, for cpuset cpus" expected := "Invalid value 1-42,, for cpuset cpus"
@ -1375,8 +1360,8 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
CpusetMems: "42-3,1--", CpusetMems: "42-3,1--",
}, },
} }
name = "wrong-cpuset-mems" const name2 = "wrong-cpuset-mems"
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig2, &network.NetworkingConfig{}, nil, name) _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig2, &network.NetworkingConfig{}, nil, name2)
expected = "Invalid value 42-3,1-- for cpuset mems" expected = "Invalid value 42-3,1-- for cpuset mems"
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
} }
@ -1420,7 +1405,7 @@ func (s *DockerAPISuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *tes
assert.Equal(c, containerJSON.HostConfig.ShmSize, dconfig.DefaultShmSize) assert.Equal(c, containerJSON.HostConfig.ShmSize, dconfig.DefaultShmSize)
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
if !shmRegexp.MatchString(out) { if !shmRegexp.MatchString(out) {
c.Fatalf("Expected shm of 64MB in mount command, got %v", out) c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
@ -1447,7 +1432,7 @@ func (s *DockerAPISuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) {
assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(67108864)) assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(67108864))
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
if !shmRegexp.MatchString(out) { if !shmRegexp.MatchString(out) {
c.Fatalf("Expected shm of 64MB in mount command, got %v", out) c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
@ -1478,7 +1463,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithShmSize(c *testing.T) {
assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(1073741824)) assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(1073741824))
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`) shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`)
if !shmRegex.MatchString(out) { if !shmRegex.MatchString(out) {
c.Fatalf("Expected shm of 1GB in mount command, got %v", out) c.Fatalf("Expected shm of 1GB in mount command, got %v", out)
@ -1526,7 +1511,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() defer apiClient.Close()
name := "oomscoreadj-over" const name = "oomscoreadj-over"
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name) _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name)
expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]" expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]"
@ -1536,8 +1521,8 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
OomScoreAdj: -1001, OomScoreAdj: -1001,
} }
name = "oomscoreadj-low" const name2 = "oomscoreadj-low"
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name) _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name2)
expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]" expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]"
assert.ErrorContains(c, err, expected) assert.ErrorContains(c, err, expected)
@ -1557,7 +1542,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
// Problematic on Windows as Windows does not support stats // Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "testing-network-disabled" const name = "testing-network-disabled"
config := container.Config{ config := container.Config{
Image: "busybox", Image: "busybox",
@ -1574,8 +1559,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{}) err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{})
assert.NilError(c, err) assert.NilError(c, err)
cli.WaitRun(c, name)
assert.Assert(c, waitRun(name) == nil)
type b struct { type b struct {
stats types.ContainerStats stats types.ContainerStats
@ -1589,7 +1573,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
// allow some time to stream the stats from the container // allow some time to stream the stats from the container
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
dockerCmd(c, "rm", "-f", name) cli.DockerCmd(c, "rm", "-f", name)
// collect the results from the stats stream or timeout and fail // collect the results from the stats stream or timeout and fail
// if the stream was not disconnected. // if the stream was not disconnected.
@ -1943,7 +1927,7 @@ func (s *DockerAPISuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, "test") _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, "test")
assert.NilError(c, err) assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", "test") out := cli.DockerCmd(c, "start", "-a", "test").Combined()
assert.Equal(c, out, "hello") assert.Equal(c, out, "hello")
} }
@ -2197,7 +2181,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, cName) _, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, cName)
assert.NilError(c, err) assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", cName) out := cli.DockerCmd(c, "start", "-a", cName).Combined()
for _, option := range x.expectedOptions { for _, option := range x.expectedOptions {
assert.Assert(c, strings.Contains(out, option)) assert.Assert(c, strings.Contains(out, option))
} }

View file

@ -11,6 +11,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -19,7 +20,7 @@ import (
func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) { func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
@ -35,7 +36,7 @@ func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
// Part of #14845 // Part of #14845
func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) { func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
name := "exec_resize_test" name := "exec_resize_test"
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
testExecResize := func() error { testExecResize := func() error {
data := map[string]interface{}{ data := map[string]interface{}{

View file

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -26,7 +27,7 @@ import (
// Regression test for #9414 // Regression test for #9414
func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) { func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
res, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": nil})) res, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": nil}))
assert.NilError(c, err) assert.NilError(c, err)
@ -42,7 +43,7 @@ func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) {
func (s *DockerAPISuite) TestExecAPICreateNoValidContentType(c *testing.T) { func (s *DockerAPISuite) TestExecAPICreateNoValidContentType(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
jsonData := bytes.NewBuffer(nil) jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil { if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil {
@ -65,9 +66,9 @@ func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
// Not relevant on Windows as Windows containers cannot be paused // Not relevant on Windows as Windows containers cannot be paused
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "exec_create_test" name := "exec_create_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
dockerCmd(c, "pause", name) cli.DockerCmd(c, "pause", name)
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
@ -82,7 +83,7 @@ func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) {
testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
id := createExec(c, "test") id := createExec(c, "test")
startExec(c, id, http.StatusOK) startExec(c, id, http.StatusOK)
@ -92,24 +93,24 @@ func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) {
assert.Assert(c, execJSON.PID > 1) assert.Assert(c, execJSON.PID > 1)
id = createExec(c, "test") id = createExec(c, "test")
dockerCmd(c, "stop", "test") cli.DockerCmd(c, "stop", "test")
startExec(c, id, http.StatusNotFound) startExec(c, id, http.StatusNotFound)
dockerCmd(c, "start", "test") cli.DockerCmd(c, "start", "test")
startExec(c, id, http.StatusNotFound) startExec(c, id, http.StatusNotFound)
// make sure exec is created before pausing // make sure exec is created before pausing
id = createExec(c, "test") id = createExec(c, "test")
dockerCmd(c, "pause", "test") cli.DockerCmd(c, "pause", "test")
startExec(c, id, http.StatusConflict) startExec(c, id, http.StatusConflict)
dockerCmd(c, "unpause", "test") cli.DockerCmd(c, "unpause", "test")
startExec(c, id, http.StatusOK) startExec(c, id, http.StatusOK)
} }
func (s *DockerAPISuite) TestExecAPIStartEnsureHeaders(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartEnsureHeaders(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
id := createExec(c, "test") id := createExec(c, "test")
resp, _, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON) resp, _, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
@ -177,7 +178,7 @@ func (s *DockerAPISuite) TestExecAPIStartWithDetach(c *testing.T) {
// #30311 // #30311
func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
id := createExecCmd(c, name, "true") id := createExecCmd(c, name, "true")
startExec(c, id, http.StatusOK) startExec(c, id, http.StatusOK)
@ -194,7 +195,7 @@ func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) {
// #30311 // #30311
func (s *DockerAPISuite) TestExecAPIStartInvalidCommand(c *testing.T) { func (s *DockerAPISuite) TestExecAPIStartInvalidCommand(c *testing.T) {
name := "exec_test" name := "exec_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
id := createExecCmd(c, name, "invalid") id := createExecCmd(c, name, "invalid")
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") { if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
@ -217,7 +218,7 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) {
// This test checks accidental regressions. Not part of stable API. // This test checks accidental regressions. Not part of stable API.
name := "exec_cleanup" name := "exec_cleanup"
cid, _ := dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cid := cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh").Stdout()
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
stateDir := "/var/run/docker/containerd/" + cid stateDir := "/var/run/docker/containerd/" + cid
@ -246,7 +247,7 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) {
poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second)) poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
dockerCmd(c, "stop", name) cli.DockerCmd(c, "stop", name)
_, err = os.Stat(stateDir) _, err = os.Stat(stateDir)
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
assert.Assert(c, os.IsNotExist(err)) assert.Assert(c, os.IsNotExist(err))

View file

@ -26,7 +26,7 @@ func (s *DockerAPISuite) TestAPIImagesSaveAndLoad(c *testing.T) {
defer body.Close() defer body.Close()
assert.Equal(c, res.StatusCode, http.StatusOK) assert.Equal(c, res.StatusCode, http.StatusOK)
dockerCmd(c, "rmi", id) cli.DockerCmd(c, "rmi", id)
res, loadBody, err := request.Post(ctx, "/images/load", request.RawContent(body), request.ContentType("application/x-tar")) res, loadBody, err := request.Post(ctx, "/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
assert.NilError(c, err) assert.NilError(c, err)
@ -49,7 +49,7 @@ func (s *DockerAPISuite) TestAPIImagesDelete(c *testing.T) {
buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar")) buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
id := getIDByName(c, name) id := getIDByName(c, name)
dockerCmd(c, "tag", name, "test:tag1") cli.DockerCmd(c, "tag", name, "test:tag1")
_, err = apiClient.ImageRemove(testutil.GetContext(c), id, types.ImageRemoveOptions{}) _, err = apiClient.ImageRemove(testutil.GetContext(c), id, types.ImageRemoveOptions{})
assert.ErrorContains(c, err, "unable to delete") assert.ErrorContains(c, err, "unable to delete")

View file

@ -8,15 +8,16 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions/v1p20" "github.com/docker/docker/api/types/versions/v1p20"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
keysBase := []string{ keysBase := []string{
"Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", "Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings",
"ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel", "GraphDriver", "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel", "GraphDriver",
@ -61,8 +62,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
// No legacy implications for Windows // No legacy implications for Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
cases := []string{"v1.19", "v1.20"} cases := []string{"v1.19", "v1.20"}
@ -82,8 +82,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T)
} }
func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true") out := cli.DockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
body := getInspectBody(c, "v1.25", cleanedContainerID) body := getInspectBody(c, "v1.25", cleanedContainerID)
@ -106,7 +105,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
} }
func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
dockerCmd(c, "tag", "busybox:latest", "busybox:mytag") cli.DockerCmd(c, "tag", "busybox:latest", "busybox:mytag")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() defer apiClient.Close()
@ -123,8 +122,7 @@ func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
// Not relevant on Windows // Not relevant on Windows
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
cases := []string{"v1.19", "v1.20"} cases := []string{"v1.19", "v1.20"}
@ -147,9 +145,9 @@ func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
// Not relevant on Windows, and besides it doesn't have any bridge network settings // Not relevant on Windows, and besides it doesn't have any bridge network settings
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
waitRun(containerID) cli.WaitRun(c, containerID)
body := getInspectBody(c, "v1.20", containerID) body := getInspectBody(c, "v1.20", containerID)
@ -164,9 +162,9 @@ func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) { func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) {
// Windows doesn't have any bridge network settings // Windows doesn't have any bridge network settings
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
waitRun(containerID) cli.WaitRun(c, containerID)
body := getInspectBody(c, "v1.21", containerID) body := getInspectBody(c, "v1.21", containerID)

View file

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
@ -20,9 +21,9 @@ import (
) )
func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") out := cli.DockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done").Stdout()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) cli.WaitRun(c, id)
type logOut struct { type logOut struct {
out string out string
@ -56,8 +57,8 @@ func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) {
} }
func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) { func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
name := "logs_test" const name = "logs_test"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
apiClient, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() defer apiClient.Close()
@ -68,9 +69,9 @@ func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
// Regression test for #12704 // Regression test for #12704
func (s *DockerAPISuite) TestLogsAPIFollowEmptyOutput(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIFollowEmptyOutput(c *testing.T) {
name := "logs_test" const name = "logs_test"
t0 := time.Now() t0 := time.Now()
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10") cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
_, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name)) _, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
t1 := time.Now() t1 := time.Now()
@ -91,21 +92,21 @@ func (s *DockerAPISuite) TestLogsAPIContainerNotFound(c *testing.T) {
func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "logsuntilfuturefollow" const name = "logsuntilfuturefollow"
dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done") cli.DockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done")
assert.NilError(c, waitRun(name)) cli.WaitRun(c, name)
untilSecs := 5 untilSecs := 5
untilDur, err := time.ParseDuration(fmt.Sprintf("%ds", untilSecs)) untilDur, err := time.ParseDuration(fmt.Sprintf("%ds", untilSecs))
assert.NilError(c, err) assert.NilError(c, err)
until := daemonTime(c).Add(untilDur) until := daemonTime(c).Add(untilDur)
client, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
} }
reader, err := client.ContainerLogs(testutil.GetContext(c), name, container.LogsOptions{ reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, container.LogsOptions{
Until: until.Format(time.RFC3339Nano), Until: until.Format(time.RFC3339Nano),
Follow: true, Follow: true,
ShowStdout: true, ShowStdout: true,
@ -163,16 +164,16 @@ func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) {
testRequires(c, MinimumAPIVersion("1.34")) testRequires(c, MinimumAPIVersion("1.34"))
name := "logsuntil" const name = "logsuntil"
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done") cli.DockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")
client, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
} }
extractBody := func(c *testing.T, cfg container.LogsOptions) []string { extractBody := func(c *testing.T, cfg container.LogsOptions) []string {
reader, err := client.ContainerLogs(testutil.GetContext(c), name, cfg) reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg)
assert.NilError(c, err) assert.NilError(c, err)
actualStdout := new(bytes.Buffer) actualStdout := new(bytes.Buffer)
@ -200,16 +201,16 @@ func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) {
} }
func (s *DockerAPISuite) TestLogsAPIUntilDefaultValue(c *testing.T) { func (s *DockerAPISuite) TestLogsAPIUntilDefaultValue(c *testing.T) {
name := "logsuntildefaultval" const name = "logsuntildefaultval"
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done") cli.DockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done")
client, err := client.NewClientWithOpts(client.FromEnv) apiClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil { if err != nil {
c.Fatal(err) c.Fatal(err)
} }
extractBody := func(c *testing.T, cfg container.LogsOptions) []string { extractBody := func(c *testing.T, cfg container.LogsOptions) []string {
reader, err := client.ContainerLogs(testutil.GetContext(c), name, cfg) reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg)
assert.NilError(c, err) assert.NilError(c, err)
actualStdout := new(bytes.Buffer) actualStdout := new(bytes.Buffer)

View file

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -40,7 +41,7 @@ func (s *DockerAPISuite) TestAPINetworkInspectBridge(c *testing.T) {
assert.Equal(c, nr.Name, "bridge") assert.Equal(c, nr.Name, "bridge")
// run a container and attach it to the default bridge network // run a container and attach it to the default bridge network
out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top").Stdout()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
containerIP := findContainerIP(c, "test", "bridge") containerIP := findContainerIP(c, "test", "bridge")
@ -104,7 +105,7 @@ func (s *DockerAPISuite) TestAPINetworkConnectDisconnect(c *testing.T) {
assert.Equal(c, len(nr.Containers), 0) assert.Equal(c, len(nr.Containers), 0)
// run a container // run a container
out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") out := cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top").Stdout()
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
// connect the container to the test network // connect the container to the test network

View file

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/system" "github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -26,10 +27,9 @@ var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors
func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done") out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done").Stdout()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) cli.WaitRun(c, id)
resp, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/stats?stream=false", id)) resp, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/stats?stream=false", id))
assert.NilError(c, err) assert.NilError(c, err)
assert.Equal(c, resp.StatusCode, http.StatusOK) assert.Equal(c, resp.StatusCode, http.StatusOK)
@ -66,7 +66,7 @@ func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
} }
func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1") out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1").Stdout()
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
getGoRoutines := func() int { getGoRoutines := func() int {
@ -104,9 +104,8 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStats(c *testing.T) {
skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination") skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
testRequires(c, testEnv.IsLocalDaemon) testRequires(c, testEnv.IsLocalDaemon)
out := runSleepingContainer(c) id := runSleepingContainer(c)
id := strings.TrimSpace(out) cli.WaitRun(c, id)
assert.NilError(c, waitRun(id))
// Retrieve the container address // Retrieve the container address
net := "bridge" net := "bridge"
@ -170,9 +169,8 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) {
// Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21 // Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
out := runSleepingContainer(c) id := runSleepingContainer(c)
id := strings.TrimSpace(out) cli.WaitRun(c, id)
assert.NilError(c, waitRun(id))
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
for i := 17; i <= 21; i++ { for i := 17; i <= 21; i++ {
@ -278,13 +276,11 @@ func (s *DockerAPISuite) TestAPIStatsContainerNotFound(c *testing.T) {
func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) { func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out1 := runSleepingContainer(c) id1 := runSleepingContainer(c)
id1 := strings.TrimSpace(out1) cli.WaitRun(c, id1)
assert.NilError(c, waitRun(id1))
out2 := runSleepingContainer(c, "--net", "container:"+id1) id2 := runSleepingContainer(c, "--net", "container:"+id1)
id2 := strings.TrimSpace(out2) cli.WaitRun(c, id2)
assert.NilError(c, waitRun(id2))
ch := make(chan error, 1) ch := make(chan error, 1)
go func() { go func() {

View file

@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -21,7 +22,7 @@ func formatV123StartAPIURL(url string) string {
func (s *DockerAPISuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) {
name := "test-deprecated-api-124" name := "test-deprecated-api-124"
dockerCmd(c, "create", "--name", name, "busybox") cli.DockerCmd(c, "create", "--name", name, "busybox")
config := map[string]interface{}{ config := map[string]interface{}{
"Binds": []string{"/aa:/bb"}, "Binds": []string{"/aa:/bb"},
} }
@ -108,7 +109,7 @@ func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T
volName := "voltst" volName := "voltst"
volPath := "/tmp" volPath := "/tmp"
dockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox") cli.DockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox")
name := "TestContainerAPIStartVolumesFrom" name := "TestContainerAPIStartVolumesFrom"
config := map[string]interface{}{ config := map[string]interface{}{
@ -138,12 +139,12 @@ func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T
func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) {
// TODO Windows to Windows CI - Port this // TODO Windows to Windows CI - Port this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox") cli.DockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
fooDir, err := inspectMountSourceField("one", "/foo") fooDir, err := inspectMountSourceField("one", "/foo")
assert.NilError(c, err) assert.NilError(c, err)
dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox") cli.DockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}} bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
res, _, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/two/start"), request.JSONBody(bindSpec)) res, _, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/two/start"), request.JSONBody(bindSpec))
@ -158,11 +159,10 @@ func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.
func (s *DockerAPISuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) {
// TODO Windows: Port once memory is supported // TODO Windows: Port once memory is supported
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "create", "busybox") containerID := cli.DockerCmd(c, "create", "busybox").Stdout()
containerID = strings.TrimSpace(containerID)
containerID := strings.TrimSpace(out) const config = `{
config := `{
"CpuShares": 100, "CpuShares": 100,
"Memory": 524287 "Memory": 524287
}` }`
@ -185,7 +185,7 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithoutLinksInHostConf
// An alternate test could be written to validate the negative testing aspect of this // An alternate test could be written to validate the negative testing aspect of this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-host-config-links" name := "test-host-config-links"
dockerCmd(c, append([]string{"create", "--name", name, "busybox"}, sleepCommandForDaemonPlatform()...)...) cli.DockerCmd(c, append([]string{"create", "--name", name, "busybox"}, sleepCommandForDaemonPlatform()...)...)
hc := inspectFieldJSON(c, name, "HostConfig") hc := inspectFieldJSON(c, name, "HostConfig")
config := `{"HostConfig":` + hc + `}` config := `{"HostConfig":` + hc + `}`
@ -202,8 +202,8 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(
// An alternate test could be written to validate the negative testing aspect of this // An alternate test could be written to validate the negative testing aspect of this
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-host-config-links" name := "test-host-config-links"
dockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top") cli.DockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top")
dockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top") cli.DockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top")
hc := inspectFieldJSON(c, name, "HostConfig") hc := inspectFieldJSON(c, name, "HostConfig")
config := `{"HostConfig":` + hc + `}` config := `{"HostConfig":` + hc + `}`
@ -218,12 +218,12 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(
func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) {
// Windows does not support links // Windows does not support links
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
name := "test-host-config-links" const name = "test-host-config-links"
out, _ := dockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top") containerID := cli.DockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top").Combined()
defer dockerCmd(c, "stop", "link0") containerID = strings.TrimSpace(containerID)
id := strings.TrimSpace(out) defer cli.DockerCmd(c, "stop", "link0")
dockerCmd(c, "create", "--name", name, "--link", id, "busybox", "top") cli.DockerCmd(c, "create", "--name", name, "--link", containerID, "busybox", "top")
defer dockerCmd(c, "stop", name) defer cli.DockerCmd(c, "stop", name)
hc := inspectFieldJSON(c, name, "HostConfig") hc := inspectFieldJSON(c, name, "HostConfig")
config := `{"HostConfig":` + hc + `}` config := `{"HostConfig":` + hc + `}`
@ -237,10 +237,10 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigI
func (s *DockerAPISuite) TestDeprecatedStartWithNilDNS(c *testing.T) { func (s *DockerAPISuite) TestDeprecatedStartWithNilDNS(c *testing.T) {
// TODO Windows: Add once DNS is supported // TODO Windows: Add once DNS is supported
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "create", "busybox") containerID := cli.DockerCmd(c, "create", "busybox").Stdout()
containerID := strings.TrimSpace(out) containerID = strings.TrimSpace(containerID)
config := `{"HostConfig": {"Dns": null}}` const config = `{"HostConfig": {"Dns": null}}`
res, b, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON) res, b, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
assert.NilError(c, err) assert.NilError(c, err)