1
0
mirror of https://github.com/moby/moby.git synced 2025-11-02 05:13:42 +03:00

integration-cli: DockerCLIAttachSuite: 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:16:15 +02:00
parent 1baec48367
commit cf95278122
2 changed files with 25 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ import (
"time"
"github.com/creack/pty"
"github.com/docker/docker/integration-cli/cli"
"gotest.tools/v3/assert"
)
@@ -18,12 +19,11 @@ import (
func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
testRequires(c, testEnv.IsLocalDaemon)
out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`)
out := cli.DockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`).Stdout()
id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id))
cli.WaitRun(c, id)
pty, tty, err := pty.Open()
pt, tty, err := pty.Open()
assert.NilError(c, err)
attachCmd := exec.Command(dockerBinary, "attach", id)
@@ -38,19 +38,19 @@ func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
time.Sleep(300 * time.Millisecond)
defer close(errChan)
// Container is waiting for us to signal it to stop
dockerCmd(c, "stop", id)
cli.DockerCmd(c, "stop", id)
// And wait for the attach command to end
errChan <- attachCmd.Wait()
}()
// Wait for the docker to end (should be done by the
// stop command in the go routine)
dockerCmd(c, "wait", id)
cli.DockerCmd(c, "wait", id)
select {
case err := <-errChan:
tty.Close()
out, _ := io.ReadAll(pty)
out, _ := io.ReadAll(pt)
assert.Assert(c, err == nil, "out: %v", string(out))
case <-time.After(attachWait):
c.Fatal("timed out without attach returning")
@@ -73,7 +73,7 @@ func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
close(cmdExit)
}()
assert.Assert(c, waitRun(name) == nil)
cli.WaitRun(c, name)
cpty.Write([]byte{16})
time.Sleep(100 * time.Millisecond)
@@ -123,9 +123,9 @@ func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
// TestAttachDetach checks that attach in tty mode can be detached using the long container ID
func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat")
out := cli.DockerCmd(c, "run", "-itd", "busybox", "cat").Stdout()
id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id))
cli.WaitRun(c, id)
cpty, tty, err := pty.Open()
assert.NilError(c, err)
@@ -138,7 +138,7 @@ func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
defer stdout.Close()
err = cmd.Start()
assert.NilError(c, err)
assert.NilError(c, waitRun(id))
cli.WaitRun(c, id)
_, err = cpty.Write([]byte("hello\n"))
assert.NilError(c, err)