Skip to content

Commit 5a60c46

Browse files
ForestEckhardtryanmoran
authored andcommitted
Refactor to remove ioutil which is depercated
- Also formats the imports
1 parent 173f021 commit 5a60c46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+265
-304
lines changed

build_test.go

+37-38
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package packit_test
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"testing"
@@ -35,18 +34,18 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
3534
workingDir, err = os.Getwd()
3635
Expect(err).NotTo(HaveOccurred())
3736

38-
tmpDir, err = ioutil.TempDir("", "working-dir")
37+
tmpDir, err = os.MkdirTemp("", "working-dir")
3938
Expect(err).NotTo(HaveOccurred())
4039

4140
tmpDir, err = filepath.EvalSymlinks(tmpDir)
4241
Expect(err).NotTo(HaveOccurred())
4342

4443
Expect(os.Chdir(tmpDir)).To(Succeed())
4544

46-
layersDir, err = ioutil.TempDir("", "layers")
45+
layersDir, err = os.MkdirTemp("", "layers")
4746
Expect(err).NotTo(HaveOccurred())
4847

49-
file, err := ioutil.TempFile("", "plan.toml")
48+
file, err := os.CreateTemp("", "plan.toml")
5049
Expect(err).NotTo(HaveOccurred())
5150
defer file.Close()
5251

@@ -62,10 +61,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
6261

6362
planPath = file.Name()
6463

65-
cnbDir, err = ioutil.TempDir("", "cnb")
64+
cnbDir, err = os.MkdirTemp("", "cnb")
6665
Expect(err).NotTo(HaveOccurred())
6766

68-
envCnbDir, err = ioutil.TempDir("", "envCnb")
67+
envCnbDir, err = os.MkdirTemp("", "envCnb")
6968
Expect(err).NotTo(HaveOccurred())
7069

7170
bpTOML := []byte(`
@@ -76,8 +75,8 @@ api = "0.5"
7675
version = "some-version"
7776
clear-env = false
7877
`)
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())
8180

8281
binaryPath = filepath.Join(cnbDir, "bin", "build")
8382

@@ -140,8 +139,8 @@ api = "0.4"
140139
version = "some-version"
141140
clear-env = false
142141
`)
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())
145144

146145
})
147146

@@ -154,7 +153,7 @@ api = "0.4"
154153
}, nil
155154
}, packit.WithArgs([]string{binaryPath, "", "", planPath}))
156155

157-
contents, err := ioutil.ReadFile(planPath)
156+
contents, err := os.ReadFile(planPath)
158157
Expect(err).NotTo(HaveOccurred())
159158

160159
Expect(string(contents)).To(MatchTOML(`
@@ -202,7 +201,7 @@ api = "0.4"
202201
}, nil
203202
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
204203

205-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer.toml"))
204+
contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer.toml"))
206205
Expect(err).NotTo(HaveOccurred())
207206

