integration/container: use subtests for TestAttach
- Combine TestAttachWithTTY and TestAttachWithoutTTy to a single test using sub-tests - Set up and tear-down the test-environment once - Remove redundant client.ContainerRemove, as it's taken care of by testEnv.Clean() - Run both tests in parallel make TEST_FILTER=TestAttach DOCKER_GRAPHDRIVER=overlay2 TESTDEBUG=1 test-integration Loaded image: busybox:latest Loaded image: busybox:glibc Loaded image: debian:bullseye-slim Loaded image: hello-world:latest Loaded image: arm32v7/hello-world:latest INFO: Testing against a local daemon === RUN TestAttach === RUN TestAttach/without_TTY === PAUSE TestAttach/without_TTY === RUN TestAttach/with_TTY === PAUSE TestAttach/with_TTY === CONT TestAttach/without_TTY === CONT TestAttach/with_TTY --- PASS: TestAttach (0.00s) --- PASS: TestAttach/without_TTY (0.03s) --- PASS: TestAttach/with_TTY (0.03s) PASS DONE 3 tests in 1.347s Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
193f16238b
commit
79c72390b9
1 changed files with 43 additions and 34 deletions
|
@ -8,25 +8,37 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
is "gotest.tools/v3/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAttachWithTTY(t *testing.T) {
|
func TestAttach(t *testing.T) {
|
||||||
testAttach(t, true, types.MediaTypeRawStream)
|
t.Cleanup(setupTest(t))
|
||||||
}
|
|
||||||
|
|
||||||
func TestAttachWithoutTTy(t *testing.T) {
|
|
||||||
testAttach(t, false, types.MediaTypeMultiplexedStream)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAttach(t *testing.T, tty bool, expected string) {
|
|
||||||
defer setupTest(t)()
|
|
||||||
client := testEnv.APIClient()
|
client := 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 := client.ContainerCreate(context.Background(),
|
resp, err := client.ContainerCreate(context.Background(),
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Image: "busybox",
|
Image: "busybox",
|
||||||
Cmd: []string{"echo", "hello"},
|
Cmd: []string{"echo", "hello"},
|
||||||
Tty: tty,
|
Tty: tc.tty,
|
||||||
},
|
},
|
||||||
&container.HostConfig{},
|
&container.HostConfig{},
|
||||||
&network.NetworkingConfig{},
|
&network.NetworkingConfig{},
|
||||||
|
@ -34,17 +46,14 @@ func testAttach(t *testing.T, tty bool, expected string) {
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
container := resp.ID
|
attach, err := client.ContainerAttach(context.Background(), resp.ID, types.ContainerAttachOptions{
|
||||||
defer client.ContainerRemove(context.Background(), container, types.ContainerRemoveOptions{
|
|
||||||
Force: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
attach, err := client.ContainerAttach(context.Background(), container, types.ContainerAttachOptions{
|
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
Stderr: true,
|
Stderr: true,
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
mediaType, ok := attach.MediaType()
|
mediaType, ok := attach.MediaType()
|
||||||
assert.Check(t, ok)
|
assert.Check(t, ok)
|
||||||
assert.Check(t, mediaType == expected)
|
assert.Check(t, is.Equal(mediaType, tc.expectedMediaType))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue