Calling function returned from setupTest (which calls testEnv.Clean) in
a defer block inside a test that spawns parallel subtests caused the
cleanup function to be called before any of the subtest did anything.
Change the defer expressions to use `t.Cleanup` instead to call it only
after all subtests have also finished.
This only changes tests which have parallel subtests.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
| ... | ... |
@@ -22,7 +22,7 @@ import ( |
| 22 | 22 |
) |
| 23 | 23 |
|
| 24 | 24 |
func TestBuildWithRemoveAndForceRemove(t *testing.T) {
|
| 25 |
- defer setupTest(t)() |
|
| 25 |
+ t.Cleanup(setupTest(t)) |
|
| 26 | 26 |
|
| 27 | 27 |
cases := []struct {
|
| 28 | 28 |
name string |
| ... | ... |
@@ -577,7 +577,7 @@ COPY --from=intermediate C:\\stuff C:\\stuff |
| 577 | 577 |
func TestBuildWithEmptyDockerfile(t *testing.T) {
|
| 578 | 578 |
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "broken in earlier versions") |
| 579 | 579 |
ctx := context.TODO() |
| 580 |
- defer setupTest(t)() |
|
| 580 |
+ t.Cleanup(setupTest(t)) |
|
| 581 | 581 |
|
| 582 | 582 |
tests := []struct {
|
| 583 | 583 |
name string |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
// TestContainerInvalidJSON tests that POST endpoints that expect a body return |
| 14 | 14 |
// the correct error when sending invalid JSON requests. |
| 15 | 15 |
func TestContainerInvalidJSON(t *testing.T) {
|
| 16 |
- defer setupTest(t)() |
|
| 16 |
+ t.Cleanup(setupTest(t)) |
|
| 17 | 17 |
|
| 18 | 18 |
// POST endpoints that accept / expect a JSON body; |
| 19 | 19 |
endpoints := []string{
|
| ... | ... |
@@ -24,7 +24,7 @@ import ( |
| 24 | 24 |
) |
| 25 | 25 |
|
| 26 | 26 |
func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
|
| 27 |
- defer setupTest(t)() |
|
| 27 |
+ t.Cleanup(setupTest(t)) |
|
| 28 | 28 |
client := testEnv.APIClient() |
| 29 | 29 |
|
| 30 | 30 |
testCases := []struct {
|
| ... | ... |
@@ -90,7 +90,7 @@ func TestCreateLinkToNonExistingContainer(t *testing.T) {
|
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
func TestCreateWithInvalidEnv(t *testing.T) {
|
| 93 |
- defer setupTest(t)() |
|
| 93 |
+ t.Cleanup(setupTest(t)) |
|
| 94 | 94 |
client := testEnv.APIClient() |
| 95 | 95 |
|
| 96 | 96 |
testCases := []struct {
|
| ... | ... |
@@ -337,7 +337,7 @@ func TestCreateWithCustomReadonlyPaths(t *testing.T) {
|
| 337 | 337 |
} |
| 338 | 338 |
|
| 339 | 339 |
func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
|
| 340 |
- defer setupTest(t)() |
|
| 340 |
+ t.Cleanup(setupTest(t)) |
|
| 341 | 341 |
client := testEnv.APIClient() |
| 342 | 342 |
ctx := context.Background() |
| 343 | 343 |
|
| ... | ... |
@@ -532,7 +532,7 @@ func TestCreatePlatformSpecificImageNoPlatform(t *testing.T) {
|
| 532 | 532 |
func TestCreateInvalidHostConfig(t *testing.T) {
|
| 533 | 533 |
skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 534 | 534 |
|
| 535 |
- defer setupTest(t)() |
|
| 535 |
+ t.Cleanup(setupTest(t)) |
|
| 536 | 536 |
apiClient := testEnv.APIClient() |
| 537 | 537 |
ctx := context.Background() |
| 538 | 538 |
|
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
// via HostConfig.Devices through to the implementation in hcsshim. |
| 19 | 19 |
func TestWindowsDevices(t *testing.T) {
|
| 20 | 20 |
skip.If(t, testEnv.DaemonInfo.OSType != "windows") |
| 21 |
- defer setupTest(t)() |
|
| 21 |
+ t.Cleanup(setupTest(t)) |
|
| 22 | 22 |
client := testEnv.APIClient() |
| 23 | 23 |
ctx := context.Background() |
| 24 | 24 |
|
| ... | ... |
@@ -91,7 +91,7 @@ func TestContainerNetworkMountsNoChown(t *testing.T) {
|
| 91 | 91 |
func TestMountDaemonRoot(t *testing.T) {
|
| 92 | 92 |
skip.If(t, testEnv.IsRemoteDaemon) |
| 93 | 93 |
|
| 94 |
- defer setupTest(t)() |
|
| 94 |
+ t.Cleanup(setupTest(t)) |
|
| 95 | 95 |
client := testEnv.APIClient() |
| 96 | 96 |
ctx := context.Background() |
| 97 | 97 |
info, err := client.Info(ctx) |
| ... | ... |
@@ -24,7 +24,7 @@ import ( |
| 24 | 24 |
// a timeout works as documented, i.e. in case of negative timeout |
| 25 | 25 |
// waiting is not limited (issue #35311). |
| 26 | 26 |
func TestStopContainerWithTimeout(t *testing.T) {
|
| 27 |
- defer setupTest(t)() |
|
| 27 |
+ t.Cleanup(setupTest(t)) |
|
| 28 | 28 |
client := testEnv.APIClient() |
| 29 | 29 |
ctx := context.Background() |
| 30 | 30 |
|
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
// waiting is not limited (issue #35311). |
| 19 | 19 |
func TestStopContainerWithTimeout(t *testing.T) {
|
| 20 | 20 |
skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 21 |
- defer setupTest(t)() |
|
| 21 |
+ t.Cleanup(setupTest(t)) |
|
| 22 | 22 |
client := testEnv.APIClient() |
| 23 | 23 |
ctx := context.Background() |
| 24 | 24 |
|
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
func TestWaitNonBlocked(t *testing.T) {
|
| 19 |
- defer setupTest(t)() |
|
| 19 |
+ t.Cleanup(setupTest(t)) |
|
| 20 | 20 |
cli := request.NewAPIClient(t) |
| 21 | 21 |
|
| 22 | 22 |
testCases := []struct {
|
| ... | ... |
@@ -59,7 +59,7 @@ func TestWaitBlocked(t *testing.T) {
|
| 59 | 59 |
// Windows busybox does not support trap in this way, not sleep with sub-second |
| 60 | 60 |
// granularity. It will always exit 0x40010004. |
| 61 | 61 |
skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
| 62 |
- defer setupTest(t)() |
|
| 62 |
+ t.Cleanup(setupTest(t)) |
|
| 63 | 63 |
cli := request.NewAPIClient(t) |
| 64 | 64 |
|
| 65 | 65 |
testCases := []struct {
|
| ... | ... |
@@ -104,7 +104,7 @@ func TestWaitBlocked(t *testing.T) {
|
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
func TestWaitConditions(t *testing.T) {
|
| 107 |
- defer setupTest(t)() |
|
| 107 |
+ t.Cleanup(setupTest(t)) |
|
| 108 | 108 |
cli := request.NewAPIClient(t) |
| 109 | 109 |
|
| 110 | 110 |
testCases := []struct {
|
| ... | ... |
@@ -179,7 +179,7 @@ func TestWaitConditions(t *testing.T) {
|
| 179 | 179 |
} |
| 180 | 180 |
|
| 181 | 181 |
func TestWaitRestartedContainer(t *testing.T) {
|
| 182 |
- defer setupTest(t)() |
|
| 182 |
+ t.Cleanup(setupTest(t)) |
|
| 183 | 183 |
cli := request.NewAPIClient(t) |
| 184 | 184 |
|
| 185 | 185 |
testCases := []struct {
|
| ... | ... |
@@ -67,7 +67,7 @@ func TestRunContainerWithBridgeNone(t *testing.T) {
|
| 67 | 67 |
// TestNetworkInvalidJSON tests that POST endpoints that expect a body return |
| 68 | 68 |
// the correct error when sending invalid JSON requests. |
| 69 | 69 |
func TestNetworkInvalidJSON(t *testing.T) {
|
| 70 |
- defer setupTest(t)() |
|
| 70 |
+ t.Cleanup(setupTest(t)) |
|
| 71 | 71 |
|
| 72 | 72 |
// POST endpoints that accept / expect a JSON body; |
| 73 | 73 |
endpoints := []string{
|
| ... | ... |
@@ -126,7 +126,7 @@ func TestNetworkInvalidJSON(t *testing.T) {
|
| 126 | 126 |
// TestNetworkList verifies that /networks returns a list of networks either |
| 127 | 127 |
// with, or without a trailing slash (/networks/). Regression test for https://github.com/moby/moby/issues/24595 |
| 128 | 128 |
func TestNetworkList(t *testing.T) {
|
| 129 |
- defer setupTest(t)() |
|
| 129 |
+ t.Cleanup(setupTest(t)) |
|
| 130 | 130 |
|
| 131 | 131 |
endpoints := []string{
|
| 132 | 132 |
"/networks", |
| ... | ... |
@@ -33,7 +33,7 @@ import ( |
| 33 | 33 |
// TestPluginInvalidJSON tests that POST endpoints that expect a body return |
| 34 | 34 |
// the correct error when sending invalid JSON requests. |
| 35 | 35 |
func TestPluginInvalidJSON(t *testing.T) {
|
| 36 |
- defer setupTest(t)() |
|
| 36 |
+ t.Cleanup(setupTest(t)) |
|
| 37 | 37 |
|
| 38 | 38 |
// POST endpoints that accept / expect a JSON body; |
| 39 | 39 |
endpoints := []string{
|
| ... | ... |
@@ -196,7 +196,7 @@ func TestVolumesInspect(t *testing.T) {
|
| 196 | 196 |
// TestVolumesInvalidJSON tests that POST endpoints that expect a body return |
| 197 | 197 |
// the correct error when sending invalid JSON requests. |
| 198 | 198 |
func TestVolumesInvalidJSON(t *testing.T) {
|
| 199 |
- defer setupTest(t)() |
|
| 199 |
+ t.Cleanup(setupTest(t)) |
|
| 200 | 200 |
|
| 201 | 201 |
// POST endpoints that accept / expect a JSON body; |
| 202 | 202 |
endpoints := []string{"/volumes/create"}
|