Files
docker-cli/e2e/container/attach_test.go
Vincent Demeester ae03dd7f46 Handle some TODOs in tests
Use more gotestyourself for `env.Patch`, and `icmd.RunCommand`

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-04-23 14:13:52 +02:00

32 lines
771 B
Go

package container
import (
"fmt"
"strings"
"testing"
"github.com/docker/cli/e2e/internal/fixtures"
"github.com/gotestyourself/gotestyourself/icmd"
)
func TestAttachExitCode(t *testing.T) {
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.RunCommand("docker", "run", "-d", "-i", "--rm", fixtures.AlpineImage,
"sh", "-c", fmt.Sprintf("read; exit %d", exitcode))
result.Assert(t, icmd.Success)
return strings.TrimSpace(result.Stdout())
}
func withStdinNewline(cmd *icmd.Cmd) {
cmd.Stdin = strings.NewReader("\n")
}