integration-cli: DockerCLIAttachSuite: replace dockerCmd and waitRun
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
1baec48367
commit
cf95278122
2 changed files with 25 additions and 19 deletions
|
@ -110,10 +110,9 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
||||||
// will just fail and `MISS` all the other tests. For now, disabling it. Will
|
// will just fail and `MISS` all the other tests. For now, disabling it. Will
|
||||||
// open an issue to track re-enabling this and root-causing the problem.
|
// open an issue to track re-enabling this and root-causing the problem.
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
|
out := cli.DockerCmd(c, "run", "-d", "-ti", "busybox").Stdout()
|
||||||
|
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
assert.NilError(c, waitRun(id))
|
cli.WaitRun(c, id)
|
||||||
|
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -129,10 +128,17 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
|
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
|
||||||
}
|
}
|
||||||
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
result := icmd.RunCmd(icmd.Cmd{
|
||||||
|
Command: cmd.Args,
|
||||||
|
Env: cmd.Env,
|
||||||
|
Dir: cmd.Dir,
|
||||||
|
Stdin: cmd.Stdin,
|
||||||
|
Stdout: cmd.Stdout,
|
||||||
|
})
|
||||||
|
if result.Error == nil {
|
||||||
done <- fmt.Errorf("attach should have failed")
|
done <- fmt.Errorf("attach should have failed")
|
||||||
return
|
return
|
||||||
} else if !strings.Contains(out, expected) {
|
} else if !strings.Contains(result.Combined(), expected) {
|
||||||
done <- fmt.Errorf("attach failed with error %q: expected %q", out, expected)
|
done <- fmt.Errorf("attach failed with error %q: expected %q", out, expected)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -148,7 +154,7 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
|
func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
|
out := cli.DockerCmd(c, "run", "-di", "busybox", "/bin/cat").Stdout()
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
||||||
cmd := exec.Command(dockerBinary, "attach", id)
|
cmd := exec.Command(dockerBinary, "attach", id)
|
||||||
|
@ -182,9 +188,9 @@ func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
|
||||||
func (s *DockerCLIAttachSuite) TestAttachPausedContainer(c *testing.T) {
|
func (s *DockerCLIAttachSuite) TestAttachPausedContainer(c *testing.T) {
|
||||||
testRequires(c, IsPausable)
|
testRequires(c, IsPausable)
|
||||||
runSleepingContainer(c, "-d", "--name=test")
|
runSleepingContainer(c, "-d", "--name=test")
|
||||||
dockerCmd(c, "pause", "test")
|
cli.DockerCmd(c, "pause", "test")
|
||||||
|
|
||||||
result := dockerCmdWithResult("attach", "test")
|
result := cli.Docker(cli.Args("attach", "test"))
|
||||||
result.Assert(c, icmd.Expected{
|
result.Assert(c, icmd.Expected{
|
||||||
Error: "exit status 1",
|
Error: "exit status 1",
|
||||||
ExitCode: 1,
|
ExitCode: 1,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
|
"github.com/docker/docker/integration-cli/cli"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,12 +19,11 @@ import (
|
||||||
func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
||||||
testRequires(c, testEnv.IsLocalDaemon)
|
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)
|
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)
|
assert.NilError(c, err)
|
||||||
|
|
||||||
attachCmd := exec.Command(dockerBinary, "attach", id)
|
attachCmd := exec.Command(dockerBinary, "attach", id)
|
||||||
|
@ -38,19 +38,19 @@ func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
defer close(errChan)
|
defer close(errChan)
|
||||||
// Container is waiting for us to signal it to stop
|
// 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
|
// And wait for the attach command to end
|
||||||
errChan <- attachCmd.Wait()
|
errChan <- attachCmd.Wait()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Wait for the docker to end (should be done by the
|
// Wait for the docker to end (should be done by the
|
||||||
// stop command in the go routine)
|
// stop command in the go routine)
|
||||||
dockerCmd(c, "wait", id)
|
cli.DockerCmd(c, "wait", id)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
tty.Close()
|
tty.Close()
|
||||||
out, _ := io.ReadAll(pty)
|
out, _ := io.ReadAll(pt)
|
||||||
assert.Assert(c, err == nil, "out: %v", string(out))
|
assert.Assert(c, err == nil, "out: %v", string(out))
|
||||||
case <-time.After(attachWait):
|
case <-time.After(attachWait):
|
||||||
c.Fatal("timed out without attach returning")
|
c.Fatal("timed out without attach returning")
|
||||||
|
@ -73,7 +73,7 @@ func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
|
||||||
close(cmdExit)
|
close(cmdExit)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
assert.Assert(c, waitRun(name) == nil)
|
cli.WaitRun(c, name)
|
||||||
|
|
||||||
cpty.Write([]byte{16})
|
cpty.Write([]byte{16})
|
||||||
time.Sleep(100 * time.Millisecond)
|
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
|
// TestAttachDetach checks that attach in tty mode can be detached using the long container ID
|
||||||
func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
|
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)
|
id := strings.TrimSpace(out)
|
||||||
assert.NilError(c, waitRun(id))
|
cli.WaitRun(c, id)
|
||||||
|
|
||||||
cpty, tty, err := pty.Open()
|
cpty, tty, err := pty.Open()
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
@ -138,7 +138,7 @@ func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
|
||||||
defer stdout.Close()
|
defer stdout.Close()
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
assert.NilError(c, waitRun(id))
|
cli.WaitRun(c, id)
|
||||||
|
|
||||||
_, err = cpty.Write([]byte("hello\n"))
|
_, err = cpty.Write([]byte("hello\n"))
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
|
Loading…
Reference in a new issue