Use t.Run for /pkg/cri tests
A majority of the tests in /pkg/cri are testing/validating multiple things per test (generally spec or options validations). This flow lends itself well to using *testing.T's Run method to run each thing as a subtest so `go test` output can actually display which subtest failed/passed. Some of the tests in the packages in pkg/cri already did this, but a bunch simply logged what sub-testcase was currently running without invoking t.Run. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
This commit is contained in:
		| @@ -236,7 +236,7 @@ func TestRedirectLogs(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			rc := io.NopCloser(strings.NewReader(test.input)) | 			rc := io.NopCloser(strings.NewReader(test.input)) | ||||||
| 			buf := bytes.NewBuffer(nil) | 			buf := bytes.NewBuffer(nil) | ||||||
| 			wc := cioutil.NewNopWriteCloser(buf) | 			wc := cioutil.NewNopWriteCloser(buf) | ||||||
| @@ -254,5 +254,6 @@ func TestRedirectLogs(t *testing.T) { | |||||||
| 				assert.Equal(t, string(test.tag[i]), fields[2]) | 				assert.Equal(t, string(test.tag[i]), fields[2]) | ||||||
| 				assert.Equal(t, test.content[i], fields[3]) | 				assert.Equal(t, test.content[i], fields[3]) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -238,7 +238,7 @@ func TestContainerCapabilities(t *testing.T) { | |||||||
| 			excludes: util.SubtractStringSlice(allCaps, "CAP_SYS_ADMIN"), | 			excludes: util.SubtractStringSlice(allCaps, "CAP_SYS_ADMIN"), | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() | 			containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() | ||||||
| 			ociRuntime := config.Runtime{} | 			ociRuntime := config.Runtime{} | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| @@ -266,6 +266,7 @@ func TestContainerCapabilities(t *testing.T) { | |||||||
| 			} | 			} | ||||||
| 			assert.Empty(t, spec.Process.Capabilities.Inheritable) | 			assert.Empty(t, spec.Process.Capabilities.Inheritable) | ||||||
| 			assert.Empty(t, spec.Process.Capabilities.Ambient) | 			assert.Empty(t, spec.Process.Capabilities.Ambient) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -425,7 +426,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) { | |||||||
| 			expectError:         false, | 			expectError:         false, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			containerConfig.Linux.SecurityContext.Privileged = test.containerPrivileged | 			containerConfig.Linux.SecurityContext.Privileged = test.containerPrivileged | ||||||
| 			sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{ | 			sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{ | ||||||
| 				Privileged: test.sandboxPrivileged, | 				Privileged: test.sandboxPrivileged, | ||||||
| @@ -436,6 +437,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) { | |||||||
| 			} else { | 			} else { | ||||||
| 				assert.NoError(t, err) | 				assert.NoError(t, err) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -587,6 +589,7 @@ func TestContainerMounts(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			config := &runtime.ContainerConfig{ | 			config := &runtime.ContainerConfig{ | ||||||
| 				Metadata: &runtime.ContainerMetadata{ | 				Metadata: &runtime.ContainerMetadata{ | ||||||
| 					Name:    "test-name", | 					Name:    "test-name", | ||||||
| @@ -601,6 +604,7 @@ func TestContainerMounts(t *testing.T) { | |||||||
| 			c.os.(*ostesting.FakeOS).StatFn = test.statFn | 			c.os.(*ostesting.FakeOS).StatFn = test.statFn | ||||||
| 			mounts := c.containerMounts(testSandboxID, config) | 			mounts := c.containerMounts(testSandboxID, config) | ||||||
| 			assert.Equal(t, test.expectedMounts, mounts, desc) | 			assert.Equal(t, test.expectedMounts, mounts, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -627,8 +631,7 @@ func TestPrivilegedBindMount(t *testing.T) { | |||||||
| 			expectedCgroupFSRO: false, | 			expectedCgroupFSRO: false, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
|  |  | ||||||
| 			containerConfig.Linux.SecurityContext.Privileged = test.privileged | 			containerConfig.Linux.SecurityContext.Privileged = test.privileged | ||||||
| 			sandboxConfig.Linux.SecurityContext.Privileged = test.privileged | 			sandboxConfig.Linux.SecurityContext.Privileged = test.privileged | ||||||
|  |  | ||||||
| @@ -645,6 +648,7 @@ func TestPrivilegedBindMount(t *testing.T) { | |||||||
| 			} else { | 			} else { | ||||||
| 				checkMount(t, spec.Mounts, "cgroup", "/sys/fs/cgroup", "cgroup", []string{"rw"}, []string{"ro"}) | 				checkMount(t, spec.Mounts, "cgroup", "/sys/fs/cgroup", "cgroup", []string{"rw"}, []string{"ro"}) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -736,7 +740,7 @@ func TestMountPropagation(t *testing.T) { | |||||||
| 			expectErr:         true, | 			expectErr:         true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn | 			c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn | ||||||
| 			config, _, _, _ := getCreateContainerTestData() | 			config, _, _, _ := getCreateContainerTestData() | ||||||
| @@ -751,6 +755,7 @@ func TestMountPropagation(t *testing.T) { | |||||||
| 				require.NoError(t, err) | 				require.NoError(t, err) | ||||||
| 				checkMount(t, spec.Mounts, test.criMount.HostPath, test.criMount.ContainerPath, "bind", test.optionsCheck, nil) | 				checkMount(t, spec.Mounts, test.criMount.HostPath, test.criMount.ContainerPath, "bind", test.optionsCheck, nil) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -787,11 +792,12 @@ func TestPidNamespace(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS} | 			containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS} | ||||||
| 			spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime) | 			spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime) | ||||||
| 			require.NoError(t, err) | 			require.NoError(t, err) | ||||||
| 			assert.Contains(t, spec.Linux.Namespaces, test.expected) | 			assert.Contains(t, spec.Linux.Namespaces, test.expected) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -920,7 +926,7 @@ func TestGenerateSeccompSecurityProfileSpecOpts(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Run(fmt.Sprintf("TestCase %q", desc), func(t *testing.T) { | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			cri := &criService{} | 			cri := &criService{} | ||||||
| 			cri.config.UnsetSeccompProfile = test.defaultProfile | 			cri.config.UnsetSeccompProfile = test.defaultProfile | ||||||
| 			ssp := test.sp | 			ssp := test.sp | ||||||
| @@ -1073,7 +1079,7 @@ func TestGenerateApparmorSpecOpts(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			asp := test.sp | 			asp := test.sp | ||||||
| 			csp, err := generateApparmorSecurityProfile(test.profile) | 			csp, err := generateApparmorSecurityProfile(test.profile) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| @@ -1096,6 +1102,7 @@ func TestGenerateApparmorSpecOpts(t *testing.T) { | |||||||
| 					assert.NoError(t, err) | 					assert.NoError(t, err) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1169,7 +1176,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) { | |||||||
| 			privileged:       true, | 			privileged:       true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c.config.DisableProcMount = test.disableProcMount | 			c.config.DisableProcMount = test.disableProcMount | ||||||
| 			containerConfig.Linux.SecurityContext.MaskedPaths = test.masked | 			containerConfig.Linux.SecurityContext.MaskedPaths = test.masked | ||||||
| 			containerConfig.Linux.SecurityContext.ReadonlyPaths = test.readonly | 			containerConfig.Linux.SecurityContext.ReadonlyPaths = test.readonly | ||||||
| @@ -1184,6 +1191,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) { | |||||||
| 			} | 			} | ||||||
| 			assert.Equal(t, test.expectedMasked, spec.Linux.MaskedPaths) | 			assert.Equal(t, test.expectedMasked, spec.Linux.MaskedPaths) | ||||||
| 			assert.Equal(t, test.expectedReadonly, spec.Linux.ReadonlyPaths) | 			assert.Equal(t, test.expectedReadonly, spec.Linux.ReadonlyPaths) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1219,7 +1227,7 @@ func TestHostname(t *testing.T) { | |||||||
| 			expectedEnv: "HOSTNAME=real-hostname", | 			expectedEnv: "HOSTNAME=real-hostname", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			sandboxConfig.Hostname = test.hostname | 			sandboxConfig.Hostname = test.hostname | ||||||
| 			sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{ | 			sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{ | ||||||
| 				NamespaceOptions: &runtime.NamespaceOption{Network: test.networkNs}, | 				NamespaceOptions: &runtime.NamespaceOption{Network: test.networkNs}, | ||||||
| @@ -1228,6 +1236,7 @@ func TestHostname(t *testing.T) { | |||||||
| 			require.NoError(t, err) | 			require.NoError(t, err) | ||||||
| 			specCheck(t, testID, testSandboxID, testPid, spec) | 			specCheck(t, testID, testSandboxID, testPid, spec) | ||||||
| 			assert.Contains(t, spec.Process.Env, test.expectedEnv) | 			assert.Contains(t, spec.Process.Env, test.expectedEnv) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1363,8 +1372,7 @@ func TestNonRootUserAndDevices(t *testing.T) { | |||||||
| 			expectedDeviceGID:                  *testDevice.GID, | 			expectedDeviceGID:                  *testDevice.GID, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
|  |  | ||||||
| 			c.config.DeviceOwnershipFromSecurityContext = test.deviceOwnershipFromSecurityContext | 			c.config.DeviceOwnershipFromSecurityContext = test.deviceOwnershipFromSecurityContext | ||||||
| 			containerConfig.Linux.SecurityContext.RunAsUser = test.uid | 			containerConfig.Linux.SecurityContext.RunAsUser = test.uid | ||||||
| 			containerConfig.Linux.SecurityContext.RunAsGroup = test.gid | 			containerConfig.Linux.SecurityContext.RunAsGroup = test.gid | ||||||
| @@ -1381,6 +1389,7 @@ func TestNonRootUserAndDevices(t *testing.T) { | |||||||
|  |  | ||||||
| 			assert.Equal(t, test.expectedDeviceUID, *spec.Linux.Devices[0].UID) | 			assert.Equal(t, test.expectedDeviceUID, *spec.Linux.Devices[0].UID) | ||||||
| 			assert.Equal(t, test.expectedDeviceGID, *spec.Linux.Devices[0].GID) | 			assert.Equal(t, test.expectedDeviceGID, *spec.Linux.Devices[0].GID) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1434,8 +1443,7 @@ func TestPrivilegedDevices(t *testing.T) { | |||||||
| 			expectAllDevicesAllowed: true, | 			expectAllDevicesAllowed: true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
|  |  | ||||||
| 			containerConfig.Linux.SecurityContext.Privileged = test.privileged | 			containerConfig.Linux.SecurityContext.Privileged = test.privileged | ||||||
| 			sandboxConfig.Linux.SecurityContext.Privileged = test.privileged | 			sandboxConfig.Linux.SecurityContext.Privileged = test.privileged | ||||||
|  |  | ||||||
| @@ -1465,7 +1473,7 @@ func TestPrivilegedDevices(t *testing.T) { | |||||||
| 			assert.Len(t, spec.Linux.Resources.Devices, 1) | 			assert.Len(t, spec.Linux.Resources.Devices, 1) | ||||||
| 			assert.Equal(t, spec.Linux.Resources.Devices[0].Allow, test.expectAllDevicesAllowed) | 			assert.Equal(t, spec.Linux.Resources.Devices[0].Allow, test.expectAllDevicesAllowed) | ||||||
| 			assert.Equal(t, spec.Linux.Resources.Devices[0].Access, "rwm") | 			assert.Equal(t, spec.Linux.Resources.Devices[0].Access, "rwm") | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1628,8 +1636,7 @@ containerEdits: | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", test.description) | 		t.Run(test.description, func(t *testing.T) { | ||||||
|  |  | ||||||
| 			spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime) | 			spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime) | ||||||
| 			require.NoError(t, err) | 			require.NoError(t, err) | ||||||
|  |  | ||||||
| @@ -1657,5 +1664,6 @@ containerEdits: | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -187,7 +187,7 @@ func TestContainerSpecCommand(t *testing.T) { | |||||||
| 			expectErr: true, | 			expectErr: true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			config, _, imageConfig, _ := getCreateContainerTestData() | 			config, _, imageConfig, _ := getCreateContainerTestData() | ||||||
| 			config.Command = test.criEntrypoint | 			config.Command = test.criEntrypoint | ||||||
| 			config.Args = test.criArgs | 			config.Args = test.criArgs | ||||||
| @@ -198,10 +198,11 @@ func TestContainerSpecCommand(t *testing.T) { | |||||||
| 			err := opts.WithProcessArgs(config, imageConfig)(context.Background(), nil, nil, &spec) | 			err := opts.WithProcessArgs(config, imageConfig)(context.Background(), nil, nil, &spec) | ||||||
| 			if test.expectErr { | 			if test.expectErr { | ||||||
| 				assert.Error(t, err) | 				assert.Error(t, err) | ||||||
| 			continue | 				return | ||||||
| 			} | 			} | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			assert.Equal(t, test.expected, spec.Process.Args, desc) | 			assert.Equal(t, test.expected, spec.Process.Args, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -253,7 +254,7 @@ func TestVolumeMounts(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			config := &imagespec.ImageConfig{ | 			config := &imagespec.ImageConfig{ | ||||||
| 				Volumes: test.imageVolumes, | 				Volumes: test.imageVolumes, | ||||||
| 			} | 			} | ||||||
| @@ -273,6 +274,7 @@ func TestVolumeMounts(t *testing.T) { | |||||||
| 				} | 				} | ||||||
| 				assert.True(t, found) | 				assert.True(t, found) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -149,8 +149,10 @@ func TestFilterContainers(t *testing.T) { | |||||||
| 			expect: []*runtime.Container{testContainers[2]}, | 			expect: []*runtime.Container{testContainers[2]}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			filtered := c.filterCRIContainers(testContainers, test.filter) | 			filtered := c.filterCRIContainers(testContainers, test.filter) | ||||||
| 			assert.Equal(t, test.expect, filtered, desc) | 			assert.Equal(t, test.expect, filtered, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -332,7 +334,7 @@ func TestListContainers(t *testing.T) { | |||||||
| 			expect: expectedContainers[:1], | 			expect: expectedContainers[:1], | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase: %s", testdesc) | 		t.Run(testdesc, func(t *testing.T) { | ||||||
| 			resp, err := c.ListContainers(context.Background(), &runtime.ListContainersRequest{Filter: testdata.filter}) | 			resp, err := c.ListContainers(context.Background(), &runtime.ListContainersRequest{Filter: testdata.filter}) | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			require.NotNil(t, resp) | 			require.NotNil(t, resp) | ||||||
| @@ -341,5 +343,6 @@ func TestListContainers(t *testing.T) { | |||||||
| 			for _, cntr := range testdata.expect { | 			for _, cntr := range testdata.expect { | ||||||
| 				assert.Contains(t, containers, cntr) | 				assert.Contains(t, containers, cntr) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ func TestSetContainerRemoving(t *testing.T) { | |||||||
| 			expectErr: false, | 			expectErr: false, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			container, err := containerstore.NewContainer( | 			container, err := containerstore.NewContainer( | ||||||
| 				containerstore.Metadata{ID: testID}, | 				containerstore.Metadata{ID: testID}, | ||||||
| 				containerstore.WithFakeStatus(test.status), | 				containerstore.WithFakeStatus(test.status), | ||||||
| @@ -81,5 +81,6 @@ func TestSetContainerRemoving(t *testing.T) { | |||||||
| 				assert.NoError(t, resetContainerRemoving(container)) | 				assert.NoError(t, resetContainerRemoving(container)) | ||||||
| 				assert.False(t, container.Status.Get().Removing, "removing should be reset") | 				assert.False(t, container.Status.Get().Removing, "removing should be reset") | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -78,7 +78,7 @@ func TestSetContainerStarting(t *testing.T) { | |||||||
| 			expectErr: true, | 			expectErr: true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			container, err := containerstore.NewContainer( | 			container, err := containerstore.NewContainer( | ||||||
| 				containerstore.Metadata{ID: testID}, | 				containerstore.Metadata{ID: testID}, | ||||||
| 				containerstore.WithFakeStatus(test.status), | 				containerstore.WithFakeStatus(test.status), | ||||||
| @@ -94,5 +94,6 @@ func TestSetContainerStarting(t *testing.T) { | |||||||
| 				assert.NoError(t, resetContainerStarting(container)) | 				assert.NoError(t, resetContainerStarting(container)) | ||||||
| 				assert.False(t, container.Status.Get().Starting, "starting should be reset") | 				assert.False(t, container.Status.Get().Starting, "starting should be reset") | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -168,7 +168,6 @@ func TestContainerMetricsCPU(t *testing.T) { | |||||||
| 		expectedFirst  *runtime.CpuUsage | 		expectedFirst  *runtime.CpuUsage | ||||||
| 		expectedSecond *runtime.CpuUsage | 		expectedSecond *runtime.CpuUsage | ||||||
| 	}{ | 	}{ | ||||||
|  |  | ||||||
| 		"v1 metrics": { | 		"v1 metrics": { | ||||||
| 			firstMetrics: &v1.Metrics{ | 			firstMetrics: &v1.Metrics{ | ||||||
| 				CPU: &v1.CPUStat{ | 				CPU: &v1.CPUStat{ | ||||||
|   | |||||||
| @@ -127,6 +127,8 @@ func TestToCRIContainerStatus(t *testing.T) { | |||||||
| 			expectedReason: errorExitReason, | 			expectedReason: errorExitReason, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
|  |  | ||||||
| 			metadata, status, _, expected := getContainerStatusTestData() | 			metadata, status, _, expected := getContainerStatusTestData() | ||||||
| 			// Update status with test case. | 			// Update status with test case. | ||||||
| 			status.StartedAt = test.startedAt | 			status.StartedAt = test.startedAt | ||||||
| @@ -150,6 +152,7 @@ func TestToCRIContainerStatus(t *testing.T) { | |||||||
| 				expected.Image, | 				expected.Image, | ||||||
| 				expected.ImageRef) | 				expected.ImageRef) | ||||||
| 			assert.Equal(t, expected, containerStatus, desc) | 			assert.Equal(t, expected, containerStatus, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -209,7 +212,7 @@ func TestContainerStatus(t *testing.T) { | |||||||
| 			expectErr:  true, | 			expectErr:  true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			metadata, status, image, expected := getContainerStatusTestData() | 			metadata, status, image, expected := getContainerStatusTestData() | ||||||
| 			// Update status with test case. | 			// Update status with test case. | ||||||
| @@ -232,7 +235,7 @@ func TestContainerStatus(t *testing.T) { | |||||||
| 			if test.expectErr { | 			if test.expectErr { | ||||||
| 				assert.Error(t, err) | 				assert.Error(t, err) | ||||||
| 				assert.Nil(t, resp) | 				assert.Nil(t, resp) | ||||||
| 			continue | 				return | ||||||
| 			} | 			} | ||||||
| 			// Set expectation based on test case. | 			// Set expectation based on test case. | ||||||
| 			expected.StartedAt = test.startedAt | 			expected.StartedAt = test.startedAt | ||||||
| @@ -240,6 +243,7 @@ func TestContainerStatus(t *testing.T) { | |||||||
| 			expected.Reason = test.reason | 			expected.Reason = test.reason | ||||||
| 			patchExceptedWithState(expected, test.expectedState) | 			patchExceptedWithState(expected, test.expectedState) | ||||||
| 			assert.Equal(t, expected, resp.GetStatus()) | 			assert.Equal(t, expected, resp.GetStatus()) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -61,6 +61,7 @@ func TestWaitContainerStop(t *testing.T) { | |||||||
| 			expectErr: false, | 			expectErr: false, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			container, err := containerstore.NewContainer( | 			container, err := containerstore.NewContainer( | ||||||
| 				containerstore.Metadata{ID: id}, | 				containerstore.Metadata{ID: id}, | ||||||
| @@ -81,5 +82,6 @@ func TestWaitContainerStop(t *testing.T) { | |||||||
| 			} | 			} | ||||||
| 			err = c.waitContainerStop(ctx, container) | 			err = c.waitContainerStop(ctx, container) | ||||||
| 			assert.Equal(t, test.expectErr, err != nil, desc) | 			assert.Equal(t, test.expectErr, err != nil, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -211,7 +211,7 @@ func TestUpdateOCILinuxResource(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			config := criconfig.Config{ | 			config := criconfig.Config{ | ||||||
| 				PluginConfig: criconfig.PluginConfig{ | 				PluginConfig: criconfig.PluginConfig{ | ||||||
| 					TolerateMissingHugetlbController: true, | 					TolerateMissingHugetlbController: true, | ||||||
| @@ -225,5 +225,6 @@ func TestUpdateOCILinuxResource(t *testing.T) { | |||||||
| 				assert.NoError(t, err) | 				assert.NoError(t, err) | ||||||
| 			} | 			} | ||||||
| 			assert.Equal(t, test.expected, got) | 			assert.Equal(t, test.expected, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -54,9 +54,10 @@ func TestGetCgroupsPath(t *testing.T) { | |||||||
| 			expected:      "/test-id", | 			expected:      "/test-id", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			got := getCgroupsPath(test.cgroupsParent, testID) | 			got := getCgroupsPath(test.cgroupsParent, testID) | ||||||
| 			assert.Equal(t, test.expected, got) | 			assert.Equal(t, test.expected, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -75,10 +75,11 @@ func TestGetUserFromImage(t *testing.T) { | |||||||
| 			name: "test", | 			name: "test", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase - %q", c) | 		t.Run(c, func(t *testing.T) { | ||||||
| 			actualUID, actualName := getUserFromImage(test.user) | 			actualUID, actualName := getUserFromImage(test.user) | ||||||
| 			assert.Equal(t, test.uid, actualUID) | 			assert.Equal(t, test.uid, actualUID) | ||||||
| 			assert.Equal(t, test.name, actualName) | 			assert.Equal(t, test.name, actualName) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -112,12 +113,13 @@ func TestGetRepoDigestAndTag(t *testing.T) { | |||||||
| 			expectedRepoTag:    "", | 			expectedRepoTag:    "", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			named, err := docker.ParseDockerRef(test.ref) | 			named, err := docker.ParseDockerRef(test.ref) | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			repoDigest, repoTag := getRepoDigestAndTag(named, digest, test.schema1) | 			repoDigest, repoTag := getRepoDigestAndTag(named, digest, test.schema1) | ||||||
| 			assert.Equal(t, test.expectedRepoDigest, repoDigest) | 			assert.Equal(t, test.expectedRepoDigest, repoDigest) | ||||||
| 			assert.Equal(t, test.expectedRepoTag, repoTag) | 			assert.Equal(t, test.expectedRepoTag, repoTag) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -364,7 +366,7 @@ func TestEnvDeduplication(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			var spec runtimespec.Spec | 			var spec runtimespec.Spec | ||||||
| 			if len(test.existing) > 0 { | 			if len(test.existing) > 0 { | ||||||
| 				spec.Process = &runtimespec.Process{ | 				spec.Process = &runtimespec.Process{ | ||||||
| @@ -375,6 +377,7 @@ func TestEnvDeduplication(t *testing.T) { | |||||||
| 				oci.WithEnv([]string{kv[0] + "=" + kv[1]})(context.Background(), nil, nil, &spec) | 				oci.WithEnv([]string{kv[0] + "=" + kv[1]})(context.Background(), nil, nil, &spec) | ||||||
| 			} | 			} | ||||||
| 			assert.Equal(t, test.expected, spec.Process.Env) | 			assert.Equal(t, test.expected, spec.Process.Env) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -102,11 +102,12 @@ func TestParseAuth(t *testing.T) { | |||||||
| 			expectedSecret: testPasswd, | 			expectedSecret: testPasswd, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			u, s, err := ParseAuth(test.auth, test.host) | 			u, s, err := ParseAuth(test.auth, test.host) | ||||||
| 			assert.Equal(t, test.expectErr, err != nil) | 			assert.Equal(t, test.expectErr, err != nil) | ||||||
| 			assert.Equal(t, test.expectedUser, u) | 			assert.Equal(t, test.expectedUser, u) | ||||||
| 			assert.Equal(t, test.expectedSecret, s) | 			assert.Equal(t, test.expectedSecret, s) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -250,12 +251,13 @@ func TestRegistryEndpoints(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			c.config.Registry.Mirrors = test.mirrors | 			c.config.Registry.Mirrors = test.mirrors | ||||||
| 			got, err := c.registryEndpoints(test.host) | 			got, err := c.registryEndpoints(test.host) | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			assert.Equal(t, test.expected, got) | 			assert.Equal(t, test.expected, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -305,9 +307,10 @@ func TestDefaultScheme(t *testing.T) { | |||||||
| 			expected: "https", | 			expected: "https", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			got := defaultScheme(test.host) | 			got := defaultScheme(test.host) | ||||||
| 			assert.Equal(t, test.expected, got) | 			assert.Equal(t, test.expected, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -325,11 +328,12 @@ func TestEncryptedImagePullOpts(t *testing.T) { | |||||||
| 			expectedOpts: 0, | 			expectedOpts: 0, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			c.config.ImageDecryption.KeyModel = test.keyModel | 			c.config.ImageDecryption.KeyModel = test.keyModel | ||||||
| 			got := len(c.encryptedImagesPullOpts()) | 			got := len(c.encryptedImagesPullOpts()) | ||||||
| 			assert.Equal(t, test.expectedOpts, got) | 			assert.Equal(t, test.expectedOpts, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -70,6 +70,7 @@ func TestToCRISandbox(t *testing.T) { | |||||||
| 			expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY, | 			expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			status := sandboxstore.Status{ | 			status := sandboxstore.Status{ | ||||||
| 				CreatedAt: createdAt, | 				CreatedAt: createdAt, | ||||||
| 				State:     test.state, | 				State:     test.state, | ||||||
| @@ -77,6 +78,7 @@ func TestToCRISandbox(t *testing.T) { | |||||||
| 			expect.State = test.expectedState | 			expect.State = test.expectedState | ||||||
| 			s := toCRISandbox(meta, status) | 			s := toCRISandbox(meta, status) | ||||||
| 			assert.Equal(t, expect, s, desc) | 			assert.Equal(t, expect, s, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -201,8 +203,9 @@ func TestFilterSandboxes(t *testing.T) { | |||||||
| 			expect: []*runtime.PodSandbox{testSandboxes[2]}, | 			expect: []*runtime.PodSandbox{testSandboxes[2]}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase: %s", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			filtered := c.filterCRISandboxes(testSandboxes, test.filter) | 			filtered := c.filterCRISandboxes(testSandboxes, test.filter) | ||||||
| 			assert.Equal(t, test.expect, filtered, desc) | 			assert.Equal(t, test.expect, filtered, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -235,7 +235,7 @@ func TestLinuxSandboxContainerSpec(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			c.config.EnableUnprivilegedICMP = true | 			c.config.EnableUnprivilegedICMP = true | ||||||
| 			c.config.EnableUnprivilegedPorts = true | 			c.config.EnableUnprivilegedPorts = true | ||||||
| @@ -247,7 +247,7 @@ func TestLinuxSandboxContainerSpec(t *testing.T) { | |||||||
| 			if test.expectErr { | 			if test.expectErr { | ||||||
| 				assert.Error(t, err) | 				assert.Error(t, err) | ||||||
| 				assert.Nil(t, spec) | 				assert.Nil(t, spec) | ||||||
| 			continue | 				return | ||||||
| 			} | 			} | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			assert.NotNil(t, spec) | 			assert.NotNil(t, spec) | ||||||
| @@ -255,6 +255,7 @@ func TestLinuxSandboxContainerSpec(t *testing.T) { | |||||||
| 			if test.specCheck != nil { | 			if test.specCheck != nil { | ||||||
| 				test.specCheck(t, spec) | 				test.specCheck(t, spec) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -426,7 +427,7 @@ options timeout:1 | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			c.os.(*ostesting.FakeOS).HostnameFn = func() (string, error) { | 			c.os.(*ostesting.FakeOS).HostnameFn = func() (string, error) { | ||||||
| 				return realhostname, nil | 				return realhostname, nil | ||||||
| @@ -452,6 +453,7 @@ options timeout:1 | |||||||
| 				} | 				} | ||||||
| 				assert.Equal(t, expected, calls[i]) | 				assert.Equal(t, expected, calls[i]) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -493,14 +495,15 @@ options timeout:1 | |||||||
| `, | `, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			resolvContent, err := parseDNSOptions(test.servers, test.searches, test.options) | 			resolvContent, err := parseDNSOptions(test.servers, test.searches, test.options) | ||||||
| 			if test.expectErr { | 			if test.expectErr { | ||||||
| 				assert.Error(t, err) | 				assert.Error(t, err) | ||||||
| 			continue | 				return | ||||||
| 			} | 			} | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			assert.Equal(t, resolvContent, test.expectedContent) | 			assert.Equal(t, resolvContent, test.expectedContent) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -92,7 +92,7 @@ func TestSandboxContainerSpec(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			config, imageConfig, specCheck := getRunPodSandboxTestData() | 			config, imageConfig, specCheck := getRunPodSandboxTestData() | ||||||
| 			if test.configChange != nil { | 			if test.configChange != nil { | ||||||
| @@ -107,7 +107,7 @@ func TestSandboxContainerSpec(t *testing.T) { | |||||||
| 			if test.expectErr { | 			if test.expectErr { | ||||||
| 				assert.Error(t, err) | 				assert.Error(t, err) | ||||||
| 				assert.Nil(t, spec) | 				assert.Nil(t, spec) | ||||||
| 			continue | 				return | ||||||
| 			} | 			} | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			assert.NotNil(t, spec) | 			assert.NotNil(t, spec) | ||||||
| @@ -115,6 +115,7 @@ func TestSandboxContainerSpec(t *testing.T) { | |||||||
| 			if test.specCheck != nil { | 			if test.specCheck != nil { | ||||||
| 				test.specCheck(t, spec) | 				test.specCheck(t, spec) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -139,7 +140,7 @@ func TestTypeurlMarshalUnmarshalSandboxMeta(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			meta := &sandboxstore.Metadata{ | 			meta := &sandboxstore.Metadata{ | ||||||
| 				ID:        "1", | 				ID:        "1", | ||||||
| 				Name:      "sandbox_1", | 				Name:      "sandbox_1", | ||||||
| @@ -158,6 +159,7 @@ func TestTypeurlMarshalUnmarshalSandboxMeta(t *testing.T) { | |||||||
| 			curMeta, ok := data.(*sandboxstore.Metadata) | 			curMeta, ok := data.(*sandboxstore.Metadata) | ||||||
| 			assert.True(t, ok) | 			assert.True(t, ok) | ||||||
| 			assert.Equal(t, meta, curMeta) | 			assert.Equal(t, meta, curMeta) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -251,8 +253,9 @@ func TestToCNIPortMappings(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			assert.Equal(t, test.cniPortMappings, toCNIPortMappings(test.criPortMappings)) | 			assert.Equal(t, test.cniPortMappings, toCNIPortMappings(test.criPortMappings)) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -297,7 +300,7 @@ func TestSelectPodIP(t *testing.T) { | |||||||
| 			expectedAdditionalIPs: []string{"2001:db8:85a3::8a2e:370:7334", "2001:db8:85a3::8a2e:370:7335", "192.168.17.45"}, | 			expectedAdditionalIPs: []string{"2001:db8:85a3::8a2e:370:7334", "2001:db8:85a3::8a2e:370:7335", "192.168.17.45"}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			var ipConfigs []*cni.IPConfig | 			var ipConfigs []*cni.IPConfig | ||||||
| 			for _, ip := range test.ips { | 			for _, ip := range test.ips { | ||||||
| 				ipConfigs = append(ipConfigs, &cni.IPConfig{ | 				ipConfigs = append(ipConfigs, &cni.IPConfig{ | ||||||
| @@ -307,6 +310,7 @@ func TestSelectPodIP(t *testing.T) { | |||||||
| 			ip, additionalIPs := selectPodIPs(context.Background(), ipConfigs, test.pref) | 			ip, additionalIPs := selectPodIPs(context.Background(), ipConfigs, test.pref) | ||||||
| 			assert.Equal(t, test.expectedIP, ip) | 			assert.Equal(t, test.expectedIP, ip) | ||||||
| 			assert.Equal(t, test.expectedAdditionalIPs, additionalIPs) | 			assert.Equal(t, test.expectedAdditionalIPs, additionalIPs) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -104,7 +104,7 @@ func TestPodSandboxStatus(t *testing.T) { | |||||||
| 			expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY, | 			expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase: %s", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			status := sandboxstore.Status{ | 			status := sandboxstore.Status{ | ||||||
| 				CreatedAt: createdAt, | 				CreatedAt: createdAt, | ||||||
| 				State:     test.state, | 				State:     test.state, | ||||||
| @@ -112,5 +112,6 @@ func TestPodSandboxStatus(t *testing.T) { | |||||||
| 			expected.State = test.expectedState | 			expected.State = test.expectedState | ||||||
| 			got := toCRISandboxStatus(metadata, status, ip, additionalIPs) | 			got := toCRISandboxStatus(metadata, status, ip, additionalIPs) | ||||||
| 			assert.Equal(t, expected, got) | 			assert.Equal(t, expected, got) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ func TestWaitSandboxStop(t *testing.T) { | |||||||
| 			expectErr: false, | 			expectErr: false, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
|  | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			c := newTestCRIService() | 			c := newTestCRIService() | ||||||
| 			sandbox := sandboxstore.NewSandbox( | 			sandbox := sandboxstore.NewSandbox( | ||||||
| 				sandboxstore.Metadata{ID: id}, | 				sandboxstore.Metadata{ID: id}, | ||||||
| @@ -69,5 +70,6 @@ func TestWaitSandboxStop(t *testing.T) { | |||||||
| 			} | 			} | ||||||
| 			err := c.waitSandboxStop(ctx, sandbox) | 			err := c.waitSandboxStop(ctx, sandbox) | ||||||
| 			assert.Equal(t, test.expectErr, err != nil, desc) | 			assert.Equal(t, test.expectErr, err != nil, desc) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -65,8 +65,9 @@ func TestContainerState(t *testing.T) { | |||||||
| 			state: runtime.ContainerState_CONTAINER_EXITED, | 			state: runtime.ContainerState_CONTAINER_EXITED, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", c) | 		t.Run(c, func(t *testing.T) { | ||||||
| 			assertlib.Equal(t, test.state, test.status.State()) | 			assertlib.Equal(t, test.state, test.status.State()) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -221,7 +221,7 @@ func TestImageStore(t *testing.T) { | |||||||
| 			expected: []Image{}, | 			expected: []Image{}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", desc) | 		t.Run(desc, func(t *testing.T) { | ||||||
| 			s, err := NewFakeStore([]Image{image}) | 			s, err := NewFakeStore([]Image{image}) | ||||||
| 			assert.NoError(err) | 			assert.NoError(err) | ||||||
| 			assert.NoError(s.update(test.ref, test.image)) | 			assert.NoError(s.update(test.ref, test.image)) | ||||||
| @@ -244,5 +244,6 @@ func TestImageStore(t *testing.T) { | |||||||
| 				assert.Equal(errdefs.ErrNotFound, err) | 				assert.Equal(errdefs.ErrNotFound, err) | ||||||
| 				assert.Empty(id) | 				assert.Empty(id) | ||||||
| 			} | 			} | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -73,12 +73,13 @@ func TestNormalizeImageRef(t *testing.T) { | |||||||
| 			expect: "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", | 			expect: "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		t.Logf("TestCase %q", test.input) | 		t.Run(test.input, func(t *testing.T) { | ||||||
| 			normalized, err := NormalizeImageRef(test.input) | 			normalized, err := NormalizeImageRef(test.input) | ||||||
| 			assert.NoError(t, err) | 			assert.NoError(t, err) | ||||||
| 			output := normalized.String() | 			output := normalized.String() | ||||||
| 			assert.Equal(t, test.expect, output) | 			assert.Equal(t, test.expect, output) | ||||||
| 			_, err = reference.Parse(output) | 			_, err = reference.Parse(output) | ||||||
| 			assert.NoError(t, err, "%q should be containerd supported reference", output) | 			assert.NoError(t, err, "%q should be containerd supported reference", output) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Canter
					Daniel Canter