Fix TestAttachExitCode

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-11-17 12:45:27 -05:00 committed by Kenfe-Mickael Laventure
parent 66661761d5
commit bace33d7a8
No known key found for this signature in database
GPG Key ID: 40CF16616B361216
1 changed files with 19 additions and 7 deletions

View File

@ -1,17 +1,29 @@
package container
import (
"strings"
"testing"
"github.com/gotestyourself/gotestyourself/icmd"
)
func TestAttachExitCode(t *testing.T) {
cName := "test-attach-exit-code"
icmd.RunCommand("docker", "run", "-d", "--rm", "--name", cName,
alpineImage, "sh", "-c", "sleep 5 ; exit 21").Assert(t, icmd.Success)
cmd := icmd.Command("docker", "wait", cName)
res := icmd.StartCmd(cmd)
icmd.RunCommand("docker", "attach", cName).Assert(t, icmd.Expected{ExitCode: 21})
icmd.WaitOnCmd(8, res).Assert(t, icmd.Expected{ExitCode: 0, Out: "21"})
containerID := runBackgroundContainsWithExitCode(t, 21)
result := icmd.RunCmd(
icmd.Command("docker", "attach", containerID),
withStdinNewline)
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")
}