2017-11-15 22:18:23 -05:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2018-04-23 08:13:52 -04:00
|
|
|
"fmt"
|
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 {
|
2018-04-23 08:13:52 -04:00
|
|
|
result := icmd.RunCommand("docker", "run", "-d", "-i", "--rm", fixtures.AlpineImage,
|
|
|
|
"sh", "-c", fmt.Sprintf("read; exit %d", 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
|
|
|
}
|