5
5
"encoding/base64"
6
6
"encoding/json"
7
7
"fmt"
8
- "io/ioutil"
9
8
"net"
10
9
"os"
11
10
"path/filepath"
@@ -32,7 +31,7 @@ func writeConfig(dir, fileName, netName, plugin string, version string) (string,
32
31
"type": "%s",
33
32
"cniVersion": "%s"
34
33
}` , netName , plugin , version )
35
- return conf , confPath , ioutil .WriteFile (confPath , []byte (conf ), 0644 )
34
+ return conf , confPath , os .WriteFile (confPath , []byte (conf ), 0644 )
36
35
}
37
36
38
37
func writeCacheFile (dir , containerID , netName , ifname , config string ) {
@@ -52,7 +51,7 @@ func writeCacheFile(dir, containerID, netName, ifname, config string) {
52
51
Expect (err ).NotTo (HaveOccurred ())
53
52
54
53
filePath := filepath .Join (dirName , fmt .Sprintf ("%s-%s-%s" , netName , containerID , ifname ))
55
- err = ioutil .WriteFile (filePath , []byte (cachedData ), 0644 )
54
+ err = os .WriteFile (filePath , []byte (cachedData ), 0644 )
56
55
Expect (err ).NotTo (HaveOccurred ())
57
56
}
58
57
@@ -146,7 +145,10 @@ func (f *fakeExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData
146
145
// SetUpPod We only care about a few fields
147
146
testConf := & TestConf {}
148
147
err = json .Unmarshal (stdinData , & testConf )
148
+ Expect (err ).NotTo (HaveOccurred ())
149
+
149
150
testData , err := json .Marshal (testConf )
151
+ Expect (err ).NotTo (HaveOccurred ())
150
152
if plugin .expectedConf != "" {
151
153
Expect (string (testData )).To (MatchJSON (plugin .expectedConf ))
152
154
}
@@ -193,11 +195,11 @@ var _ = Describe("ocicni operations", func() {
193
195
194
196
BeforeEach (func () {
195
197
var err error
196
- tmpDir , err = ioutil . TempDir ("" , "ocicni_tmp" )
198
+ tmpDir , err = os . MkdirTemp ("" , "ocicni_tmp" )
197
199
Expect (err ).NotTo (HaveOccurred ())
198
- tmpBinDir , err = ioutil . TempDir ("" , "ocicni_tmp_bin" )
200
+ tmpBinDir , err = os . MkdirTemp ("" , "ocicni_tmp_bin" )
199
201
Expect (err ).NotTo (HaveOccurred ())
200
- cacheDir , err = ioutil . TempDir ("" , "ocicni_cache" )
202
+ cacheDir , err = os . MkdirTemp ("" , "ocicni_cache" )
201
203
Expect (err ).NotTo (HaveOccurred ())
202
204
203
205
networkNS , err = testutils .NewNS ()
@@ -233,7 +235,7 @@ var _ = Describe("ocicni operations", func() {
233
235
Expect (len (net .config .Plugins )).To (BeNumerically (">" , 0 ))
234
236
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
235
237
236
- ocicni .Shutdown ()
238
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
237
239
})
238
240
239
241
It ("finds an asynchronously written default network configuration" , func () {
@@ -255,7 +257,7 @@ var _ = Describe("ocicni operations", func() {
255
257
Expect (len (net .config .Plugins )).To (BeNumerically (">" , 0 ))
256
258
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
257
259
258
- ocicni .Shutdown ()
260
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
259
261
})
260
262
261
263
It ("finds an asynchronously written default network configuration whose plugin is written later" , func () {
@@ -269,7 +271,7 @@ var _ = Describe("ocicni operations", func() {
269
271
270
272
// Write a file in the bindir to trigger the fsnotify code to resync
271
273
fExec .failFind = false
272
- err = ioutil .WriteFile (filepath .Join (tmpBinDir , "myplugin" ), []byte ("adsfasdfsafd" ), 0755 )
274
+ err = os .WriteFile (filepath .Join (tmpBinDir , "myplugin" ), []byte ("adsfasdfsafd" ), 0755 )
273
275
Expect (err ).NotTo (HaveOccurred ())
274
276
275
277
tmp := ocicni .(* cniNetworkPlugin )
@@ -290,7 +292,7 @@ var _ = Describe("ocicni operations", func() {
290
292
return nil
291
293
}, 10 ).Should (Succeed ())
292
294
293
- ocicni .Shutdown ()
295
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
294
296
})
295
297
296
298
It ("should monitor the net conf dir for changes when default network is not specified" , func () {
@@ -321,7 +323,7 @@ var _ = Describe("ocicni operations", func() {
321
323
Expect (len (net .config .Plugins )).To (BeNumerically (">" , 0 ))
322
324
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("testplugin" ))
323
325
324
- ocicni .Shutdown ()
326
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
325
327
})
326
328
327
329
It ("should monitor the net conf dir for changes when default network is specified" , func () {
@@ -352,7 +354,7 @@ var _ = Describe("ocicni operations", func() {
352
354
Expect (len (net .config .Plugins )).To (BeNumerically (">" , 0 ))
353
355
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("testplugin" ))
354
356
355
- ocicni .Shutdown ()
357
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
356
358
})
357
359
358
360
It ("finds and refinds an asynchronously written default network configuration" , func () {
@@ -382,7 +384,7 @@ var _ = Describe("ocicni operations", func() {
382
384
Expect (err ).NotTo (HaveOccurred ())
383
385
Eventually (ocicni .Status , 5 ).Should (Succeed ())
384
386
385
- ocicni .Shutdown ()
387
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
386
388
})
387
389
388
390
It ("finds an ASCIIbetically first network configuration as default real-time if given no default network name" , func () {
@@ -414,7 +416,7 @@ var _ = Describe("ocicni operations", func() {
414
416
Expect (len (net .config .Plugins )).To (BeNumerically (">" , 0 ))
415
417
Expect (net .config .Plugins [0 ].Network .Type ).To (Equal ("myplugin" ))
416
418
417
- ocicni .Shutdown ()
419
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
418
420
})
419
421
420
422
It ("returns correct default network from loadNetworks()" , func () {
@@ -638,7 +640,7 @@ var _ = Describe("ocicni operations", func() {
638
640
Expect (err ).NotTo (HaveOccurred ())
639
641
Expect (fake .delIndex ).To (Equal (len (fake .plugins )))
640
642
641
- ocicni .Shutdown ()
643
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
642
644
})
643
645
644
646
It ("sets up and tears down a pod using specified networks" , func () {
@@ -715,7 +717,7 @@ var _ = Describe("ocicni operations", func() {
715
717
Expect (err ).NotTo (HaveOccurred ())
716
718
Expect (fake .delIndex ).To (Equal (len (fake .plugins )))
717
719
718
- ocicni .Shutdown ()
720
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
719
721
})
720
722
721
723
It ("sets up and tears down a pod using specified v4 networks" , func () {
@@ -801,7 +803,7 @@ var _ = Describe("ocicni operations", func() {
801
803
Expect (err ).NotTo (HaveOccurred ())
802
804
Expect (fake .delIndex ).To (Equal (len (fake .plugins )))
803
805
804
- ocicni .Shutdown ()
806
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
805
807
})
806
808
807
809
Context ("when tearing down a pod using cached info" , func () {
@@ -855,7 +857,7 @@ var _ = Describe("ocicni operations", func() {
855
857
})
856
858
857
859
AfterEach (func () {
858
- ocicni .Shutdown ()
860
+ Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
859
861
})
860
862
861
863
It ("uses the specified networks" , func () {
@@ -910,7 +912,7 @@ var _ = Describe("ocicni operations", func() {
910
912
911
913
ocicni , err := initCNI (fake , cacheDir , defaultNetName , tmpDir , true , "/opt/cni/bin" )
912
914
Expect (err ).NotTo (HaveOccurred ())
913
- defer ocicni .Shutdown ()
915
+ defer Expect ( ocicni .Shutdown ()). NotTo ( HaveOccurred () )
914
916
915
917
podNet := PodNetwork {
916
918
Name : "pod1" ,
0 commit comments