Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -110,10 +110,9 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
| 110 | 110 |
// will just fail and `MISS` all the other tests. For now, disabling it. Will |
| 111 | 111 |
// open an issue to track re-enabling this and root-causing the problem. |
| 112 | 112 |
testRequires(c, DaemonIsLinux) |
| 113 |
- out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") |
|
| 114 |
- |
|
| 113 |
+ out := cli.DockerCmd(c, "run", "-d", "-ti", "busybox").Stdout() |
|
| 115 | 114 |
id := strings.TrimSpace(out) |
| 116 |
- assert.NilError(c, waitRun(id)) |
|
| 115 |
+ cli.WaitRun(c, id) |
|
| 117 | 116 |
|
| 118 | 117 |
done := make(chan error, 1) |
| 119 | 118 |
go func() {
|
| ... | ... |
@@ -129,10 +128,17 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
| 129 | 129 |
if runtime.GOOS == "windows" {
|
| 130 | 130 |
expected += ". If you are using mintty, try prefixing the command with 'winpty'" |
| 131 | 131 |
} |
| 132 |
- if out, _, err := runCommandWithOutput(cmd); err == nil {
|
|
| 132 |
+ result := icmd.RunCmd(icmd.Cmd{
|
|
| 133 |
+ Command: cmd.Args, |
|
| 134 |
+ Env: cmd.Env, |
|
| 135 |
+ Dir: cmd.Dir, |
|
| 136 |
+ Stdin: cmd.Stdin, |
|
| 137 |
+ Stdout: cmd.Stdout, |
|
| 138 |
+ }) |
|
| 139 |
+ if result.Error == nil {
|
|
| 133 | 140 |
done <- fmt.Errorf("attach should have failed")
|
| 134 | 141 |
return |
| 135 |
- } else if !strings.Contains(out, expected) {
|
|
| 142 |
+ } else if !strings.Contains(result.Combined(), expected) {
|
|
| 136 | 143 |
done <- fmt.Errorf("attach failed with error %q: expected %q", out, expected)
|
| 137 | 144 |
return |
| 138 | 145 |
} |
| ... | ... |
@@ -148,7 +154,7 @@ func (s *DockerCLIAttachSuite) TestAttachTTYWithoutStdin(c *testing.T) {
|
| 148 | 148 |
|
| 149 | 149 |
func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
|
| 150 | 150 |
testRequires(c, DaemonIsLinux) |
| 151 |
- out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat") |
|
| 151 |
+ out := cli.DockerCmd(c, "run", "-di", "busybox", "/bin/cat").Stdout() |
|
| 152 | 152 |
id := strings.TrimSpace(out) |
| 153 | 153 |
|
| 154 | 154 |
cmd := exec.Command(dockerBinary, "attach", id) |
| ... | ... |
@@ -182,9 +188,9 @@ func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) {
|
| 182 | 182 |
func (s *DockerCLIAttachSuite) TestAttachPausedContainer(c *testing.T) {
|
| 183 | 183 |
testRequires(c, IsPausable) |
| 184 | 184 |
runSleepingContainer(c, "-d", "--name=test") |
| 185 |
- dockerCmd(c, "pause", "test") |
|
| 185 |
+ cli.DockerCmd(c, "pause", "test") |
|
| 186 | 186 |
|
| 187 |
- result := dockerCmdWithResult("attach", "test")
|
|
| 187 |
+ result := cli.Docker(cli.Args("attach", "test"))
|
|
| 188 | 188 |
result.Assert(c, icmd.Expected{
|
| 189 | 189 |
Error: "exit status 1", |
| 190 | 190 |
ExitCode: 1, |
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"time" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/creack/pty" |
| 14 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 14 | 15 |
"gotest.tools/v3/assert" |
| 15 | 16 |
) |
| 16 | 17 |
|
| ... | ... |
@@ -18,12 +19,11 @@ import ( |
| 18 | 18 |
func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
| 19 | 19 |
testRequires(c, testEnv.IsLocalDaemon) |
| 20 | 20 |
|
| 21 |
- out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`) |
|
| 22 |
- |
|
| 21 |
+ out := cli.DockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`).Stdout() |
|
| 23 | 22 |
id := strings.TrimSpace(out) |
| 24 |
- assert.NilError(c, waitRun(id)) |
|
| 23 |
+ cli.WaitRun(c, id) |
|
| 25 | 24 |
|
| 26 |
- pty, tty, err := pty.Open() |
|
| 25 |
+ pt, tty, err := pty.Open() |
|
| 27 | 26 |
assert.NilError(c, err) |
| 28 | 27 |
|
| 29 | 28 |
attachCmd := exec.Command(dockerBinary, "attach", id) |
| ... | ... |
@@ -38,19 +38,19 @@ func (s *DockerCLIAttachSuite) TestAttachClosedOnContainerStop(c *testing.T) {
|
| 38 | 38 |
time.Sleep(300 * time.Millisecond) |
| 39 | 39 |
defer close(errChan) |
| 40 | 40 |
// Container is waiting for us to signal it to stop |
| 41 |
- dockerCmd(c, "stop", id) |
|
| 41 |
+ cli.DockerCmd(c, "stop", id) |
|
| 42 | 42 |
// And wait for the attach command to end |
| 43 | 43 |
errChan <- attachCmd.Wait() |
| 44 | 44 |
}() |
| 45 | 45 |
|
| 46 | 46 |
// Wait for the docker to end (should be done by the |
| 47 | 47 |
// stop command in the go routine) |
| 48 |
- dockerCmd(c, "wait", id) |
|
| 48 |
+ cli.DockerCmd(c, "wait", id) |
|
| 49 | 49 |
|
| 50 | 50 |
select {
|
| 51 | 51 |
case err := <-errChan: |
| 52 | 52 |
tty.Close() |
| 53 |
- out, _ := io.ReadAll(pty) |
|
| 53 |
+ out, _ := io.ReadAll(pt) |
|
| 54 | 54 |
assert.Assert(c, err == nil, "out: %v", string(out)) |
| 55 | 55 |
case <-time.After(attachWait): |
| 56 | 56 |
c.Fatal("timed out without attach returning")
|
| ... | ... |
@@ -73,7 +73,7 @@ func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
|
| 73 | 73 |
close(cmdExit) |
| 74 | 74 |
}() |
| 75 | 75 |
|
| 76 |
- assert.Assert(c, waitRun(name) == nil) |
|
| 76 |
+ cli.WaitRun(c, name) |
|
| 77 | 77 |
|
| 78 | 78 |
cpty.Write([]byte{16})
|
| 79 | 79 |
time.Sleep(100 * time.Millisecond) |
| ... | ... |
@@ -123,9 +123,9 @@ func (s *DockerCLIAttachSuite) TestAttachAfterDetach(c *testing.T) {
|
| 123 | 123 |
|
| 124 | 124 |
// TestAttachDetach checks that attach in tty mode can be detached using the long container ID |
| 125 | 125 |
func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
|
| 126 |
- out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") |
|
| 126 |
+ out := cli.DockerCmd(c, "run", "-itd", "busybox", "cat").Stdout() |
|
| 127 | 127 |
id := strings.TrimSpace(out) |
| 128 |
- assert.NilError(c, waitRun(id)) |
|
| 128 |
+ cli.WaitRun(c, id) |
|
| 129 | 129 |
|
| 130 | 130 |
cpty, tty, err := pty.Open() |
| 131 | 131 |
assert.NilError(c, err) |
| ... | ... |
@@ -138,7 +138,7 @@ func (s *DockerCLIAttachSuite) TestAttachDetach(c *testing.T) {
|
| 138 | 138 |
defer stdout.Close() |
| 139 | 139 |
err = cmd.Start() |
| 140 | 140 |
assert.NilError(c, err) |
| 141 |
- assert.NilError(c, waitRun(id)) |
|
| 141 |
+ cli.WaitRun(c, id) |
|
| 142 | 142 |
|
| 143 | 143 |
_, err = cpty.Write([]byte("hello\n"))
|
| 144 | 144 |
assert.NilError(c, err) |