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"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/icmd"
|
2017-11-15 22:18:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAttachExitCode(t *testing.T) {
|
2023-11-20 05:10:29 -05:00
|
|
|
const exitCode = 21
|
|
|
|
result := icmd.RunCommand("docker", "run", "-d", "-i", "--rm", fixtures.AlpineImage, "sh", "-c", fmt.Sprintf("read; exit %d", exitCode))
|
|
|
|
result.Assert(t, icmd.Success)
|
2017-11-17 12:45:27 -05:00
|
|
|
|
2023-11-20 05:10:29 -05:00
|
|
|
containerID := strings.TrimSpace(result.Stdout())
|
2017-11-17 12:45:27 -05:00
|
|
|
|
2023-11-20 05:10:29 -05:00
|
|
|
result = icmd.RunCmd(icmd.Command("docker", "attach", containerID), withStdinNewline)
|
|
|
|
result.Assert(t, icmd.Expected{ExitCode: exitCode})
|
2017-11-17 12:45:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func withStdinNewline(cmd *icmd.Cmd) {
|
|
|
|
cmd.Stdin = strings.NewReader("\n")
|
2017-11-15 22:18:23 -05:00
|
|
|
}
|