@@ -3,7 +3,6 @@ package packit_test
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "io/ioutil"
7
6
"os"
8
7
"path/filepath"
9
8
"testing"
@@ -35,18 +34,18 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
35
34
workingDir , err = os .Getwd ()
36
35
Expect (err ).NotTo (HaveOccurred ())
37
36
38
- tmpDir , err = ioutil . TempDir ("" , "working-dir" )
37
+ tmpDir , err = os . MkdirTemp ("" , "working-dir" )
39
38
Expect (err ).NotTo (HaveOccurred ())
40
39
41
40
tmpDir , err = filepath .EvalSymlinks (tmpDir )
42
41
Expect (err ).NotTo (HaveOccurred ())
43
42
44
43
Expect (os .Chdir (tmpDir )).To (Succeed ())
45
44
46
- layersDir , err = ioutil . TempDir ("" , "layers" )
45
+ layersDir , err = os . MkdirTemp ("" , "layers" )
47
46
Expect (err ).NotTo (HaveOccurred ())
48
47
49
- file , err := ioutil . TempFile ("" , "plan.toml" )
48
+ file , err := os . CreateTemp ("" , "plan.toml" )
50
49
Expect (err ).NotTo (HaveOccurred ())
51
50
defer file .Close ()
52
51
@@ -62,10 +61,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
62
61
63
62
planPath = file .Name ()
64
63
65
- cnbDir , err = ioutil . TempDir ("" , "cnb" )
64
+ cnbDir , err = os . MkdirTemp ("" , "cnb" )
66
65
Expect (err ).NotTo (HaveOccurred ())
67
66
68
- envCnbDir , err = ioutil . TempDir ("" , "envCnb" )
67
+ envCnbDir , err = os . MkdirTemp ("" , "envCnb" )
69
68
Expect (err ).NotTo (HaveOccurred ())
70
69
71
70
bpTOML := []byte (`
@@ -76,8 +75,8 @@ api = "0.5"
76
75
version = "some-version"
77
76
clear-env = false
78
77
` )
79
- Expect (ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
80
- Expect (ioutil .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
78
+ Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
79
+ Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
81
80
82
81
binaryPath = filepath .Join (cnbDir , "bin" , "build" )
83
82
@@ -140,8 +139,8 @@ api = "0.4"
140
139
version = "some-version"
141
140
clear-env = false
142
141
` )
143
- Expect (ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
144
- Expect (ioutil .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
142
+ Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
143
+ Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
145
144
146
145
})
147
146
@@ -154,7 +153,7 @@ api = "0.4"
154
153
}, nil
155
154
}, packit .WithArgs ([]string {binaryPath , "" , "" , planPath }))
156
155
157
- contents , err := ioutil .ReadFile (planPath )
156
+ contents , err := os .ReadFile (planPath )
158
157
Expect (err ).NotTo (HaveOccurred ())
159
158
160
159
Expect (string (contents )).To (MatchTOML (`
@@ -202,7 +201,7 @@ api = "0.4"
202
201
}, nil
203
202
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
204
203
205
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "some-layer.toml" ))
204
+ contents , err := os .ReadFile (filepath .Join (layersDir , "some-layer.toml" ))
206
205
Expect (err ).NotTo (HaveOccurred ())
207
206
208
207
Expect (string (contents )).To (MatchTOML (`
@@ -222,10 +221,10 @@ cache = true
222
221
it .Before (func () {
223
222
obsoleteLayerPath = filepath .Join (layersDir , "obsolete-layer" )
224
223
Expect (os .MkdirAll (obsoleteLayerPath , os .ModePerm )).To (Succeed ())
225
- Expect (ioutil .WriteFile (obsoleteLayerPath + ".toml" , []byte {}, 0600 )).To (Succeed ())
224
+ Expect (os .WriteFile (obsoleteLayerPath + ".toml" , []byte {}, 0600 )).To (Succeed ())
226
225
227
- Expect (ioutil .WriteFile (filepath .Join (layersDir , "launch.toml" ), []byte {}, 0600 )).To (Succeed ())
228
- Expect (ioutil .WriteFile (filepath .Join (layersDir , "store.toml" ), []byte {}, 0600 )).To (Succeed ())
226
+ Expect (os .WriteFile (filepath .Join (layersDir , "launch.toml" ), []byte {}, 0600 )).To (Succeed ())
227
+ Expect (os .WriteFile (filepath .Join (layersDir , "store.toml" ), []byte {}, 0600 )).To (Succeed ())
229
228
})
230
229
231
230
it ("removes them" , func () {
@@ -295,7 +294,7 @@ cache = true
295
294
it .Before (func () {
296
295
unremovableTOMLPath = filepath .Join (layersDir , "unremovable.toml" )
297
296
Expect (os .MkdirAll (filepath .Join (layersDir , "unremovable" ), os .ModePerm )).To (Succeed ())
298
- Expect (ioutil .WriteFile (unremovableTOMLPath , []byte {}, os .ModePerm )).To (Succeed ())
297
+ Expect (os .WriteFile (unremovableTOMLPath , []byte {}, os .ModePerm )).To (Succeed ())
299
298
Expect (os .Chmod (layersDir , 0666 )).To (Succeed ())
300
299
})
301
300
@@ -335,7 +334,7 @@ cache = true
335
334
}, nil
336
335
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
337
336
338
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "build.toml" ))
337
+ contents , err := os .ReadFile (filepath .Join (layersDir , "build.toml" ))
339
338
Expect (err ).NotTo (HaveOccurred ())
340
339
341
340
Expect (string (contents )).To (MatchTOML (`
@@ -358,8 +357,8 @@ api = "0.4"
358
357
version = "some-version"
359
358
clear-env = false
360
359
` )
361
- Expect (ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
362
- Expect (ioutil .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
360
+ Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
361
+ Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
363
362
364
363
})
365
364
it ("throws an error" , func () {
@@ -403,7 +402,7 @@ api = "0.4"
403
402
}, nil
404
403
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
405
404
406
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "build.toml" ))
405
+ contents , err := os .ReadFile (filepath .Join (layersDir , "build.toml" ))
407
406
Expect (err ).NotTo (HaveOccurred ())
408
407
409
408
Expect (string (contents )).To (MatchTOML (`
@@ -423,8 +422,8 @@ api = "0.4"
423
422
version = "some-version"
424
423
clear-env = false
425
424
` )
426
- Expect (ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
427
- Expect (ioutil .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
425
+ Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
426
+ Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
428
427
429
428
})
430
429
@@ -470,7 +469,7 @@ api = "0.4"
470
469
}, nil
471
470
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
472
471
473
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
472
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
474
473
Expect (err ).NotTo (HaveOccurred ())
475
474
476
475
Expect (string (contents )).To (MatchTOML (`
@@ -501,7 +500,7 @@ api = "0.4"
501
500
}, nil
502
501
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
503
502
504
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
503
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
505
504
Expect (err ).NotTo (HaveOccurred ())
506
505
507
506
Expect (string (contents )).To (MatchTOML (`
@@ -530,7 +529,7 @@ api = "0.4"
530
529
}, nil
531
530
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
532
531
533
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
532
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
534
533
Expect (err ).NotTo (HaveOccurred ())
535
534
536
535
Expect (string (contents )).To (MatchTOML (`
@@ -558,7 +557,7 @@ api = "0.4"
558
557
}, nil
559
558
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
560
559
561
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
560
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
562
561
Expect (err ).NotTo (HaveOccurred ())
563
562
564
563
Expect (string (contents )).To (MatchTOML (`
@@ -581,7 +580,7 @@ api = "0.4"
581
580
}, nil
582
581
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
583
582
584
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
583
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
585
584
Expect (err ).NotTo (HaveOccurred ())
586
585
587
586
Expect (string (contents )).To (MatchTOML (`
@@ -605,7 +604,7 @@ api = "0.4"
605
604
}, nil
606
605
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
607
606
608
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
607
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
609
608
Expect (err ).NotTo (HaveOccurred ())
610
609
611
610
Expect (string (contents )).To (MatchTOML (`
@@ -632,7 +631,7 @@ api = "0.4"
632
631
}, nil
633
632
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
634
633
635
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "launch.toml" ))
634
+ contents , err := os .ReadFile (filepath .Join (layersDir , "launch.toml" ))
636
635
Expect (err ).NotTo (HaveOccurred ())
637
636
638
637
Expect (string (contents )).To (MatchTOML (`
@@ -679,7 +678,7 @@ api = "0.4"
679
678
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
680
679
681
680
for _ , modifier := range []string {"append" , "default" , "delim" , "prepend" , "override" } {
682
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "some-layer" , "env" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
681
+ contents , err := os .ReadFile (filepath .Join (layersDir , "some-layer" , "env" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
683
682
Expect (err ).NotTo (HaveOccurred ())
684
683
Expect (string (contents )).To (Equal (fmt .Sprintf ("%s-value" , modifier )))
685
684
}
@@ -706,7 +705,7 @@ api = "0.4"
706
705
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
707
706
708
707
for _ , modifier := range []string {"append" , "default" , "delim" , "prepend" , "override" } {
709
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "some-layer" , "env.launch" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
708
+ contents , err := os .ReadFile (filepath .Join (layersDir , "some-layer" , "env.launch" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
710
709
Expect (err ).NotTo (HaveOccurred ())
711
710
Expect (string (contents )).To (Equal (fmt .Sprintf ("%s-value" , modifier )))
712
711
}
@@ -740,7 +739,7 @@ api = "0.4"
740
739
741
740
for _ , process := range []string {"process-name" , "another-process-name" } {
742
741
for _ , modifier := range []string {"append" , "default" , "delim" , "prepend" , "override" } {
743
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "some-layer" , "env.launch" , process , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
742
+ contents , err := os .ReadFile (filepath .Join (layersDir , "some-layer" , "env.launch" , process , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
744
743
Expect (err ).NotTo (HaveOccurred ())
745
744
Expect (string (contents )).To (Equal (fmt .Sprintf ("%s-value" , modifier )))
746
745
}
@@ -768,7 +767,7 @@ api = "0.4"
768
767
}, packit .WithArgs ([]string {binaryPath , layersDir , "" , planPath }))
769
768
770
769
for _ , modifier := range []string {"append" , "default" , "delim" , "prepend" , "override" } {
771
- contents , err := ioutil .ReadFile (filepath .Join (layersDir , "some-layer" , "env.build" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
770
+ contents , err := os .ReadFile (filepath .Join (layersDir , "some-layer" , "env.build" , fmt .Sprintf ("SOME_VAR.%s" , modifier )))
772
771
Expect (err ).NotTo (HaveOccurred ())
773
772
Expect (string (contents )).To (Equal (fmt .Sprintf ("%s-value" , modifier )))
774
773
}
@@ -779,7 +778,7 @@ api = "0.4"
779
778
context ("failure cases" , func () {
780
779
context ("when the buildpack plan.toml is malformed" , func () {
781
780
it .Before (func () {
782
- err := ioutil .WriteFile (planPath , []byte ("%%%" ), 0600 )
781
+ err := os .WriteFile (planPath , []byte ("%%%" ), 0600 )
783
782
Expect (err ).NotTo (HaveOccurred ())
784
783
})
785
784
@@ -804,7 +803,7 @@ api = "0.4"
804
803
805
804
context ("when the buildpack.toml is malformed" , func () {
806
805
it .Before (func () {
807
- err := ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), []byte ("%%%" ), 0600 )
806
+ err := os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), []byte ("%%%" ), 0600 )
808
807
Expect (err ).NotTo (HaveOccurred ())
809
808
})
810
809
@@ -827,8 +826,8 @@ api = "0.4"
827
826
version = "some-version"
828
827
clear-env = false
829
828
` )
830
- Expect (ioutil .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
831
- Expect (ioutil .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
829
+ Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
830
+ Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
832
831
Expect (os .Chmod (planPath , 0444 )).To (Succeed ())
833
832
})
834
833
@@ -893,7 +892,7 @@ api = "0.4"
893
892
var envDir string
894
893
it .Before (func () {
895
894
var err error
896
- envDir , err = ioutil . TempDir ("" , "environment" )
895
+ envDir , err = os . MkdirTemp ("" , "environment" )
897
896
Expect (err ).NotTo (HaveOccurred ())
898
897
899
898
Expect (os .Chmod (envDir , 0000 )).To (Succeed ())
0 commit comments