Skip to content

Commit e84bf6c

Browse files
dnephinmlaventure
authored andcommitted
Fix TestAttachExitCode
Signed-off-by: Daniel Nephin <dnephin@docker.com>
1 parent 0074a18 commit e84bf6c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

e2e/container/attach_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
package container
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/gotestyourself/gotestyourself/icmd"
78
)
89

910
func TestAttachExitCode(t *testing.T) {
10-
cName := "test-attach-exit-code"
11-
icmd.RunCommand("docker", "run", "-d", "--rm", "--name", cName,
12-
alpineImage, "sh", "-c", "sleep 5 ; exit 21").Assert(t, icmd.Success)
13-
cmd := icmd.Command("docker", "wait", cName)
14-
res := icmd.StartCmd(cmd)
15-
icmd.RunCommand("docker", "attach", cName).Assert(t, icmd.Expected{ExitCode: 21})
16-
icmd.WaitOnCmd(8, res).Assert(t, icmd.Expected{ExitCode: 0, Out: "21"})
11+
containerID := runBackgroundContainsWithExitCode(t, 21)
12+
13+
result := icmd.RunCmd(
14+
icmd.Command("docker", "attach", containerID),
15+
withStdinNewline)
16+
17+
result.Assert(t, icmd.Expected{ExitCode: 21})
18+
}
19+
20+
func runBackgroundContainsWithExitCode(t *testing.T, exitcode int) string {
21+
result := icmd.RunCmd(shell(t,
22+
"docker run -d -i --rm %s sh -c 'read; exit %d'", alpineImage, exitcode))
23+
result.Assert(t, icmd.Success)
24+
return strings.TrimSpace(result.Stdout())
25+
}
26+
27+
func withStdinNewline(cmd *icmd.Cmd) {
28+
cmd.Stdin = strings.NewReader("\n")
1729
}

0 commit comments

Comments
 (0)