208207
Expect(string(contents)).To(MatchTOML(`
@@ -222,10 +221,10 @@ cache = true
222221
it.Before(func() {
223222
obsoleteLayerPath = filepath.Join(layersDir, "obsolete-layer")
224223
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())
226225

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())
229228
})
230229

231230
it("removes them", func() {
@@ -295,7 +294,7 @@ cache = true
295294
it.Before(func() {
296295
unremovableTOMLPath = filepath.Join(layersDir, "unremovable.toml")
297296
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())
299298
Expect(os.Chmod(layersDir, 0666)).To(Succeed())
300299
})
301300

@@ -335,7 +334,7 @@ cache = true
335334
}, nil
336335
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
337336

338-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "build.toml"))
337+
contents, err := os.ReadFile(filepath.Join(layersDir, "build.toml"))
339338
Expect(err).NotTo(HaveOccurred())
340339

341340
Expect(string(contents)).To(MatchTOML(`
@@ -358,8 +357,8 @@ api = "0.4"
358357
version = "some-version"
359358
clear-env = false
360359
`)
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())
363362

364363
})
365364
it("throws an error", func() {
@@ -403,7 +402,7 @@ api = "0.4"
403402
}, nil
404403
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
405404

406-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "build.toml"))
405+
contents, err := os.ReadFile(filepath.Join(layersDir, "build.toml"))
407406
Expect(err).NotTo(HaveOccurred())
408407

409408
Expect(string(contents)).To(MatchTOML(`
@@ -423,8 +422,8 @@ api = "0.4"
423422
version = "some-version"
424423
clear-env = false
425424
`)
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())
428427

429428
})
430429

@@ -470,7 +469,7 @@ api = "0.4"
470469
}, nil
471470
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
472471

473-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
472+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
474473
Expect(err).NotTo(HaveOccurred())
475474

476475
Expect(string(contents)).To(MatchTOML(`
@@ -501,7 +500,7 @@ api = "0.4"
501500
}, nil
502501
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
503502

504-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
503+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
505504
Expect(err).NotTo(HaveOccurred())
506505

507506
Expect(string(contents)).To(MatchTOML(`
@@ -530,7 +529,7 @@ api = "0.4"
530529
}, nil
531530
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
532531

533-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
532+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
534533
Expect(err).NotTo(HaveOccurred())
535534

536535
Expect(string(contents)).To(MatchTOML(`
@@ -558,7 +557,7 @@ api = "0.4"
558557
}, nil
559558
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
560559

561-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
560+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
562561
Expect(err).NotTo(HaveOccurred())
563562

564563
Expect(string(contents)).To(MatchTOML(`
@@ -581,7 +580,7 @@ api = "0.4"
581580
}, nil
582581
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
583582

584-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
583+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
585584
Expect(err).NotTo(HaveOccurred())
586585

587586
Expect(string(contents)).To(MatchTOML(`
@@ -605,7 +604,7 @@ api = "0.4"
605604
}, nil
606605
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
607606

608-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
607+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
609608
Expect(err).NotTo(HaveOccurred())
610609

611610
Expect(string(contents)).To(MatchTOML(`
@@ -632,7 +631,7 @@ api = "0.4"
632631
}, nil
633632
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
634633

635-
contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml"))
634+
contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml"))
636635
Expect(err).NotTo(HaveOccurred())
637636

638637
Expect(string(contents)).To(MatchTOML(`
@@ -679,7 +678,7 @@ api = "0.4"
679678
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
680679

681680
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)))
683682
Expect(err).NotTo(HaveOccurred())
684683
Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier)))
685684
}
@@ -706,7 +705,7 @@ api = "0.4"
706705
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
707706

708707
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)))
710709
Expect(err).NotTo(HaveOccurred())
711710
Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier)))
712711
}
@@ -740,7 +739,7 @@ api = "0.4"
740739

741740
for _, process := range []string{"process-name", "another-process-name"} {
742741
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)))
744743
Expect(err).NotTo(HaveOccurred())
745744
Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier)))
746745
}
@@ -768,7 +767,7 @@ api = "0.4"
768767
}, packit.WithArgs([]string{binaryPath, layersDir, "", planPath}))
769768

