mirror of https://github.com/docker/cli.git
Fix TestAttachExitCode
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
66661761d5
commit
bace33d7a8
|
@ -1,17 +1,29 @@
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gotestyourself/gotestyourself/icmd"
|
"github.com/gotestyourself/gotestyourself/icmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAttachExitCode(t *testing.T) {
|
func TestAttachExitCode(t *testing.T) {
|
||||||
cName := "test-attach-exit-code"
|
containerID := runBackgroundContainsWithExitCode(t, 21)
|
||||||
icmd.RunCommand("docker", "run", "-d", "--rm", "--name", cName,
|
|
||||||
alpineImage, "sh", "-c", "sleep 5 ; exit 21").Assert(t, icmd.Success)
|
result := icmd.RunCmd(
|
||||||
cmd := icmd.Command("docker", "wait", cName)
|
icmd.Command("docker", "attach", containerID),
|
||||||
res := icmd.StartCmd(cmd)
|
withStdinNewline)
|
||||||
icmd.RunCommand("docker", "attach", cName).Assert(t, icmd.Expected{ExitCode: 21})
|
|
||||||
icmd.WaitOnCmd(8, res).Assert(t, icmd.Expected{ExitCode: 0, Out: "21"})
|
result.Assert(t, icmd.Expected{ExitCode: 21})
|
||||||
|
}
|
||||||
|
|
||||||
|
func runBackgroundContainsWithExitCode(t *testing.T, exitcode int) string {
|
||||||
|
result := icmd.RunCmd(shell(t,
|
||||||
|
"docker run -d -i --rm %s sh -c 'read; exit %d'", alpineImage, exitcode))
|
||||||
|
result.Assert(t, icmd.Success)
|
||||||
|
return strings.TrimSpace(result.Stdout())
|
||||||
|
}
|
||||||
|
|
||||||
|
func withStdinNewline(cmd *icmd.Cmd) {
|
||||||
|
cmd.Stdin = strings.NewReader("\n")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue