2017-11-15 22:18:23 -05:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2017-11-17 12:45:27 -05:00
|
|
|
"strings"
|
2017-11-15 22:18:23 -05:00
|
|
|
"testing"
|
|
|
|
|
2018-01-22 18:09:47 -05:00
|
|
|
"github.com/docker/cli/e2e/internal/fixtures"
|
2017-11-15 22:18:23 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAttachExitCode(t *testing.T) {
|
2017-11-17 12:45:27 -05:00
|
|
|
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,
|
2018-01-22 18:09:47 -05:00
|
|
|
"docker run -d -i --rm %s sh -c 'read; exit %d'", fixtures.AlpineImage, exitcode))
|
2017-11-17 12:45:27 -05:00
|
|
|
result.Assert(t, icmd.Success)
|
|
|
|
return strings.TrimSpace(result.Stdout())
|
|
|
|
}
|
|
|
|
|
|
|
|
func withStdinNewline(cmd *icmd.Cmd) {
|
|
|
|
cmd.Stdin = strings.NewReader("\n")
|
2017-11-15 22:18:23 -05:00
|
|
|
}
|