فهرست منبع

TestDaemonRestartKillContainers: Fix loop capture

TestDaemonRestartKillContainers test was always executing the last case
(`container created should not be restarted`) because the iterated
variables were not copied correctly.
Capture iterated values by value correctly and rename c to tc.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit fed1c96e10fc246076db43465d0f5a8b9d93d42d)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 2 سال پیش
والد
کامیت
d26e4dab48
1فایلهای تغییر یافته به همراه7 افزوده شده و 8 حذف شده
  1. 7 8
      integration/container/restart_test.go

+ 7 - 8
integration/container/restart_test.go

@@ -58,11 +58,10 @@ func TestDaemonRestartKillContainers(t *testing.T) {
 					d.Stop(t)
 				},
 			} {
+				tc := tc
+				liveRestoreEnabled := liveRestoreEnabled
+				stopDaemon := stopDaemon
 				t.Run(fmt.Sprintf("live-restore=%v/%s/%s", liveRestoreEnabled, tc.desc, fnName), func(t *testing.T) {
-					c := tc
-					liveRestoreEnabled := liveRestoreEnabled
-					stopDaemon := stopDaemon
-
 					t.Parallel()
 
 					d := daemon.New(t)
@@ -77,11 +76,11 @@ func TestDaemonRestartKillContainers(t *testing.T) {
 					defer d.Stop(t)
 					ctx := context.Background()
 
-					resp, err := client.ContainerCreate(ctx, c.config, c.hostConfig, nil, nil, "")
+					resp, err := client.ContainerCreate(ctx, tc.config, tc.hostConfig, nil, nil, "")
 					assert.NilError(t, err)
 					defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
 
-					if c.xStart {
+					if tc.xStart {
 						err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
 						assert.NilError(t, err)
 					}
@@ -89,9 +88,9 @@ func TestDaemonRestartKillContainers(t *testing.T) {
 					stopDaemon(t, d)
 					d.Start(t, args...)
 
-					expected := c.xRunning
+					expected := tc.xRunning
 					if liveRestoreEnabled {
-						expected = c.xRunningLiveRestore
+						expected = tc.xRunningLiveRestore
 					}
 
 					var running bool