github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/container/attach_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/container"
     9  	"github.com/docker/docker/api/types/network"
    10  	"gotest.tools/v3/assert"
    11  )
    12  
    13  func TestAttachWithTTY(t *testing.T) {
    14  	testAttach(t, true, types.MediaTypeRawStream)
    15  }
    16  
    17  func TestAttachWithoutTTy(t *testing.T) {
    18  	testAttach(t, false, types.MediaTypeMultiplexedStream)
    19  }
    20  
    21  func testAttach(t *testing.T, tty bool, expected string) {
    22  	defer setupTest(t)()
    23  	client := testEnv.APIClient()
    24  
    25  	resp, err := client.ContainerCreate(context.Background(),
    26  		&container.Config{
    27  			Image: "busybox",
    28  			Cmd:   []string{"echo", "hello"},
    29  			Tty:   tty,
    30  		},
    31  		&container.HostConfig{},
    32  		&network.NetworkingConfig{},
    33  		nil,
    34  		"",
    35  	)
    36  	assert.NilError(t, err)
    37  	container := resp.ID
    38  	defer client.ContainerRemove(context.Background(), container, types.ContainerRemoveOptions{
    39  		Force: true,
    40  	})
    41  
    42  	attach, err := client.ContainerAttach(context.Background(), container, types.ContainerAttachOptions{
    43  		Stdout: true,
    44  		Stderr: true,
    45  	})
    46  	assert.NilError(t, err)
    47  	mediaType, ok := attach.MediaType()
    48  	assert.Check(t, ok)
    49  	assert.Check(t, mediaType == expected)
    50  }