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>
| ... | ... |
@@ -2097,63 +2097,65 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) {
|
| 2097 | 2097 |
ctx := context.Background() |
| 2098 | 2098 |
apiclient := testEnv.APIClient() |
| 2099 | 2099 |
for i, x := range cases {
|
| 2100 |
- c.Logf("case %d - config: %v", i, x.spec)
|
|
| 2101 |
- container, err := apiclient.ContainerCreate( |
|
| 2102 |
- ctx, |
|
| 2103 |
- &containertypes.Config{Image: testImg},
|
|
| 2104 |
- &containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}},
|
|
| 2105 |
- &networktypes.NetworkingConfig{},
|
|
| 2106 |
- "") |
|
| 2107 |
- assert.NilError(c, err) |
|
| 2100 |
+ x := x |
|
| 2101 |
+ c.Run(fmt.Sprintf("%d config: %v", i, x.spec), func(c *testing.T) {
|
|
| 2102 |
+ container, err := apiclient.ContainerCreate( |
|
| 2103 |
+ ctx, |
|
| 2104 |
+ &containertypes.Config{Image: testImg},
|
|
| 2105 |
+ &containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}},
|
|
| 2106 |
+ &networktypes.NetworkingConfig{},
|
|
| 2107 |
+ "") |
|
| 2108 |
+ assert.NilError(c, err) |
|
| 2108 | 2109 |
|
| 2109 |
- containerInspect, err := apiclient.ContainerInspect(ctx, container.ID) |
|
| 2110 |
- assert.NilError(c, err) |
|
| 2111 |
- mps := containerInspect.Mounts |
|
| 2112 |
- assert.Assert(c, is.Len(mps, 1)) |
|
| 2113 |
- mountPoint := mps[0] |
|
| 2110 |
+ containerInspect, err := apiclient.ContainerInspect(ctx, container.ID) |
|
| 2111 |
+ assert.NilError(c, err) |
|
| 2112 |
+ mps := containerInspect.Mounts |
|
| 2113 |
+ assert.Assert(c, is.Len(mps, 1)) |
|
| 2114 |
+ mountPoint := mps[0] |
|
| 2114 | 2115 |
|
| 2115 |
- if x.expected.Source != "" {
|
|
| 2116 |
- assert.Check(c, is.Equal(x.expected.Source, mountPoint.Source)) |
|
| 2117 |
- } |
|
| 2118 |
- if x.expected.Name != "" {
|
|
| 2119 |
- assert.Check(c, is.Equal(x.expected.Name, mountPoint.Name)) |
|
| 2120 |
- } |
|
| 2121 |
- if x.expected.Driver != "" {
|
|
| 2122 |
- assert.Check(c, is.Equal(x.expected.Driver, mountPoint.Driver)) |
|
| 2123 |
- } |
|
| 2124 |
- if x.expected.Propagation != "" {
|
|
| 2125 |
- assert.Check(c, is.Equal(x.expected.Propagation, mountPoint.Propagation)) |
|
| 2126 |
- } |
|
| 2127 |
- assert.Check(c, is.Equal(x.expected.RW, mountPoint.RW)) |
|
| 2128 |
- assert.Check(c, is.Equal(x.expected.Type, mountPoint.Type)) |
|
| 2129 |
- assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode)) |
|
| 2130 |
- assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination)) |
|
| 2116 |
+ if x.expected.Source != "" {
|
|
| 2117 |
+ assert.Check(c, is.Equal(x.expected.Source, mountPoint.Source)) |
|
| 2118 |
+ } |
|
| 2119 |
+ if x.expected.Name != "" {
|
|
| 2120 |
+ assert.Check(c, is.Equal(x.expected.Name, mountPoint.Name)) |
|
| 2121 |
+ } |
|
| 2122 |
+ if x.expected.Driver != "" {
|
|
| 2123 |
+ assert.Check(c, is.Equal(x.expected.Driver, mountPoint.Driver)) |
|
| 2124 |
+ } |
|
| 2125 |
+ if x.expected.Propagation != "" {
|
|
| 2126 |
+ assert.Check(c, is.Equal(x.expected.Propagation, mountPoint.Propagation)) |
|
| 2127 |
+ } |
|
| 2128 |
+ assert.Check(c, is.Equal(x.expected.RW, mountPoint.RW)) |
|
| 2129 |
+ assert.Check(c, is.Equal(x.expected.Type, mountPoint.Type)) |
|
| 2130 |
+ assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode)) |
|
| 2131 |
+ assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination)) |
|
| 2131 | 2132 |
|
| 2132 |
- err = apiclient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{})
|
|
| 2133 |
- assert.NilError(c, err) |
|
| 2134 |
- poll.WaitOn(c, containerExit(apiclient, container.ID), poll.WithDelay(time.Second)) |
|
| 2133 |
+ err = apiclient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{})
|
|
| 2134 |
+ assert.NilError(c, err) |
|
| 2135 |
+ poll.WaitOn(c, containerExit(apiclient, container.ID), poll.WithDelay(time.Second)) |
|
| 2135 | 2136 |
|
| 2136 |
- err = apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{
|
|
| 2137 |
- RemoveVolumes: true, |
|
| 2138 |
- Force: true, |
|
| 2139 |
- }) |
|
| 2140 |
- assert.NilError(c, err) |
|
| 2137 |
+ err = apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{
|
|
| 2138 |
+ RemoveVolumes: true, |
|
| 2139 |
+ Force: true, |
|
| 2140 |
+ }) |
|
| 2141 |
+ assert.NilError(c, err) |
|
| 2141 | 2142 |
|
| 2142 |
- switch {
|
|
| 2143 |
+ switch {
|
|
| 2143 | 2144 |
|
| 2144 |
- // Named volumes still exist after the container is removed |
|
| 2145 |
- case x.spec.Type == "volume" && len(x.spec.Source) > 0: |
|
| 2146 |
- _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) |
|
| 2147 |
- assert.NilError(c, err) |
|
| 2145 |
+ // Named volumes still exist after the container is removed |
|
| 2146 |
+ case x.spec.Type == "volume" && len(x.spec.Source) > 0: |
|
| 2147 |
+ _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) |
|
| 2148 |
+ assert.NilError(c, err) |
|
| 2148 | 2149 |
|
| 2149 |
- // Bind mounts are never removed with the container |
|
| 2150 |
- case x.spec.Type == "bind": |
|
| 2150 |
+ // Bind mounts are never removed with the container |
|
| 2151 |
+ case x.spec.Type == "bind": |
|
| 2151 | 2152 |
|
| 2152 |
- // anonymous volumes are removed |
|
| 2153 |
- default: |
|
| 2154 |
- _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) |
|
| 2155 |
- assert.Check(c, client.IsErrNotFound(err)) |
|
| 2156 |
- } |
|
| 2153 |
+ // anonymous volumes are removed |
|
| 2154 |
+ default: |
|
| 2155 |
+ _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) |
|
| 2156 |
+ assert.Check(c, client.IsErrNotFound(err)) |
|
| 2157 |
+ } |
|
| 2158 |
+ }) |
|
| 2157 | 2159 |
} |
| 2158 | 2160 |
} |
| 2159 | 2161 |
|