770769
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)))
772771
Expect(err).NotTo(HaveOccurred())
773772
Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier)))
774773
}
@@ -779,7 +778,7 @@ api = "0.4"
779778
context("failure cases", func() {
780779
context("when the buildpack plan.toml is malformed", func() {
781780
it.Before(func() {
782-
err := ioutil.WriteFile(planPath, []byte("%%%"), 0600)
781+
err := os.WriteFile(planPath, []byte("%%%"), 0600)
783782
Expect(err).NotTo(HaveOccurred())
784783
})
785784

@@ -804,7 +803,7 @@ api = "0.4"
804803

805804
context("when the buildpack.toml is malformed", func() {
806805
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)
808807
Expect(err).NotTo(HaveOccurred())
809808
})
810809

@@ -827,8 +826,8 @@ api = "0.4"
827826
version = "some-version"
828827
clear-env = false
829828
`)
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())
832831
Expect(os.Chmod(planPath, 0444)).To(Succeed())
833832
})
834833

@@ -893,7 +892,7 @@ api = "0.4"
893892
var envDir string
894893
it.Before(func() {
895894
var err error
896-
envDir, err = ioutil.TempDir("", "environment")
895+
envDir, err = os.MkdirTemp("", "environment")
897896
Expect(err).NotTo(HaveOccurred())
898897

899898
Expect(os.Chmod(envDir, 0000)).To(Succeed())

cargo/buildpack_parser_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cargo_test
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76
"time"
@@ -21,7 +20,7 @@ func testBuildpackParser(t *testing.T, context spec.G, it spec.S) {
2120
)
2221

2322
it.Before(func() {
24-
file, err := ioutil.TempFile("", "buildpack.toml")
23+
file, err := os.CreateTemp("", "buildpack.toml")
2524
Expect(err).NotTo(HaveOccurred())
2625

2726
_, err = file.WriteString(`api = "0.2"
@@ -103,7 +102,7 @@ pre-package = "some-pre-package-script.sh"
103102

104103
context("when the buildpack.toml is malformed", func() {
105104
it.Before(func() {
106-
Expect(ioutil.WriteFile(path, []byte("%%%"), 0644)).To(Succeed())
105+
Expect(os.WriteFile(path, []byte("%%%"), 0644)).To(Succeed())
107106
})
108107

109108
it("returns an error", func() {

cargo/directory_duplicator_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cargo_test
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"os"
66
"path/filepath"
77
"testing"
@@ -23,16 +23,16 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) {
2323
it.Before(func() {
2424
var err error
2525

26-
sourceDir, err = ioutil.TempDir("", "source")
26+
sourceDir, err = os.MkdirTemp("", "source")
2727
Expect(err).NotTo(HaveOccurred())
2828

29-
Expect(ioutil.WriteFile(filepath.Join(sourceDir, "some-file"), []byte("some content"), 0644)).To(Succeed())
29+
Expect(os.WriteFile(filepath.Join(sourceDir, "some-file"), []byte("some content"), 0644)).To(Succeed())
3030

3131
Expect(os.MkdirAll(filepath.Join(sourceDir, "some-dir"), os.ModePerm)).To(Succeed())
32-
Expect(ioutil.WriteFile(filepath.Join(sourceDir, "some-dir", "other-file"), []byte("other content"), 0755)).To(Succeed())
32+
Expect(os.WriteFile(filepath.Join(sourceDir, "some-dir", "other-file"), []byte("other content"), 0755)).To(Succeed())
3333
Expect(os.Symlink("other-file", filepath.Join(sourceDir, "some-dir", "link"))).To(Succeed())
3434

35-
destDir, err = ioutil.TempDir("", "dest")
35+
destDir, err = os.MkdirTemp("", "dest")
3636
Expect(err).NotTo(HaveOccurred())
3737

3838
directoryDup = cargo.NewDirectoryDuplicator()
@@ -50,7 +50,7 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) {
5050
file, err := os.Open(filepath.Join(destDir, "some-file"))
5151
Expect(err).NotTo(HaveOccurred())
5252

53-
content, err := ioutil.ReadAll(file)
53+
content, err := io.ReadAll(file)
5454
Expect(err).NotTo(HaveOccurred())
5555
Expect(string(content)).To(Equal("some content"))
5656

@@ -67,7 +67,7 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) {
6767
file, err = os.Open(filepath.Join(destDir, "some-dir", "other-file"))
6868
Expect(err).NotTo(HaveOccurred())
6969

70-
content, err = ioutil.ReadAll(file)
70+
content, err = io.ReadAll(file)
7171
Expect(err).NotTo(HaveOccurred())
7272
Expect(string(content)).To(Equal("other content"))
7373

cargo/jam/commands/pack.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package commands
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
59
"github.com/paketo-buildpacks/packit/cargo"
610
"github.com/paketo-buildpacks/packit/cargo/jam/internal"
711
"github.com/paketo-buildpacks/packit/pexec"
812
"github.com/paketo-buildpacks/packit/scribe"
913
"github.com/spf13/cobra"
10-
"io/ioutil"
11-
"os"
12-
"path/filepath"
13-
"strings"
1414
)
1515

1616
type packFlags struct {
@@ -56,7 +56,7 @@ func init() {
5656
}
5757

5858
func packRun(flags packFlags) error {
59-
buildpackDir, err := ioutil.TempDir("", "dup-dest")
59+
buildpackDir, err := os.MkdirTemp("", "dup-dest")
6060
if err != nil {
6161
return fmt.Errorf("unable to create temporary directory: %s", err)
6262
}

cargo/jam/commands/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "github.com/spf13/cobra"
44

55
var (
66
rootCmd = &cobra.Command{
7-
Use: "jam",
7+
Use: "jam",
88
}
99
)
1010

0 commit comments

Comments
 (0)