@@ -12,17 +12,15 @@ import (
12
12
"reflect"
13
13
"strings"
14
14
15
- "github.com/vishvananda/netlink"
16
-
17
15
"github.com/containernetworking/cni/libcni"
18
16
"github.com/containernetworking/cni/pkg/types"
19
17
cniv04 "github.com/containernetworking/cni/pkg/types/040"
20
18
"github.com/containernetworking/cni/pkg/version"
21
19
"github.com/containernetworking/plugins/pkg/ns"
22
20
"github.com/containernetworking/plugins/pkg/testutils"
23
-
24
21
. "github.com/onsi/ginkgo/v2"
25
22
. "github.com/onsi/gomega"
23
+ "github.com/vishvananda/netlink"
26
24
)
27
25
28
26
func writeConfig (dir , fileName , netName , plugin , vers string ) (conf , confPath string , err error ) {
@@ -88,7 +86,7 @@ func (f *fakeExec) addPlugin(expectedEnv []string, expectedConf string, result t
88
86
})
89
87
}
90
88
91
- // Ensure everything in needles is also present in haystack
89
+ // Ensure everything in needles is also present in haystack.
92
90
func matchArray (needles , haystack []string ) {
93
91
Expect (len (needles )).To (BeNumerically ("<=" , len (haystack )))
94
92
for _ , e1 := range needles {
@@ -170,7 +168,7 @@ func (f *fakeExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData
170
168
}
171
169
172
170
func (f * fakeExec ) FindInPath (plugin string , paths []string ) (string , error ) {
173
- Expect (len ( paths )). To ( BeNumerically ( ">" , 0 ))
171
+ Expect (paths ). ToNot ( BeEmpty ( ))
174
172
175
173
if f .failFind {
176
174
return "" , fmt .Errorf ("failed to find plugin %q in path %s" , plugin , paths )
@@ -233,7 +231,7 @@ var _ = Describe("ocicni operations", func() {
233
231
Expect (ok ).To (BeTrue ())
234
232
net := tmp .getDefaultNetwork ()
235
233
Expect (net .name ).To (Equal ("test" ))
236
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
234
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
237
235
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
238
236
239
237
Expect (ocicni .Shutdown ()).NotTo (HaveOccurred ())
@@ -256,7 +254,7 @@ var _ = Describe("ocicni operations", func() {
256
254
Expect (ok ).To (BeTrue ())
257
255
net := tmp .getDefaultNetwork ()
258
256
Expect (net .name ).To (Equal ("test" ))
259
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
257
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
260
258
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
261
259
262
260
Expect (ocicni .Shutdown ()).NotTo (HaveOccurred ())
@@ -314,7 +312,7 @@ var _ = Describe("ocicni operations", func() {
314
312
Expect (ok ).To (BeTrue ())
315
313
net := tmp .getDefaultNetwork ()
316
314
Expect (net .name ).To (Equal ("test" ))
317
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
315
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
318
316
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
319
317
320
318
// If a CNI config file is updated, default network name should be reloaded real-time
@@ -325,7 +323,7 @@ var _ = Describe("ocicni operations", func() {
325
323
326
324
net = tmp .getDefaultNetwork ()
327
325
Expect (net .name ).To (Equal ("secondary" ))
328
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
326
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
329
327
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("testplugin" ))
330
328
331
329
Expect (ocicni .Shutdown ()).NotTo (HaveOccurred ())
@@ -347,7 +345,7 @@ var _ = Describe("ocicni operations", func() {
347
345
Expect (ok ).To (BeTrue ())
348
346
net := tmp .getDefaultNetwork ()
349
347
Expect (net .name ).To (Equal ("test" ))
350
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
348
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
351
349
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
352
350
353
351
// If a CNI config file is updated, default network name should be reloaded real-time
@@ -358,7 +356,7 @@ var _ = Describe("ocicni operations", func() {
358
356
359
357
net = tmp .getDefaultNetwork ()
360
358
Expect (net .name ).To (Equal ("test" ))
361
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
359
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
362
360
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("testplugin" ))
363
361
364
362
Expect (ocicni .Shutdown ()).NotTo (HaveOccurred ())
@@ -377,7 +375,7 @@ var _ = Describe("ocicni operations", func() {
377
375
Expect (ok ).To (BeTrue ())
378
376
net := tmp .getDefaultNetwork ()
379
377
Expect (net .name ).To (Equal ("test" ))
380
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
378
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
381
379
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
382
380
383
381
// Delete the default network config, ensure ocicni begins to
@@ -410,7 +408,7 @@ var _ = Describe("ocicni operations", func() {
410
408
Expect (ok ).To (BeTrue ())
411
409
net := tmp .getDefaultNetwork ()
412
410
Expect (net .name ).To (Equal ("test" ))
413
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
411
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
414
412
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
415
413
416
414
// If a new CNI config file is added, default network name should be reloaded real-time
@@ -422,7 +420,7 @@ var _ = Describe("ocicni operations", func() {
422
420
423
421
net = tmp .getDefaultNetwork ()
424
422
Expect (net .name ).To (Equal ("newdefault" ))
425
- Expect (len ( net .config .Plugins )). To ( BeNumerically ( ">" , 0 ))
423
+ Expect (net .config .Plugins ). ToNot ( BeEmpty ( ))
426
424
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
427
425
428
426
Expect (ocicni .Shutdown ()).NotTo (HaveOccurred ())
@@ -442,7 +440,7 @@ var _ = Describe("ocicni operations", func() {
442
440
cniConfig := libcni .NewCNIConfig ([]string {"/opt/cni/bin" }, & fakeExec {})
443
441
netMap , defname , err := loadNetworks (context .TODO (), tmpDir , cniConfig )
444
442
Expect (err ).NotTo (HaveOccurred ())
445
- Expect (len ( netMap )) .To (Equal (4 ))
443
+ Expect (netMap ).To (HaveLen (4 ))
446
444
// filenames are sorted asciibetically
447
445
Expect (defname ).To (Equal ("network2" ))
448
446
})
@@ -451,7 +449,7 @@ var _ = Describe("ocicni operations", func() {
451
449
cniConfig := libcni .NewCNIConfig ([]string {"/opt/cni/bin" }, & fakeExec {})
452
450
netMap , defname , err := loadNetworks (context .TODO (), tmpDir , cniConfig )
453
451
Expect (err ).NotTo (HaveOccurred ())
454
- Expect (len ( netMap )) .To (Equal ( 0 ))
452
+ Expect (netMap ).To (BeEmpty ( ))
455
453
// filenames are sorted asciibetically
456
454
Expect (defname ).To (Equal ("" ))
457
455
})
@@ -471,7 +469,7 @@ var _ = Describe("ocicni operations", func() {
471
469
472
470
// We expect the type=myplugin2 network be ignored since it
473
471
// was read earlier than the type=myplugin network with the same name
474
- Expect (len ( netMap )) .To (Equal (2 ))
472
+ Expect (netMap ).To (HaveLen (2 ))
475
473
net , ok := netMap ["network2" ]
476
474
Expect (ok ).To (BeTrue ())
477
475
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
@@ -500,7 +498,7 @@ var _ = Describe("ocicni operations", func() {
500
498
runtimeConfig = & RuntimeConfig {IP : "172.16.0.1" }
501
499
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
502
500
Expect (err ).NotTo (HaveOccurred ())
503
- Expect (len ( rt .Args )) .To (Equal (6 ))
501
+ Expect (rt .Args ).To (HaveLen (6 ))
504
502
Expect (rt .Args [5 ][1 ]).To (Equal ("172.16.0.1" ))
505
503
506
504
// runtimeConfig with invalid MAC
@@ -512,14 +510,14 @@ var _ = Describe("ocicni operations", func() {
512
510
runtimeConfig = & RuntimeConfig {MAC : "9e:0c:d9:b2:f0:a6" }
513
511
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
514
512
Expect (err ).NotTo (HaveOccurred ())
515
- Expect (len ( rt .Args )) .To (Equal (6 ))
513
+ Expect (rt .Args ).To (HaveLen (6 ))
516
514
Expect (rt .Args [5 ][1 ]).To (Equal ("9e:0c:d9:b2:f0:a6" ))
517
515
518
516
// runtimeConfig with valid IP and valid MAC
519
517
runtimeConfig = & RuntimeConfig {IP : "172.16.0.1" , MAC : "9e:0c:d9:b2:f0:a6" }
520
518
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
521
519
Expect (err ).NotTo (HaveOccurred ())
522
- Expect (len ( rt .Args )) .To (Equal (7 ))
520
+ Expect (rt .Args ).To (HaveLen (7 ))
523
521
Expect (rt .Args [5 ][1 ]).To (Equal ("172.16.0.1" ))
524
522
Expect (rt .Args [6 ][1 ]).To (Equal ("9e:0c:d9:b2:f0:a6" ))
525
523
@@ -538,8 +536,8 @@ var _ = Describe("ocicni operations", func() {
538
536
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
539
537
Expect (err ).NotTo (HaveOccurred ())
540
538
pm , ok := rt .CapabilityArgs ["portMappings" ].([]PortMapping )
541
- Expect (ok ).To (Equal ( true ))
542
- Expect (len ( pm )) .To (Equal (1 ))
539
+ Expect (ok ).To (BeTrue ( ))
540
+ Expect (pm ).To (HaveLen (1 ))
543
541
Expect (pm [0 ].HostPort ).To (Equal (int32 (100 )))
544
542
Expect (pm [0 ].ContainerPort ).To (Equal (int32 (50 )))
545
543
Expect (pm [0 ].Protocol ).To (Equal ("tcp" ))
@@ -560,7 +558,7 @@ var _ = Describe("ocicni operations", func() {
560
558
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
561
559
Expect (err ).NotTo (HaveOccurred ())
562
560
bw , ok := rt .CapabilityArgs ["bandwidth" ].(map [string ]uint64 )
563
- Expect (ok ).To (Equal ( true ))
561
+ Expect (ok ).To (BeTrue ( ))
564
562
Expect (bw ["ingressRate" ]).To (Equal (uint64 (1 )))
565
563
Expect (bw ["ingressBurst" ]).To (Equal (uint64 (2 )))
566
564
Expect (bw ["egressRate" ]).To (Equal (uint64 (3 )))
@@ -581,16 +579,16 @@ var _ = Describe("ocicni operations", func() {
581
579
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
582
580
Expect (err ).NotTo (HaveOccurred ())
583
581
ir , ok := rt .CapabilityArgs ["ipRanges" ].([][]IpRange )
584
- Expect (ok ).To (Equal ( true ))
585
- Expect (len ( ir )) .To (Equal (1 ))
586
- Expect (len ( ir [0 ])) .To (Equal (1 ))
582
+ Expect (ok ).To (BeTrue ( ))
583
+ Expect (ir ).To (HaveLen (1 ))
584
+ Expect (ir [0 ]).To (HaveLen (1 ))
587
585
Expect (ir [0 ][0 ].Gateway ).To (Equal ("192.168.0.254" ))
588
586
589
587
runtimeConfig = & RuntimeConfig {CgroupPath : "/slice/pod/testing" }
590
588
rt , err = buildCNIRuntimeConf (podNetwork , ifName , runtimeConfig )
591
589
Expect (err ).NotTo (HaveOccurred ())
592
590
cg , ok := rt .CapabilityArgs ["cgroupPath" ].(string )
593
- Expect (ok ).To (Equal ( true ))
591
+ Expect (ok ).To (BeTrue ( ))
594
592
Expect (cg ).To (Equal ("/slice/pod/testing" ))
595
593
})
596
594
@@ -631,7 +629,7 @@ var _ = Describe("ocicni operations", func() {
631
629
results , err := ocicni .SetUpPod (podNet )
632
630
Expect (err ).NotTo (HaveOccurred ())
633
631
Expect (fake .addIndex ).To (Equal (len (fake .plugins )))
634
- Expect (len ( results )) .To (Equal (1 ))
632
+ Expect (results ).To (HaveLen (1 ))
635
633
r , ok := results [0 ].Result .(* cniv04.Result )
636
634
Expect (ok ).To (BeTrue ())
637
635
Expect (reflect .DeepEqual (r , expectedResult )).To (BeTrue ())
@@ -717,7 +715,7 @@ var _ = Describe("ocicni operations", func() {
717
715
results , err := ocicni .SetUpPod (podNet )
718
716
Expect (err ).NotTo (HaveOccurred ())
719
717
Expect (fake .addIndex ).To (Equal (len (fake .plugins )))
720
- Expect (len ( results )) .To (Equal (2 ))
718
+ Expect (results ).To (HaveLen (2 ))
721
719
r , ok := results [0 ].Result .(* cniv04.Result )
722
720
Expect (ok ).To (BeTrue ())
723
721
Expect (reflect .DeepEqual (r , expectedResult1 )).To (BeTrue ())
@@ -797,7 +795,7 @@ var _ = Describe("ocicni operations", func() {
797
795
results , err := ocicni .SetUpPod (podNet )
798
796
Expect (err ).NotTo (HaveOccurred ())
799
797
Expect (fake .addIndex ).To (Equal (len (fake .plugins )))
800
- Expect (len ( results )) .To (Equal (2 ))
798
+ Expect (results ).To (HaveLen (2 ))
801
799
r , ok := results [0 ].Result .(* cniv04.Result )
802
800
Expect (ok ).To (BeTrue ())
803
801
Expect (reflect .DeepEqual (r , expectedResult1 )).To (BeTrue ())
@@ -807,7 +805,7 @@ var _ = Describe("ocicni operations", func() {
807
805
808
806
resultsStatus , errStatus := ocicni .GetPodNetworkStatus (podNet )
809
807
Expect (errStatus ).NotTo (HaveOccurred ())
810
- Expect (len ( resultsStatus )) .To (Equal (2 ))
808
+ Expect (resultsStatus ).To (HaveLen (2 ))
811
809
r , ok = resultsStatus [0 ].Result .(* cniv04.Result )
812
810
Expect (ok ).To (BeTrue ())
813
811
Expect (reflect .DeepEqual (r , expectedResult1 )).To (BeTrue ())
@@ -897,16 +895,16 @@ var _ = Describe("ocicni operations", func() {
897
895
podNet .Networks = []NetAttachment {}
898
896
tmp , ok := ocicni .(* cniNetworkPlugin )
899
897
Expect (ok ).To (BeTrue ())
900
- Expect (len ( tmp .pods )) .To (Equal ( 0 ))
898
+ Expect (tmp .pods ).To (BeEmpty ( ))
901
899
tmp .podLock (& podNet )
902
- Expect (len ( tmp .pods )) .To (Equal (1 ))
900
+ Expect (tmp .pods ).To (HaveLen (1 ))
903
901
})
904
902
It ("verifies that network operations can be unlocked for a pod using cached networks" , func () {
905
903
podNet .Networks = []NetAttachment {}
906
904
tmp , ok := ocicni .(* cniNetworkPlugin )
907
905
Expect (ok ).To (BeTrue ())
908
906
tmp .podUnlock (& podNet )
909
- Expect (len ( tmp .pods )) .To (Equal ( 0 ))
907
+ Expect (tmp .pods ).To (BeEmpty ( ))
910
908
})
911
909
})
912
910
0 commit comments