github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/e2e/container/attach_test.go (about)

     1  package container
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/docker/cli/e2e/internal/fixtures"
     9  	"gotest.tools/icmd"
    10  )
    11  
    12  func TestAttachExitCode(t *testing.T) {
    13  	containerID := runBackgroundContainsWithExitCode(t, 21)
    14  
    15  	result := icmd.RunCmd(
    16  		icmd.Command("docker", "attach", containerID),
    17  		withStdinNewline)
    18  
    19  	result.Assert(t, icmd.Expected{ExitCode: 21})
    20  }
    21  
    22  func runBackgroundContainsWithExitCode(t *testing.T, exitcode int) string {
    23  	result := icmd.RunCommand("docker", "run", "-d", "-i", "--rm", fixtures.AlpineImage,
    24  		"sh", "-c", fmt.Sprintf("read; exit %d", exitcode))
    25  	result.Assert(t, icmd.Success)
    26  	return strings.TrimSpace(result.Stdout())
    27  }
    28  
    29  func withStdinNewline(cmd *icmd.Cmd) {
    30  	cmd.Stdin = strings.NewReader("\n")
    31  }