moby/integration/container/attach_test.go
Sebastiaan van Stijn 30f09b4a1a
api/types: move ContainerAttachOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-12 11:29:23 +02:00

61 lines
1.4 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/testutil"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestAttach(t *testing.T) {
ctx := 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()
ctx := testutil.StartSpan(ctx, t)
resp, err := apiClient.ContainerCreate(ctx,
&container.Config{
Image: "busybox",
Cmd: []string{"echo", "hello"},
Tty: tc.tty,
},
&container.HostConfig{},
&network.NetworkingConfig{},
nil,
"",
)
assert.NilError(t, err)
attach, err := apiClient.ContainerAttach(ctx, resp.ID, container.AttachOptions{
Stdout: true,
Stderr: true,
})
assert.NilError(t, err)
mediaType, ok := attach.MediaType()
assert.Check(t, ok)
assert.Check(t, is.Equal(mediaType, tc.expectedMediaType))
})
}
}