1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package container // import "github.com/docker/docker/integration/container"
- import (
- "context"
- "testing"
- "github.com/docker/docker/api/types"
- "github.com/docker/docker/api/types/container"
- "github.com/docker/docker/api/types/network"
- "gotest.tools/v3/assert"
- is "gotest.tools/v3/assert/cmp"
- )
- func TestAttach(t *testing.T) {
- t.Cleanup(setupTest(t))
- apiClient := testEnv.APIClient()
- tests := []struct {
- doc string
- tty bool
- expectedMediaType string
- }{
- {
- doc: "without TTY",
- expectedMediaType: types.MediaTypeMultiplexedStream,
- },
- {
- doc: "with TTY",
- tty: true,
- expectedMediaType: types.MediaTypeRawStream,
- },
- }
- for _, tc := range tests {
- tc := tc
- t.Run(tc.doc, func(t *testing.T) {
- t.Parallel()
- resp, err := apiClient.ContainerCreate(context.Background(),
- &container.Config{
- Image: "busybox",
- Cmd: []string{"echo", "hello"},
- Tty: tc.tty,
- },
- &container.HostConfig{},
- &network.NetworkingConfig{},
- nil,
- "",
- )
- assert.NilError(t, err)
- attach, err := apiClient.ContainerAttach(context.Background(), resp.ID, types.ContainerAttachOptions{
- Stdout: true,
- Stderr: true,
- })
- assert.NilError(t, err)
- mediaType, ok := attach.MediaType()
- assert.Check(t, ok)
- assert.Check(t, is.Equal(mediaType, tc.expectedMediaType))
- })
- }
- }
|