@@ -81,18 +81,21 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
8181 testContainerName := "container-name"
8282 testPid := uint32 (1234 )
8383
84- for desc , test := range map [string ]struct {
84+ for _ , test := range []struct {
85+ desc string
8586 podAnnotations []string
8687 configChange func (* runtime.PodSandboxConfig )
8788 specCheck func (* testing.T , * runtimespec.Spec )
8889 }{
89- "a passthrough annotation should be passed as an OCI annotation" : {
90+ {
91+ desc : "a passthrough annotation should be passed as an OCI annotation" ,
9092 podAnnotations : []string {"c" },
9193 specCheck : func (t * testing.T , spec * runtimespec.Spec ) {
9294 assert .Equal (t , spec .Annotations ["c" ], "d" )
9395 },
9496 },
95- "a non-passthrough annotation should not be passed as an OCI annotation" : {
97+ {
98+ desc : "a non-passthrough annotation should not be passed as an OCI annotation" ,
9699 configChange : func (c * runtime.PodSandboxConfig ) {
97100 c .Annotations ["d" ] = "e"
98101 },
@@ -103,7 +106,8 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
103106 assert .False (t , ok )
104107 },
105108 },
106- "passthrough annotations should support wildcard match" : {
109+ {
110+ desc : "passthrough annotations should support wildcard match" ,
107111 configChange : func (c * runtime.PodSandboxConfig ) {
108112 c .Annotations ["t.f" ] = "j"
109113 c .Annotations ["z.g" ] = "o"
@@ -124,7 +128,8 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
124128 },
125129 },
126130 } {
127- t .Run (desc , func (t * testing.T ) {
131+ test := test
132+ t .Run (test .desc , func (t * testing.T ) {
128133 c := newTestCRIService ()
129134 containerConfig , sandboxConfig , imageConfig , specCheck := getCreateContainerTestData ()
130135 if test .configChange != nil {
@@ -147,50 +152,58 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
147152}
148153
149154func TestContainerSpecCommand (t * testing.T ) {
150- for desc , test := range map [string ]struct {
155+ for _ , test := range []struct {
156+ desc string
151157 criEntrypoint []string
152158 criArgs []string
153159 imageEntrypoint []string
154160 imageArgs []string
155161 expected []string
156162 expectErr bool
157163 }{
158- "should use cri entrypoint if it's specified" : {
164+ {
165+ desc : "should use cri entrypoint if it's specified" ,
159166 criEntrypoint : []string {"a" , "b" },
160167 imageEntrypoint : []string {"c" , "d" },
161168 imageArgs : []string {"e" , "f" },
162169 expected : []string {"a" , "b" },
163170 },
164- "should use cri entrypoint if it's specified even if it's empty" : {
171+ {
172+ desc : "should use cri entrypoint if it's specified even if it's empty" ,
165173 criEntrypoint : []string {},
166174 criArgs : []string {"a" , "b" },
167175 imageEntrypoint : []string {"c" , "d" },
168176 imageArgs : []string {"e" , "f" },
169177 expected : []string {"a" , "b" },
170178 },
171- "should use cri entrypoint and args if they are specified" : {
179+ {
180+ desc : "should use cri entrypoint and args if they are specified" ,
172181 criEntrypoint : []string {"a" , "b" },
173182 criArgs : []string {"c" , "d" },
174183 imageEntrypoint : []string {"e" , "f" },
175184 imageArgs : []string {"g" , "h" },
176185 expected : []string {"a" , "b" , "c" , "d" },
177186 },
178- "should use image entrypoint if cri entrypoint is not specified" : {
187+ {
188+ desc : "should use image entrypoint if cri entrypoint is not specified" ,
179189 criArgs : []string {"a" , "b" },
180190 imageEntrypoint : []string {"c" , "d" },
181191 imageArgs : []string {"e" , "f" },
182192 expected : []string {"c" , "d" , "a" , "b" },
183193 },
184- "should use image args if both cri entrypoint and args are not specified" : {
194+ {
195+ desc : "should use image args if both cri entrypoint and args are not specified" ,
185196 imageEntrypoint : []string {"c" , "d" },
186197 imageArgs : []string {"e" , "f" },
187198 expected : []string {"c" , "d" , "e" , "f" },
188199 },
189- "should return error if both entrypoint and args are empty" : {
200+ {
201+ desc : "should return error if both entrypoint and args are empty" ,
190202 expectErr : true ,
191203 },
192204 } {
193- t .Run (desc , func (t * testing.T ) {
205+ test := test
206+ t .Run (test .desc , func (t * testing.T ) {
194207 config , _ , imageConfig , _ := getCreateContainerTestData ()
195208 config .Command = test .criEntrypoint
196209 config .Args = test .criArgs
@@ -204,19 +217,21 @@ func TestContainerSpecCommand(t *testing.T) {
204217 return
205218 }
206219 assert .NoError (t , err )
207- assert .Equal (t , test .expected , spec .Process .Args , desc )
220+ assert .Equal (t , test .expected , spec .Process .Args , test . desc )
208221 })
209222 }
210223}
211224
212225func TestVolumeMounts (t * testing.T ) {
213226 testContainerRootDir := "test-container-root"
214- for desc , test := range map [string ]struct {
227+ for _ , test := range []struct {
228+ desc string
215229 criMounts []* runtime.Mount
216230 imageVolumes map [string ]struct {}
217231 expectedMountDest []string
218232 }{
219- "should setup rw mount for image volumes" : {
233+ {
234+ desc : "should setup rw mount for image volumes" ,
220235 imageVolumes : map [string ]struct {}{
221236 "/test-volume-1" : {},
222237 "/test-volume-2" : {},
@@ -226,7 +241,8 @@ func TestVolumeMounts(t *testing.T) {
226241 "/test-volume-2" ,
227242 },
228243 },
229- "should skip image volumes if already mounted by CRI" : {
244+ {
245+ desc : "should skip image volumes if already mounted by CRI" ,
230246 criMounts : []* runtime.Mount {
231247 {
232248 ContainerPath : "/test-volume-1" ,
@@ -241,7 +257,8 @@ func TestVolumeMounts(t *testing.T) {
241257 "/test-volume-2" ,
242258 },
243259 },
244- "should compare and return cleanpath" : {
260+ {
261+ desc : "should compare and return cleanpath" ,
245262 criMounts : []* runtime.Mount {
246263 {
247264 ContainerPath : "/test-volume-1" ,
@@ -257,7 +274,8 @@ func TestVolumeMounts(t *testing.T) {
257274 },
258275 },
259276 } {
260- t .Run (desc , func (t * testing.T ) {
277+ test := test
278+ t .Run (test .desc , func (t * testing.T ) {
261279 config := & imagespec.ImageConfig {
262280 Volumes : test .imageVolumes ,
263281 }
@@ -294,14 +312,16 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
294312 testContainerName := "container-name"
295313 testPid := uint32 (1234 )
296314
297- for desc , test := range map [string ]struct {
315+ for _ , test := range []struct {
316+ desc string
298317 podAnnotations []string
299318 containerAnnotations []string
300319 podConfigChange func (* runtime.PodSandboxConfig )
301320 configChange func (* runtime.ContainerConfig )
302321 specCheck func (* testing.T , * runtimespec.Spec )
303322 }{
304- "passthrough annotations from pod and container should be passed as an OCI annotation" : {
323+ {
324+ desc : "passthrough annotations from pod and container should be passed as an OCI annotation" ,
305325 podConfigChange : func (p * runtime.PodSandboxConfig ) {
306326 p .Annotations ["pod.annotation.1" ] = "1"
307327 p .Annotations ["pod.annotation.2" ] = "2"
@@ -327,7 +347,8 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
327347 assert .False (t , ok )
328348 },
329349 },
330- "passthrough annotations from pod and container should support wildcard" : {
350+ {
351+ desc : "passthrough annotations from pod and container should support wildcard" ,
331352 podConfigChange : func (p * runtime.PodSandboxConfig ) {
332353 p .Annotations ["pod.annotation.1" ] = "1"
333354 p .Annotations ["pod.annotation.2" ] = "2"
@@ -349,7 +370,8 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
349370 assert .Equal (t , "3" , spec .Annotations ["pod.annotation.3" ])
350371 },
351372 },
352- "annotations should not pass through if no passthrough annotations are configured" : {
373+ {
374+ desc : "annotations should not pass through if no passthrough annotations are configured" ,
353375 podConfigChange : func (p * runtime.PodSandboxConfig ) {
354376 p .Annotations ["pod.annotation.1" ] = "1"
355377 p .Annotations ["pod.annotation.2" ] = "2"
@@ -378,7 +400,8 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
378400 },
379401 },
380402 } {
381- t .Run (desc , func (t * testing.T ) {
403+ test := test
404+ t .Run (test .desc , func (t * testing.T ) {
382405 c := newTestCRIService ()
383406 containerConfig , sandboxConfig , imageConfig , specCheck := getCreateContainerTestData ()
384407 if test .configChange != nil {
@@ -440,20 +463,24 @@ func TestRuntimeSnapshotter(t *testing.T) {
440463 Snapshotter : "devmapper" ,
441464 }
442465
443- for desc , test := range map [string ]struct {
466+ for _ , test := range []struct {
467+ desc string
444468 runtime config.Runtime
445469 expectSnapshotter string
446470 }{
447- "should return default snapshotter when runtime.Snapshotter is not set" : {
471+ {
472+ desc : "should return default snapshotter when runtime.Snapshotter is not set" ,
448473 runtime : defaultRuntime ,
449474 expectSnapshotter : config .DefaultConfig ().Snapshotter ,
450475 },
451- "should return overridden snapshotter when runtime.Snapshotter is set" : {
476+ {
477+ desc : "should return overridden snapshotter when runtime.Snapshotter is set" ,
452478 runtime : fooRuntime ,
453479 expectSnapshotter : "devmapper" ,
454480 },
455481 } {
456- t .Run (desc , func (t * testing.T ) {
482+ test := test
483+ t .Run (test .desc , func (t * testing.T ) {
457484 cri := newTestCRIService ()
458485 cri .config = config.Config {
459486 PluginConfig : config .DefaultConfig (),
0 commit comments