integration-cli: TestContainersAPICreateMountsCreate: use subtests
Before: --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate (24.21s) docker_api_containers_test.go:2100: case 0 - config: {volume /foo false <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 1 - config: {volume /foo/ false <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 2 - config: {volume test1 /foo false <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 3 - config: {volume test2 /foo true <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 4 - config: {volume test3 /foo false <nil> 0xc000876640 <nil>} docker_api_containers_test.go:2100: case 5 - config: {bind /tmp/test-mounts-api-1770842294 /foo false <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 6 - config: {bind /tmp/test-mounts-api-1770842294 /foo true <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 7 - config: {bind /tmp/test-mounts-api-3832384157 /foo false <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 8 - config: {bind /tmp/test-mounts-api-3832384157 /foo true <nil> <nil> <nil>} docker_api_containers_test.go:2100: case 9 - config: {bind /tmp/test-mounts-api-3832384157 /foo true 0xc000876aa0 <nil> <nil>} docker_api_containers_test.go:2100: case 10 - config: {volume /foo false <nil> 0xc000876ac0 <nil>} docker_api_containers_test.go:2100: case 11 - config: {volume /foo/ false <nil> 0xc000876ae0 <nil>} docker_api_containers_test.go:2100: case 12 - config: {volume test4 /foo false <nil> 0xc000876b00 <nil>} docker_api_containers_test.go:2100: case 13 - config: {volume test5 /foo true <nil> 0xc000876b20 <nil>} After: --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate (63.59s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/0_config:_{volume__/foo_false__<nil>_<nil>_<nil>} (2.98s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/1_config:_{volume__/foo/_false__<nil>_<nil>_<nil>} (2.11s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/2_config:_{volume_test1_/foo_false__<nil>_<nil>_<nil>} (2.26s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/3_config:_{volume_test2_/foo_true__<nil>_<nil>_<nil>} (7.78s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/4_config:_{volume_test3_/foo_false__<nil>_0xc00000ecc0_<nil>} (25.19s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/5_config:_{bind_/tmp/test-mounts-api-1123034866_/foo_false__<nil>_<nil>_<nil>} (2.21s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/6_config:_{bind_/tmp/test-mounts-api-1123034866_/foo_true__<nil>_<nil>_<nil>} (2.21s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/7_config:_{bind_/tmp/test-mounts-api-3533158313_/foo_false__<nil>_<nil>_<nil>} (2.16s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/8_config:_{bind_/tmp/test-mounts-api-3533158313_/foo_true__<nil>_<nil>_<nil>} (2.18s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/9_config:_{bind_/tmp/test-mounts-api-3533158313_/foo_true__0xc00000f760_<nil>_<nil>} (2.18s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/10_config:_{volume__/foo_false__<nil>_0xc00000f780_<nil>} (2.25s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/11_config:_{volume__/foo/_false__<nil>_0xc00000f7e0_<nil>} (2.37s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/12_config:_{volume_test4_/foo_false__<nil>_0xc00000f800_<nil>} (2.28s) --- PASS: TestDockerSuite/TestContainersAPICreateMountsCreate/13_config:_{volume_test5_/foo_true__<nil>_0xc00000f820_<nil>} (2.44s) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
69c4a4f4a2
commit
9ca5ffd5f7
|
@ -2097,63 +2097,65 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) {
|
|||
ctx := context.Background()
|
||||
apiclient := testEnv.APIClient()
|
||||
for i, x := range cases {
|
||||
c.Logf("case %d - config: %v", i, x.spec)
|
||||
container, err := apiclient.ContainerCreate(
|
||||
ctx,
|
||||
&containertypes.Config{Image: testImg},
|
||||
&containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}},
|
||||
&networktypes.NetworkingConfig{},
|
||||
"")
|
||||
assert.NilError(c, err)
|
||||
|
||||
containerInspect, err := apiclient.ContainerInspect(ctx, container.ID)
|
||||
assert.NilError(c, err)
|
||||
mps := containerInspect.Mounts
|
||||
assert.Assert(c, is.Len(mps, 1))
|
||||
mountPoint := mps[0]
|
||||
|
||||
if x.expected.Source != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Source, mountPoint.Source))
|
||||
}
|
||||
if x.expected.Name != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Name, mountPoint.Name))
|
||||
}
|
||||
if x.expected.Driver != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Driver, mountPoint.Driver))
|
||||
}
|
||||
if x.expected.Propagation != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Propagation, mountPoint.Propagation))
|
||||
}
|
||||
assert.Check(c, is.Equal(x.expected.RW, mountPoint.RW))
|
||||
assert.Check(c, is.Equal(x.expected.Type, mountPoint.Type))
|
||||
assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode))
|
||||
assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination))
|
||||
|
||||
err = apiclient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{})
|
||||
assert.NilError(c, err)
|
||||
poll.WaitOn(c, containerExit(apiclient, container.ID), poll.WithDelay(time.Second))
|
||||
|
||||
err = apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
Force: true,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
switch {
|
||||
|
||||
// Named volumes still exist after the container is removed
|
||||
case x.spec.Type == "volume" && len(x.spec.Source) > 0:
|
||||
_, err := apiclient.VolumeInspect(ctx, mountPoint.Name)
|
||||
x := x
|
||||
c.Run(fmt.Sprintf("%d config: %v", i, x.spec), func(c *testing.T) {
|
||||
container, err := apiclient.ContainerCreate(
|
||||
ctx,
|
||||
&containertypes.Config{Image: testImg},
|
||||
&containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}},
|
||||
&networktypes.NetworkingConfig{},
|
||||
"")
|
||||
assert.NilError(c, err)
|
||||
|
||||
// Bind mounts are never removed with the container
|
||||
case x.spec.Type == "bind":
|
||||
containerInspect, err := apiclient.ContainerInspect(ctx, container.ID)
|
||||
assert.NilError(c, err)
|
||||
mps := containerInspect.Mounts
|
||||
assert.Assert(c, is.Len(mps, 1))
|
||||
mountPoint := mps[0]
|
||||
|
||||
// anonymous volumes are removed
|
||||
default:
|
||||
_, err := apiclient.VolumeInspect(ctx, mountPoint.Name)
|
||||
assert.Check(c, client.IsErrNotFound(err))
|
||||
}
|
||||
if x.expected.Source != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Source, mountPoint.Source))
|
||||
}
|
||||
if x.expected.Name != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Name, mountPoint.Name))
|
||||
}
|
||||
if x.expected.Driver != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Driver, mountPoint.Driver))
|
||||
}
|
||||
if x.expected.Propagation != "" {
|
||||
assert.Check(c, is.Equal(x.expected.Propagation, mountPoint.Propagation))
|
||||
}
|
||||
assert.Check(c, is.Equal(x.expected.RW, mountPoint.RW))
|
||||
assert.Check(c, is.Equal(x.expected.Type, mountPoint.Type))
|
||||
assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode))
|
||||
assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination))
|
||||
|
||||
err = apiclient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{})
|
||||
assert.NilError(c, err)
|
||||
poll.WaitOn(c, containerExit(apiclient, container.ID), poll.WithDelay(time.Second))
|
||||
|
||||
err = apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
Force: true,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
switch {
|
||||
|
||||
// Named volumes still exist after the container is removed
|
||||
case x.spec.Type == "volume" && len(x.spec.Source) > 0:
|
||||
_, err := apiclient.VolumeInspect(ctx, mountPoint.Name)
|
||||
assert.NilError(c, err)
|
||||
|
||||
// Bind mounts are never removed with the container
|
||||
case x.spec.Type == "bind":
|
||||
|
||||
// anonymous volumes are removed
|
||||
default:
|
||||
_, err := apiclient.VolumeInspect(ctx, mountPoint.Name)
|
||||
assert.Check(c, client.IsErrNotFound(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue