diff --git a/build_test.go b/build_test.go index 3ca0421c..81002c6c 100644 --- a/build_test.go +++ b/build_test.go @@ -3,7 +3,6 @@ package packit_test import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -35,7 +34,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { workingDir, err = os.Getwd() Expect(err).NotTo(HaveOccurred()) - tmpDir, err = ioutil.TempDir("", "working-dir") + tmpDir, err = os.MkdirTemp("", "working-dir") Expect(err).NotTo(HaveOccurred()) tmpDir, err = filepath.EvalSymlinks(tmpDir) @@ -43,10 +42,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { Expect(os.Chdir(tmpDir)).To(Succeed()) - layersDir, err = ioutil.TempDir("", "layers") + layersDir, err = os.MkdirTemp("", "layers") Expect(err).NotTo(HaveOccurred()) - file, err := ioutil.TempFile("", "plan.toml") + file, err := os.CreateTemp("", "plan.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -62,10 +61,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { planPath = file.Name() - cnbDir, err = ioutil.TempDir("", "cnb") + cnbDir, err = os.MkdirTemp("", "cnb") Expect(err).NotTo(HaveOccurred()) - envCnbDir, err = ioutil.TempDir("", "envCnb") + envCnbDir, err = os.MkdirTemp("", "envCnb") Expect(err).NotTo(HaveOccurred()) bpTOML := []byte(` @@ -76,8 +75,8 @@ api = "0.5" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) binaryPath = filepath.Join(cnbDir, "bin", "build") @@ -140,8 +139,8 @@ api = "0.4" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) }) @@ -154,7 +153,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, "", "", planPath})) - contents, err := ioutil.ReadFile(planPath) + contents, err := os.ReadFile(planPath) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -202,7 +201,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -222,10 +221,10 @@ cache = true it.Before(func() { obsoleteLayerPath = filepath.Join(layersDir, "obsolete-layer") Expect(os.MkdirAll(obsoleteLayerPath, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(obsoleteLayerPath+".toml", []byte{}, 0600)).To(Succeed()) + Expect(os.WriteFile(obsoleteLayerPath+".toml", []byte{}, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(layersDir, "launch.toml"), []byte{}, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(layersDir, "store.toml"), []byte{}, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(layersDir, "launch.toml"), []byte{}, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(layersDir, "store.toml"), []byte{}, 0600)).To(Succeed()) }) it("removes them", func() { @@ -295,7 +294,7 @@ cache = true it.Before(func() { unremovableTOMLPath = filepath.Join(layersDir, "unremovable.toml") Expect(os.MkdirAll(filepath.Join(layersDir, "unremovable"), os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(unremovableTOMLPath, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(unremovableTOMLPath, []byte{}, os.ModePerm)).To(Succeed()) Expect(os.Chmod(layersDir, 0666)).To(Succeed()) }) @@ -335,7 +334,7 @@ cache = true }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "build.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "build.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -358,8 +357,8 @@ api = "0.4" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) }) it("throws an error", func() { @@ -403,7 +402,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "build.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "build.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -423,8 +422,8 @@ api = "0.4" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) }) @@ -470,7 +469,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -501,7 +500,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -530,7 +529,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -558,7 +557,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -581,7 +580,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -605,7 +604,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -632,7 +631,7 @@ api = "0.4" }, nil }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "launch.toml")) + contents, err := os.ReadFile(filepath.Join(layersDir, "launch.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -679,7 +678,7 @@ api = "0.4" }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) for _, modifier := range []string{"append", "default", "delim", "prepend", "override"} { - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer", "env", fmt.Sprintf("SOME_VAR.%s", modifier))) + contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer", "env", fmt.Sprintf("SOME_VAR.%s", modifier))) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier))) } @@ -706,7 +705,7 @@ api = "0.4" }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) for _, modifier := range []string{"append", "default", "delim", "prepend", "override"} { - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer", "env.launch", fmt.Sprintf("SOME_VAR.%s", modifier))) + contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer", "env.launch", fmt.Sprintf("SOME_VAR.%s", modifier))) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier))) } @@ -740,7 +739,7 @@ api = "0.4" for _, process := range []string{"process-name", "another-process-name"} { for _, modifier := range []string{"append", "default", "delim", "prepend", "override"} { - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer", "env.launch", process, fmt.Sprintf("SOME_VAR.%s", modifier))) + contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer", "env.launch", process, fmt.Sprintf("SOME_VAR.%s", modifier))) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier))) } @@ -768,7 +767,7 @@ api = "0.4" }, packit.WithArgs([]string{binaryPath, layersDir, "", planPath})) for _, modifier := range []string{"append", "default", "delim", "prepend", "override"} { - contents, err := ioutil.ReadFile(filepath.Join(layersDir, "some-layer", "env.build", fmt.Sprintf("SOME_VAR.%s", modifier))) + contents, err := os.ReadFile(filepath.Join(layersDir, "some-layer", "env.build", fmt.Sprintf("SOME_VAR.%s", modifier))) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal(fmt.Sprintf("%s-value", modifier))) } @@ -779,7 +778,7 @@ api = "0.4" context("failure cases", func() { context("when the buildpack plan.toml is malformed", func() { it.Before(func() { - err := ioutil.WriteFile(planPath, []byte("%%%"), 0600) + err := os.WriteFile(planPath, []byte("%%%"), 0600) Expect(err).NotTo(HaveOccurred()) }) @@ -804,7 +803,7 @@ api = "0.4" context("when the buildpack.toml is malformed", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), []byte("%%%"), 0600) + err := os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), []byte("%%%"), 0600) Expect(err).NotTo(HaveOccurred()) }) @@ -827,8 +826,8 @@ api = "0.4" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed()) Expect(os.Chmod(planPath, 0444)).To(Succeed()) }) @@ -893,7 +892,7 @@ api = "0.4" var envDir string it.Before(func() { var err error - envDir, err = ioutil.TempDir("", "environment") + envDir, err = os.MkdirTemp("", "environment") Expect(err).NotTo(HaveOccurred()) Expect(os.Chmod(envDir, 0000)).To(Succeed()) diff --git a/cargo/buildpack_parser_test.go b/cargo/buildpack_parser_test.go index 4b50434a..4f31801e 100644 --- a/cargo/buildpack_parser_test.go +++ b/cargo/buildpack_parser_test.go @@ -1,7 +1,6 @@ package cargo_test import ( - "io/ioutil" "os" "testing" "time" @@ -21,7 +20,7 @@ func testBuildpackParser(t *testing.T, context spec.G, it spec.S) { ) it.Before(func() { - file, err := ioutil.TempFile("", "buildpack.toml") + file, err := os.CreateTemp("", "buildpack.toml") Expect(err).NotTo(HaveOccurred()) _, err = file.WriteString(`api = "0.2" @@ -103,7 +102,7 @@ pre-package = "some-pre-package-script.sh" context("when the buildpack.toml is malformed", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte("%%%"), 0644)).To(Succeed()) + Expect(os.WriteFile(path, []byte("%%%"), 0644)).To(Succeed()) }) it("returns an error", func() { diff --git a/cargo/directory_duplicator_test.go b/cargo/directory_duplicator_test.go index 0458d149..65eb79f0 100644 --- a/cargo/directory_duplicator_test.go +++ b/cargo/directory_duplicator_test.go @@ -1,7 +1,7 @@ package cargo_test import ( - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -23,16 +23,16 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - sourceDir, err = ioutil.TempDir("", "source") + sourceDir, err = os.MkdirTemp("", "source") Expect(err).NotTo(HaveOccurred()) - Expect(ioutil.WriteFile(filepath.Join(sourceDir, "some-file"), []byte("some content"), 0644)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(sourceDir, "some-file"), []byte("some content"), 0644)).To(Succeed()) Expect(os.MkdirAll(filepath.Join(sourceDir, "some-dir"), os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(sourceDir, "some-dir", "other-file"), []byte("other content"), 0755)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(sourceDir, "some-dir", "other-file"), []byte("other content"), 0755)).To(Succeed()) Expect(os.Symlink("other-file", filepath.Join(sourceDir, "some-dir", "link"))).To(Succeed()) - destDir, err = ioutil.TempDir("", "dest") + destDir, err = os.MkdirTemp("", "dest") Expect(err).NotTo(HaveOccurred()) directoryDup = cargo.NewDirectoryDuplicator() @@ -50,7 +50,7 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) { file, err := os.Open(filepath.Join(destDir, "some-file")) Expect(err).NotTo(HaveOccurred()) - content, err := ioutil.ReadAll(file) + content, err := io.ReadAll(file) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some content")) @@ -67,7 +67,7 @@ func testDirectoryDuplicator(t *testing.T, context spec.G, it spec.S) { file, err = os.Open(filepath.Join(destDir, "some-dir", "other-file")) Expect(err).NotTo(HaveOccurred()) - content, err = ioutil.ReadAll(file) + content, err = io.ReadAll(file) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("other content")) diff --git a/cargo/jam/commands/pack.go b/cargo/jam/commands/pack.go index 3b875405..c8cb6a28 100644 --- a/cargo/jam/commands/pack.go +++ b/cargo/jam/commands/pack.go @@ -2,15 +2,15 @@ package commands import ( "fmt" + "os" + "path/filepath" + "strings" + "github.com/paketo-buildpacks/packit/cargo" "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/paketo-buildpacks/packit/pexec" "github.com/paketo-buildpacks/packit/scribe" "github.com/spf13/cobra" - "io/ioutil" - "os" - "path/filepath" - "strings" ) type packFlags struct { @@ -56,7 +56,7 @@ func init() { } func packRun(flags packFlags) error { - buildpackDir, err := ioutil.TempDir("", "dup-dest") + buildpackDir, err := os.MkdirTemp("", "dup-dest") if err != nil { return fmt.Errorf("unable to create temporary directory: %s", err) } diff --git a/cargo/jam/commands/root.go b/cargo/jam/commands/root.go index 74fe8875..c2cab9fb 100644 --- a/cargo/jam/commands/root.go +++ b/cargo/jam/commands/root.go @@ -4,7 +4,7 @@ import "github.com/spf13/cobra" var ( rootCmd = &cobra.Command{ - Use: "jam", + Use: "jam", } ) diff --git a/cargo/jam/commands/summarize.go b/cargo/jam/commands/summarize.go index 8d8e64d0..166db154 100644 --- a/cargo/jam/commands/summarize.go +++ b/cargo/jam/commands/summarize.go @@ -2,9 +2,10 @@ package commands import ( "fmt" + "os" + "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/spf13/cobra" - "os" ) type summarizeFlags struct { @@ -13,7 +14,7 @@ type summarizeFlags struct { } func summarize() *cobra.Command { - flags :=&summarizeFlags{} + flags := &summarizeFlags{} cmd := &cobra.Command{ Use: "summarize", Short: "summarize buildpackage", @@ -43,7 +44,6 @@ func summarizeRun(flags summarizeFlags) error { return fmt.Errorf("failed to inspect buildpack dependencies: %w", err) } - switch flags.format { case "markdown": formatter.Markdown(configs) diff --git a/cargo/jam/commands/update_builder.go b/cargo/jam/commands/update_builder.go index f25d2dc8..02868b88 100644 --- a/cargo/jam/commands/update_builder.go +++ b/cargo/jam/commands/update_builder.go @@ -2,9 +2,10 @@ package commands import ( "fmt" + "os" + "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/spf13/cobra" - "os" ) type updateBuilderFlags struct { @@ -13,7 +14,7 @@ type updateBuilderFlags struct { } func updateBuilder() *cobra.Command { - flags :=&updateBuilderFlags{} + flags := &updateBuilderFlags{} cmd := &cobra.Command{ Use: "update-builder", Short: "update builder", diff --git a/cargo/jam/commands/update_buildpack.go b/cargo/jam/commands/update_buildpack.go index cb430709..51742ba8 100644 --- a/cargo/jam/commands/update_buildpack.go +++ b/cargo/jam/commands/update_buildpack.go @@ -2,18 +2,19 @@ package commands import ( "fmt" + "os" + "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/spf13/cobra" - "os" ) type updateBuildpackFlags struct { - buildpackFile string - packageFile string + buildpackFile string + packageFile string } func updateBuildpack() *cobra.Command { - flags :=&updateBuildpackFlags{} + flags := &updateBuildpackFlags{} cmd := &cobra.Command{ Use: "update-buildpack", Short: "update buildpack", diff --git a/cargo/jam/init_test.go b/cargo/jam/init_test.go index b5ac94f2..b1c8aab2 100644 --- a/cargo/jam/init_test.go +++ b/cargo/jam/init_test.go @@ -6,7 +6,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" "sync" "testing" @@ -73,7 +72,7 @@ func ExtractFile(file *os.File, name string) ([]byte, *tar.Header, error) { } if hdr.Name == name { - contents, err := ioutil.ReadAll(tr) + contents, err := io.ReadAll(tr) if err != nil { return nil, nil, err } diff --git a/cargo/jam/internal/builder_config_test.go b/cargo/jam/internal/builder_config_test.go index 9ee33680..a9a298c9 100644 --- a/cargo/jam/internal/builder_config_test.go +++ b/cargo/jam/internal/builder_config_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "testing" @@ -21,7 +20,7 @@ func testBuilderConfig(t *testing.T, context spec.G, it spec.S) { context("ParsePackageConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "package.toml") + file, err := os.CreateTemp("", "package.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -127,7 +126,7 @@ description = "Some description" context("when the file contents cannot be parsed", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) + Expect(os.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) }) it("returns an error", func() { @@ -139,7 +138,7 @@ description = "Some description" context("when a dependency uri is not valid", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte(` + Expect(os.WriteFile(path, []byte(` [[buildpacks]] uri = "docker://some-registry/some-repository/some-buildpack-id:0.0.10" version = "0.0.10" @@ -164,7 +163,7 @@ description = "Some description" context("OverwritePackageConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "builder.toml") + file, err := os.CreateTemp("", "builder.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -221,7 +220,7 @@ description = "Some description" }) Expect(err).NotTo(HaveOccurred()) - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` description = "Some description" diff --git a/cargo/jam/internal/buildpack_config_test.go b/cargo/jam/internal/buildpack_config_test.go index 88b5a1ff..cc430561 100644 --- a/cargo/jam/internal/buildpack_config_test.go +++ b/cargo/jam/internal/buildpack_config_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "testing" @@ -21,7 +20,7 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) { context("ParseBuildpackConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "buildpack.toml") + file, err := os.CreateTemp("", "buildpack.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -112,7 +111,7 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) { context("when the file contents cannot be parsed", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) + Expect(os.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) }) it("returns an error", func() { @@ -126,7 +125,7 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) { context("OverwriteBuildpackConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "buildpack.toml") + file, err := os.CreateTemp("", "buildpack.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -177,7 +176,7 @@ func testBuildpackConfig(t *testing.T, context spec.G, it spec.S) { }) Expect(err).NotTo(HaveOccurred()) - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` api = "0.2" diff --git a/cargo/jam/internal/buildpack_inspector_test.go b/cargo/jam/internal/buildpack_inspector_test.go index bf07f8c6..5e8a72dc 100644 --- a/cargo/jam/internal/buildpack_inspector_test.go +++ b/cargo/jam/internal/buildpack_inspector_test.go @@ -5,7 +5,6 @@ import ( "bytes" "compress/gzip" "encoding/json" - "io/ioutil" "os" "testing" @@ -25,7 +24,7 @@ func testBuildpackInspector(t *testing.T, context spec.G, it spec.S) { ) it.Before(func() { - file, err := ioutil.TempFile("", "buildpackage") + file, err := os.CreateTemp("", "buildpackage") Expect(err).NotTo(HaveOccurred()) tw := tar.NewWriter(file) diff --git a/cargo/jam/internal/dependency_cacher_test.go b/cargo/jam/internal/dependency_cacher_test.go index a3fd0ec0..173bca27 100644 --- a/cargo/jam/internal/dependency_cacher_test.go +++ b/cargo/jam/internal/dependency_cacher_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -31,20 +30,20 @@ func testDependencyCacher(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tmpDir, err = ioutil.TempDir("", "cacher-test") + tmpDir, err = os.MkdirTemp("", "cacher-test") Expect(err).NotTo(HaveOccurred()) downloader = &fakes.Downloader{} downloader.DropCall.Stub = func(root, uri string) (io.ReadCloser, error) { switch uri { case "http://dep1-uri": - return ioutil.NopCloser(strings.NewReader("dep1-contents")), nil + return io.NopCloser(strings.NewReader("dep1-contents")), nil case "http://dep2-uri": - return ioutil.NopCloser(strings.NewReader("dep2-contents")), nil + return io.NopCloser(strings.NewReader("dep2-contents")), nil case "http://error-dep": - return ioutil.NopCloser(errorReader{}), nil + return io.NopCloser(errorReader{}), nil default: return nil, fmt.Errorf("no such dependency: %s", uri) @@ -93,11 +92,11 @@ func testDependencyCacher(t *testing.T, context spec.G, it spec.S) { Expect(downloader.DropCall.Receives.Root).To(Equal("")) - contents, err := ioutil.ReadFile(filepath.Join(tmpDir, "dependencies", "3c9de6683673f3e8039599d5200d533807c6c35fd9e35d6b6d77009122868f0f")) + contents, err := os.ReadFile(filepath.Join(tmpDir, "dependencies", "3c9de6683673f3e8039599d5200d533807c6c35fd9e35d6b6d77009122868f0f")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal("dep1-contents")) - contents, err = ioutil.ReadFile(filepath.Join(tmpDir, "dependencies", "bfc72d62682f4a2edc3218d70b1f7052e4f336c179a8f19ef12ee721d4ea29b7")) + contents, err = os.ReadFile(filepath.Join(tmpDir, "dependencies", "bfc72d62682f4a2edc3218d70b1f7052e4f336c179a8f19ef12ee721d4ea29b7")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal("dep2-contents")) diff --git a/cargo/jam/internal/file_bundler.go b/cargo/jam/internal/file_bundler.go index 1f311f04..66d4a562 100644 --- a/cargo/jam/internal/file_bundler.go +++ b/cargo/jam/internal/file_bundler.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -81,7 +80,7 @@ func (b FileBundler) Bundle(root string, paths []string, config cargo.Config) ([ return nil, fmt.Errorf("error encoding buildpack.toml: %s", err) } - file.ReadCloser = ioutil.NopCloser(buf) + file.ReadCloser = io.NopCloser(buf) file.Info = NewFileInfo("buildpack.toml", buf.Len(), 0644, time.Now()) default: diff --git a/cargo/jam/internal/file_bundler_test.go b/cargo/jam/internal/file_bundler_test.go index 670878e2..4d9821fe 100644 --- a/cargo/jam/internal/file_bundler_test.go +++ b/cargo/jam/internal/file_bundler_test.go @@ -1,7 +1,7 @@ package internal_test import ( - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -53,7 +53,7 @@ func testFileBundler(t *testing.T, context spec.G, it spec.S) { Expect(files[0].Info.Mode()).To(Equal(os.FileMode(0755))) Expect(files[0].Link).To(Equal("")) - content, err := ioutil.ReadAll(files[0]) + content, err := io.ReadAll(files[0]) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("build-contents")) @@ -62,7 +62,7 @@ func testFileBundler(t *testing.T, context spec.G, it spec.S) { Expect(files[1].Info.Mode()).To(Equal(os.FileMode(0755))) Expect(files[1].Link).To(Equal("")) - content, err = ioutil.ReadAll(files[1]) + content, err = io.ReadAll(files[1]) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("detect-contents")) @@ -77,7 +77,7 @@ func testFileBundler(t *testing.T, context spec.G, it spec.S) { Expect(files[3].Info.Mode()).To(Equal(os.FileMode(0644))) Expect(files[3].Link).To(Equal("")) - content, err = ioutil.ReadAll(files[3]) + content, err = io.ReadAll(files[3]) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(MatchTOML(`api = "0.2" [buildpack] diff --git a/cargo/jam/internal/image_test.go b/cargo/jam/internal/image_test.go index 2d2e67d5..6fc60283 100644 --- a/cargo/jam/internal/image_test.go +++ b/cargo/jam/internal/image_test.go @@ -2,7 +2,6 @@ package internal_test import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -58,7 +57,7 @@ func testImage(t *testing.T, context spec.G, it spec.S) { })) var err error - dockerConfig, err = ioutil.TempDir("", "docker-config") + dockerConfig, err = os.MkdirTemp("", "docker-config") Expect(err).NotTo(HaveOccurred()) contents := fmt.Sprintf(`{ @@ -70,7 +69,7 @@ func testImage(t *testing.T, context spec.G, it spec.S) { } }`, strings.TrimPrefix(server.URL, "http://")) - err = ioutil.WriteFile(filepath.Join(dockerConfig, "config.json"), []byte(contents), 0600) + err = os.WriteFile(filepath.Join(dockerConfig, "config.json"), []byte(contents), 0600) Expect(err).NotTo(HaveOccurred()) Expect(os.Setenv("DOCKER_CONFIG", dockerConfig)).To(Succeed()) @@ -151,7 +150,7 @@ func testImage(t *testing.T, context spec.G, it spec.S) { })) var err error - dockerConfig, err = ioutil.TempDir("", "docker-config") + dockerConfig, err = os.MkdirTemp("", "docker-config") Expect(err).NotTo(HaveOccurred()) contents := fmt.Sprintf(`{ @@ -163,7 +162,7 @@ func testImage(t *testing.T, context spec.G, it spec.S) { } }`, strings.TrimPrefix(server.URL, "http://")) - err = ioutil.WriteFile(filepath.Join(dockerConfig, "config.json"), []byte(contents), 0600) + err = os.WriteFile(filepath.Join(dockerConfig, "config.json"), []byte(contents), 0600) Expect(err).NotTo(HaveOccurred()) Expect(os.Setenv("DOCKER_CONFIG", dockerConfig)).To(Succeed()) diff --git a/cargo/jam/internal/init_test.go b/cargo/jam/internal/init_test.go index 82fbfecb..db1a27e4 100644 --- a/cargo/jam/internal/init_test.go +++ b/cargo/jam/internal/init_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "testing" "time" @@ -59,7 +58,7 @@ func ExtractFile(file *os.File, name string) ([]byte, *tar.Header, error) { } if hdr.Name == name { - contents, err := ioutil.ReadAll(tr) + contents, err := io.ReadAll(tr) if err != nil { return nil, nil, err } diff --git a/cargo/jam/internal/package_config_test.go b/cargo/jam/internal/package_config_test.go index d6a14e97..0b0e967f 100644 --- a/cargo/jam/internal/package_config_test.go +++ b/cargo/jam/internal/package_config_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "testing" @@ -21,7 +20,7 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) { context("ParsePackageConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "package.toml") + file, err := os.CreateTemp("", "package.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -77,7 +76,7 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) { context("when the file contents cannot be parsed", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) + Expect(os.WriteFile(path, []byte("%%%"), 0600)).To(Succeed()) }) it("returns an error", func() { @@ -89,7 +88,7 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) { context("when a dependency uri is not valid", func() { it.Before(func() { - Expect(ioutil.WriteFile(path, []byte(` + Expect(os.WriteFile(path, []byte(` [buildpack] uri = "build/buildpack.tgz" @@ -115,7 +114,7 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) { context("OverwritePackageConfig", func() { it.Before(func() { - file, err := ioutil.TempFile("", "package.toml") + file, err := os.CreateTemp("", "package.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -142,7 +141,7 @@ func testPackageConfig(t *testing.T, context spec.G, it spec.S) { }) Expect(err).NotTo(HaveOccurred()) - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` [buildpack] diff --git a/cargo/jam/internal/tar_builder_test.go b/cargo/jam/internal/tar_builder_test.go index 332daa70..d43f3e3a 100644 --- a/cargo/jam/internal/tar_builder_test.go +++ b/cargo/jam/internal/tar_builder_test.go @@ -4,7 +4,7 @@ import ( "archive/tar" "bytes" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strings" @@ -30,7 +30,7 @@ func testTarBuilder(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "output") + tempDir, err = os.MkdirTemp("", "output") Expect(err).NotTo(HaveOccurred()) tempFile = filepath.Join(tempDir, "buildpack.tgz") @@ -50,17 +50,17 @@ func testTarBuilder(t *testing.T, context spec.G, it spec.S) { { Name: "buildpack.toml", Info: internal.NewFileInfo("buildpack.toml", len("buildpack-toml-contents"), 0644, time.Now()), - ReadCloser: ioutil.NopCloser(strings.NewReader("buildpack-toml-contents")), + ReadCloser: io.NopCloser(strings.NewReader("buildpack-toml-contents")), }, { Name: "bin/build", Info: internal.NewFileInfo("build", len("build-contents"), 0755, time.Now()), - ReadCloser: ioutil.NopCloser(strings.NewReader("build-contents")), + ReadCloser: io.NopCloser(strings.NewReader("build-contents")), }, { Name: "bin/detect", Info: internal.NewFileInfo("detect", len("detect-contents"), 0755, time.Now()), - ReadCloser: ioutil.NopCloser(strings.NewReader("detect-contents")), + ReadCloser: io.NopCloser(strings.NewReader("detect-contents")), }, { Name: "bin/link", @@ -123,7 +123,7 @@ func testTarBuilder(t *testing.T, context spec.G, it spec.S) { { Name: "bin/build", Info: internal.NewFileInfo("build", len("build-contents"), 0755, time.Now()), - ReadCloser: ioutil.NopCloser(strings.NewReader("build-contents")), + ReadCloser: io.NopCloser(strings.NewReader("build-contents")), }, }) Expect(err).To(MatchError(ContainSubstring("failed to create tarball"))) @@ -137,7 +137,7 @@ func testTarBuilder(t *testing.T, context spec.G, it spec.S) { { Name: "bin/build", Info: internal.NewFileInfo("build", 1, 0755, time.Now()), - ReadCloser: ioutil.NopCloser(strings.NewReader("build-contents")), + ReadCloser: io.NopCloser(strings.NewReader("build-contents")), }, }) Expect(err).To(MatchError(ContainSubstring("failed to write file to tarball"))) @@ -150,7 +150,7 @@ func testTarBuilder(t *testing.T, context spec.G, it spec.S) { err := builder.Build(tempFile, []internal.File{ { Name: "bin/build", - ReadCloser: ioutil.NopCloser(strings.NewReader("build-contents")), + ReadCloser: io.NopCloser(strings.NewReader("build-contents")), }, }) Expect(err).To(MatchError(ContainSubstring("failed to create header for file \"bin/build\":"))) diff --git a/cargo/jam/main.go b/cargo/jam/main.go index bb46be08..f7ba59e6 100644 --- a/cargo/jam/main.go +++ b/cargo/jam/main.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/paketo-buildpacks/packit/cargo/jam/commands" "os" + + "github.com/paketo-buildpacks/packit/cargo/jam/commands" ) func main() { diff --git a/cargo/jam/pack_test.go b/cargo/jam/pack_test.go index 9638440b..99ddc3eb 100644 --- a/cargo/jam/pack_test.go +++ b/cargo/jam/pack_test.go @@ -2,7 +2,6 @@ package main_test import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -33,10 +32,10 @@ func testPack(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tmpDir, err = ioutil.TempDir("", "output") + tmpDir, err = os.MkdirTemp("", "output") Expect(err).NotTo(HaveOccurred()) - buildpackDir, err = ioutil.TempDir("", "buildpack") + buildpackDir, err = os.MkdirTemp("", "buildpack") Expect(err).NotTo(HaveOccurred()) buffer = &Buffer{} diff --git a/cargo/jam/summarize_test.go b/cargo/jam/summarize_test.go index 378be436..c0e837c8 100644 --- a/cargo/jam/summarize_test.go +++ b/cargo/jam/summarize_test.go @@ -5,7 +5,6 @@ import ( "bytes" "compress/gzip" "encoding/json" - "io/ioutil" "os" "os/exec" "testing" @@ -27,7 +26,7 @@ func testSummarize(t *testing.T, context spec.G, it spec.S) { ) it.Before(func() { - file, err := ioutil.TempFile("", "buildpackage") + file, err := os.CreateTemp("", "buildpackage") Expect(err).NotTo(HaveOccurred()) tw := tar.NewWriter(file) diff --git a/cargo/jam/update_builder_test.go b/cargo/jam/update_builder_test.go index f60a4498..fa24d7f5 100644 --- a/cargo/jam/update_builder_test.go +++ b/cargo/jam/update_builder_test.go @@ -3,7 +3,6 @@ package main_test import ( "bytes" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -102,10 +101,10 @@ func testUpdateBuilder(t *testing.T, context spec.G, it spec.S) { })) var err error - builderDir, err = ioutil.TempDir("", "") + builderDir, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` + err = os.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` description = "Some description" [[buildpacks]] @@ -158,7 +157,7 @@ description = "Some description" Eventually(session).Should(gexec.Exit(0), func() string { return string(buffer.Contents()) }) - builderContents, err := ioutil.ReadFile(filepath.Join(builderDir, "builder.toml")) + builderContents, err := os.ReadFile(filepath.Join(builderDir, "builder.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(builderContents)).To(MatchTOML(strings.ReplaceAll(` description = "Some description" @@ -232,7 +231,7 @@ description = "Some description" context("when the latest buildpack image cannot be found", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` + err := os.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` [[buildpacks]] uri = "docker://REGISTRY-URI/some-repository/error-buildpack-id:0.0.10" version = "0.0.10" @@ -277,7 +276,7 @@ description = "Some description" context("when the latest build image cannot be found", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` + err := os.WriteFile(filepath.Join(builderDir, "builder.toml"), bytes.ReplaceAll([]byte(` description = "Some description" [[buildpacks]] diff --git a/cargo/jam/update_buildpack_test.go b/cargo/jam/update_buildpack_test.go index f5659cfc..d2e9fe9c 100644 --- a/cargo/jam/update_buildpack_test.go +++ b/cargo/jam/update_buildpack_test.go @@ -3,7 +3,6 @@ package main_test import ( "bytes" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -84,10 +83,10 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { })) var err error - buildpackDir, err = ioutil.TempDir("", "") + buildpackDir, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(buildpackDir, "buildpack.toml"), []byte(` + err = os.WriteFile(filepath.Join(buildpackDir, "buildpack.toml"), []byte(` api = "0.2" [buildpack] @@ -119,7 +118,7 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { `), 0600) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(buildpackDir, "package.toml"), bytes.ReplaceAll([]byte(` + err = os.WriteFile(filepath.Join(buildpackDir, "package.toml"), bytes.ReplaceAll([]byte(` [buildpack] uri = "build/buildpack.tgz" @@ -153,7 +152,7 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { Eventually(session).Should(gexec.Exit(0), func() string { return string(buffer.Contents()) }) - buildpackContents, err := ioutil.ReadFile(filepath.Join(buildpackDir, "buildpack.toml")) + buildpackContents, err := os.ReadFile(filepath.Join(buildpackDir, "buildpack.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(buildpackContents)).To(MatchTOML(` api = "0.2" @@ -186,7 +185,7 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { version = "0.20.12" `)) - packageContents, err := ioutil.ReadFile(filepath.Join(buildpackDir, "package.toml")) + packageContents, err := os.ReadFile(filepath.Join(buildpackDir, "package.toml")) Expect(err).NotTo(HaveOccurred()) Expect(string(packageContents)).To(MatchTOML(strings.ReplaceAll(` [buildpack] @@ -276,7 +275,7 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { context("when the latest image reference cannot be found", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(buildpackDir, "buildpack.toml"), []byte(` + err := os.WriteFile(filepath.Join(buildpackDir, "buildpack.toml"), []byte(` api = "0.2" [buildpack] @@ -294,7 +293,7 @@ func testUpdateBuildpack(t *testing.T, context spec.G, it spec.S) { `), 0600) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(buildpackDir, "package.toml"), bytes.ReplaceAll([]byte(` + err = os.WriteFile(filepath.Join(buildpackDir, "package.toml"), bytes.ReplaceAll([]byte(` [buildpack] uri = "build/buildpack.tgz" diff --git a/cargo/transport_test.go b/cargo/transport_test.go index 9fe63e32..269f419d 100644 --- a/cargo/transport_test.go +++ b/cargo/transport_test.go @@ -2,7 +2,7 @@ package cargo_test import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -47,7 +47,7 @@ func testTransport(t *testing.T, context spec.G, it spec.S) { bundle, err := transport.Drop("", fmt.Sprintf("%s/some-bundle", server.URL)) Expect(err).NotTo(HaveOccurred()) - contents, err := ioutil.ReadAll(bundle) + contents, err := io.ReadAll(bundle) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal("some-bundle-contents")) @@ -85,12 +85,12 @@ func testTransport(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - dir, err = ioutil.TempDir("", "bundle") + dir, err = os.MkdirTemp("", "bundle") Expect(err).NotTo(HaveOccurred()) path = "some-file" - err = ioutil.WriteFile(filepath.Join(dir, path), []byte("some-bundle-contents"), 0644) + err = os.WriteFile(filepath.Join(dir, path), []byte("some-bundle-contents"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -102,7 +102,7 @@ func testTransport(t *testing.T, context spec.G, it spec.S) { bundle, err := transport.Drop(dir, fmt.Sprintf("file://%s", path)) Expect(err).NotTo(HaveOccurred()) - contents, err := ioutil.ReadAll(bundle) + contents, err := io.ReadAll(bundle) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(Equal("some-bundle-contents")) diff --git a/cargo/validated_reader.go b/cargo/validated_reader.go index 19273bc8..3f73b351 100644 --- a/cargo/validated_reader.go +++ b/cargo/validated_reader.go @@ -7,7 +7,6 @@ import ( "errors" "hash" "io" - "io/ioutil" ) var ChecksumValidationError = errors.New("validation error: checksum does not match") @@ -56,7 +55,7 @@ func (vr ValidatedReader) Read(p []byte) (int, error) { } func (vr ValidatedReader) Valid() (bool, error) { - _, err := io.Copy(ioutil.Discard, vr) + _, err := io.Copy(io.Discard, vr) if err != nil { if err == ChecksumValidationError { return false, nil diff --git a/detect_test.go b/detect_test.go index 7fa9e097..d5f59ed6 100644 --- a/detect_test.go +++ b/detect_test.go @@ -3,7 +3,6 @@ package packit_test import ( "bytes" "errors" - "io/ioutil" "os" "path/filepath" "testing" @@ -35,7 +34,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) { workingDir, err = os.Getwd() Expect(err).NotTo(HaveOccurred()) - tmpDir, err = ioutil.TempDir("", "") + tmpDir, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) tmpDir, err = filepath.EvalSymlinks(tmpDir) @@ -43,14 +42,14 @@ func testDetect(t *testing.T, context spec.G, it spec.S) { Expect(os.Chdir(tmpDir)).To(Succeed()) - cnbDir, err = ioutil.TempDir("", "cnb") + cnbDir, err = os.MkdirTemp("", "cnb") Expect(err).NotTo(HaveOccurred()) stackID = "io.packit.test.stack" Expect(os.Setenv("CNB_STACK_ID", stackID)).To(Succeed()) //Separate, but valid CNB dir for testing env parsing - cnbEnvDir, err = ioutil.TempDir("", "cnbEnv") + cnbEnvDir, err = os.MkdirTemp("", "cnbEnv") Expect(err).NotTo(HaveOccurred()) binaryPath = filepath.Join(cnbDir, "bin", "detect") @@ -63,8 +62,8 @@ api = "0.5" version = "some-version" clear-env = false `) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOMLContent, 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(cnbEnvDir, "buildpack.toml"), bpTOMLContent, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOMLContent, 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(cnbEnvDir, "buildpack.toml"), bpTOMLContent, 0600)).To(Succeed()) exitHandler = &fakes.ExitHandler{} }) @@ -127,7 +126,7 @@ api = "0.5" }, nil }, packit.WithArgs([]string{binaryPath, "", path})) - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` @@ -195,7 +194,7 @@ api = "0.5" }, nil }, packit.WithArgs([]string{binaryPath, "", path})) - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(MatchTOML(` diff --git a/environment.go b/environment.go index ad8d53ba..8debeef1 100644 --- a/environment.go +++ b/environment.go @@ -2,7 +2,7 @@ package packit import ( "fmt" - "io/ioutil" + "os" "path/filepath" ) @@ -57,7 +57,7 @@ func newEnvironmentFromPath(path string) (Environment, error) { for _, file := range envFiles { switch filepath.Ext(file) { case ".delim", ".prepend", ".append", ".default", ".override": - contents, err := ioutil.ReadFile(file) + contents, err := os.ReadFile(file) if err != nil { return Environment{}, fmt.Errorf("failed to load environment variable: %s", err) } diff --git a/fs/checksum_calculator_test.go b/fs/checksum_calculator_test.go index bf3720df..2240cc22 100644 --- a/fs/checksum_calculator_test.go +++ b/fs/checksum_calculator_test.go @@ -2,7 +2,6 @@ package fs_test import ( "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -25,7 +24,7 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { context("Sum", func() { it.Before(func() { var err error - workingDir, err = ioutil.TempDir("", "working-dir") + workingDir, err = os.MkdirTemp("", "working-dir") Expect(err).NotTo(HaveOccurred()) calculator = fs.NewChecksumCalculator() @@ -40,7 +39,7 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { it.Before(func() { path = filepath.Join(workingDir, "some-file") - Expect(ioutil.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) }) it("generates the SHA256 checksum for that file", func() { @@ -72,9 +71,9 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { it.Before(func() { path1 = filepath.Join(workingDir, "some-file1") - Expect(ioutil.WriteFile(path1, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path1, []byte{}, os.ModePerm)).To(Succeed()) path2 = filepath.Join(workingDir, "some-file2") - Expect(ioutil.WriteFile(path2, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path2, []byte{}, os.ModePerm)).To(Succeed()) }) it("generates the SHA256 checksum for multiple files", func() { @@ -88,7 +87,7 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { // Generate a bunch of files and shuffle input order to ensure test fails consistently without sorting implemented for i := 0; i < 10; i++ { path := filepath.Join(workingDir, fmt.Sprintf("some-file-%d", i)) - Expect(ioutil.WriteFile(path, []byte(fmt.Sprintf("some-file-contents-%d", i)), os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path, []byte(fmt.Sprintf("some-file-contents-%d", i)), os.ModePerm)).To(Succeed()) paths = append(paths, path) } }) @@ -134,11 +133,11 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { dir2 = filepath.Join(workingDir, "some-other-dir") Expect(os.MkdirAll(dir2, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir1, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir1, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir1, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir1, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir2, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir2, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir2, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir2, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) }) it("returns the 256 sha sum of a directory containing the directories", func() { @@ -187,9 +186,9 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { path = filepath.Join(workingDir, "some-filepath") Expect(os.MkdirAll(dir, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) }) it("returns the 256 sha sum of a directory containing the file and directory", func() { @@ -208,9 +207,9 @@ func testChecksumCalculator(t *testing.T, context spec.G, it spec.S) { path = filepath.Join(workingDir, "the-item") Expect(os.MkdirAll(dir, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(dir, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir, "some-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir, "some-other-file"), []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(path, []byte{}, os.ModePerm)).To(Succeed()) }) diff --git a/fs/copy_test.go b/fs/copy_test.go index 0b47e817..669ac955 100644 --- a/fs/copy_test.go +++ b/fs/copy_test.go @@ -1,7 +1,6 @@ package fs_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -23,10 +22,10 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - sourceDir, err = ioutil.TempDir("", "source") + sourceDir, err = os.MkdirTemp("", "source") Expect(err).NotTo(HaveOccurred()) - destinationDir, err = ioutil.TempDir("", "destination") + destinationDir, err = os.MkdirTemp("", "destination") Expect(err).NotTo(HaveOccurred()) }) @@ -42,7 +41,7 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { source = filepath.Join(sourceDir, "source") destination = filepath.Join(destinationDir, "destination") - err := ioutil.WriteFile(source, []byte("some-content"), 0644) + err := os.WriteFile(source, []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -50,7 +49,7 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { err := fs.Copy(source, destination) Expect(err).NotTo(HaveOccurred()) - content, err := ioutil.ReadFile(destination) + content, err := os.ReadFile(destination) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) @@ -92,10 +91,10 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - external, err = ioutil.TempDir("", "external") + external, err = os.MkdirTemp("", "external") Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(external, "some-file"), []byte("some-content"), 0644) + err = os.WriteFile(filepath.Join(external, "some-file"), []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) source = filepath.Join(sourceDir, "source") @@ -103,10 +102,10 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { Expect(os.MkdirAll(filepath.Join(source, "some-dir"), os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(source, "some-dir", "some-file"), []byte("some-content"), 0644) + err = os.WriteFile(filepath.Join(source, "some-dir", "some-file"), []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(source, "some-dir", "readonly-file"), []byte("some-content"), 0444) + err = os.WriteFile(filepath.Join(source, "some-dir", "readonly-file"), []byte("some-content"), 0444) Expect(err).NotTo(HaveOccurred()) err = os.Symlink("some-file", filepath.Join(source, "some-dir", "some-symlink")) @@ -123,7 +122,7 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { Expect(destination).To(BeADirectory()) - content, err := ioutil.ReadFile(filepath.Join(destination, "some-dir", "some-file")) + content, err := os.ReadFile(filepath.Join(destination, "some-dir", "some-file")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) @@ -150,7 +149,7 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { context("when the destination is a file", func() { it.Before(func() { Expect(os.RemoveAll(destination)) - Expect(ioutil.WriteFile(destination, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(destination, []byte{}, os.ModePerm)).To(Succeed()) }) it("copies the source directory to the destination", func() { @@ -159,7 +158,7 @@ func testCopy(t *testing.T, context spec.G, it spec.S) { Expect(destination).To(BeADirectory()) - content, err := ioutil.ReadFile(filepath.Join(destination, "some-dir", "some-file")) + content, err := os.ReadFile(filepath.Join(destination, "some-dir", "some-file")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) diff --git a/fs/is_empty_dir.go b/fs/is_empty_dir.go index 0916cbc4..5ce41029 100644 --- a/fs/is_empty_dir.go +++ b/fs/is_empty_dir.go @@ -1,12 +1,10 @@ package fs -import ( - "io/ioutil" -) +import "os" // IsEmptyDir checks to see if a directory exists and is empty. func IsEmptyDir(path string) bool { - contents, err := ioutil.ReadDir(path) + contents, err := os.ReadDir(path) if err != nil { return false } diff --git a/fs/is_empty_dir_test.go b/fs/is_empty_dir_test.go index c23200c6..7f278c75 100644 --- a/fs/is_empty_dir_test.go +++ b/fs/is_empty_dir_test.go @@ -1,7 +1,6 @@ package fs_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -21,7 +20,7 @@ func testIsEmptyDir(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - path, err = ioutil.TempDir("", "dir") + path, err = os.MkdirTemp("", "dir") Expect(err).NotTo(HaveOccurred()) }) @@ -37,7 +36,7 @@ func testIsEmptyDir(t *testing.T, context spec.G, it spec.S) { context("when the directory is not empty", func() { it.Before(func() { - Expect(ioutil.WriteFile(filepath.Join(path, "some-file"), []byte{}, 0644)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(path, "some-file"), []byte{}, 0644)).To(Succeed()) }) it("returns false", func() { diff --git a/fs/move_test.go b/fs/move_test.go index c2077903..fa317186 100644 --- a/fs/move_test.go +++ b/fs/move_test.go @@ -1,7 +1,6 @@ package fs_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -23,10 +22,10 @@ func testMove(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - sourceDir, err = ioutil.TempDir("", "source") + sourceDir, err = os.MkdirTemp("", "source") Expect(err).NotTo(HaveOccurred()) - destinationDir, err = ioutil.TempDir("", "destination") + destinationDir, err = os.MkdirTemp("", "destination") Expect(err).NotTo(HaveOccurred()) }) @@ -42,7 +41,7 @@ func testMove(t *testing.T, context spec.G, it spec.S) { source = filepath.Join(sourceDir, "source") destination = filepath.Join(destinationDir, "destination") - err := ioutil.WriteFile(source, []byte("some-content"), 0644) + err := os.WriteFile(source, []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -50,7 +49,7 @@ func testMove(t *testing.T, context spec.G, it spec.S) { err := fs.Move(source, destination) Expect(err).NotTo(HaveOccurred()) - content, err := ioutil.ReadFile(destination) + content, err := os.ReadFile(destination) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) @@ -92,10 +91,10 @@ func testMove(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - external, err = ioutil.TempDir("", "external") + external, err = os.MkdirTemp("", "external") Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(external, "some-file"), []byte("some-content"), 0644) + err = os.WriteFile(filepath.Join(external, "some-file"), []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) source = filepath.Join(sourceDir, "source") @@ -103,10 +102,10 @@ func testMove(t *testing.T, context spec.G, it spec.S) { Expect(os.MkdirAll(filepath.Join(source, "some-dir"), os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(source, "some-dir", "some-file"), []byte("some-content"), 0644) + err = os.WriteFile(filepath.Join(source, "some-dir", "some-file"), []byte("some-content"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(source, "some-dir", "readonly-file"), []byte("some-content"), 0444) + err = os.WriteFile(filepath.Join(source, "some-dir", "readonly-file"), []byte("some-content"), 0444) Expect(err).NotTo(HaveOccurred()) err = os.Symlink("some-file", filepath.Join(source, "some-dir", "some-symlink")) @@ -123,7 +122,7 @@ func testMove(t *testing.T, context spec.G, it spec.S) { Expect(destination).To(BeADirectory()) - content, err := ioutil.ReadFile(filepath.Join(destination, "some-dir", "some-file")) + content, err := os.ReadFile(filepath.Join(destination, "some-dir", "some-file")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) @@ -150,7 +149,7 @@ func testMove(t *testing.T, context spec.G, it spec.S) { context("when the destination is a file", func() { it.Before(func() { Expect(os.RemoveAll(destination)) - Expect(ioutil.WriteFile(destination, []byte{}, os.ModePerm)).To(Succeed()) + Expect(os.WriteFile(destination, []byte{}, os.ModePerm)).To(Succeed()) }) it("moves the source directory to the destination", func() { @@ -159,7 +158,7 @@ func testMove(t *testing.T, context spec.G, it spec.S) { Expect(destination).To(BeADirectory()) - content, err := ioutil.ReadFile(filepath.Join(destination, "some-dir", "some-file")) + content, err := os.ReadFile(filepath.Join(destination, "some-dir", "some-file")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) diff --git a/go.sum b/go.sum index 245300e9..014b5900 100644 --- a/go.sum +++ b/go.sum @@ -313,7 +313,6 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= @@ -596,7 +595,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/environment_writer.go b/internal/environment_writer.go index 717fb529..4ef659c8 100644 --- a/internal/environment_writer.go +++ b/internal/environment_writer.go @@ -1,7 +1,6 @@ package internal import ( - "io/ioutil" "os" "path/filepath" ) @@ -23,7 +22,7 @@ func (w EnvironmentWriter) Write(dir string, env map[string]string) error { } for key, value := range env { - err := ioutil.WriteFile(filepath.Join(dir, key), []byte(value), 0644) + err := os.WriteFile(filepath.Join(dir, key), []byte(value), 0644) if err != nil { return err } diff --git a/internal/environment_writer_test.go b/internal/environment_writer_test.go index 28018446..82b38024 100644 --- a/internal/environment_writer_test.go +++ b/internal/environment_writer_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -22,7 +21,7 @@ func testEnvironmentWriter(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tmpDir, err = ioutil.TempDir("", "env-vars") + tmpDir, err = os.MkdirTemp("", "env-vars") Expect(err).NotTo(HaveOccurred()) Expect(os.RemoveAll(tmpDir)).To(Succeed()) @@ -41,11 +40,11 @@ func testEnvironmentWriter(t *testing.T, context spec.G, it spec.S) { }) Expect(err).NotTo(HaveOccurred()) - content, err := ioutil.ReadFile(filepath.Join(tmpDir, "some-name")) + content, err := os.ReadFile(filepath.Join(tmpDir, "some-name")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("some-content")) - content, err = ioutil.ReadFile(filepath.Join(tmpDir, "other-name")) + content, err = os.ReadFile(filepath.Join(tmpDir, "other-name")) Expect(err).NotTo(HaveOccurred()) Expect(string(content)).To(Equal("other-content")) }) diff --git a/internal/toml_writer_test.go b/internal/toml_writer_test.go index 8753585c..9a5f1e23 100644 --- a/internal/toml_writer_test.go +++ b/internal/toml_writer_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -23,7 +22,7 @@ func testTOMLWriter(t *testing.T, context spec.G, it spec.S) { ) it.Before(func() { var err error - tmpDir, err = ioutil.TempDir("", "tomlWriter") + tmpDir, err = os.MkdirTemp("", "tomlWriter") Expect(err).NotTo(HaveOccurred()) path = filepath.Join(tmpDir, "writer.toml") @@ -36,7 +35,7 @@ func testTOMLWriter(t *testing.T, context spec.G, it spec.S) { }) Expect(err).NotTo(HaveOccurred()) - tomlFileContents, err := ioutil.ReadFile(path) + tomlFileContents, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) Expect(string(tomlFileContents)).To(MatchTOML(` some-field = "some-value" diff --git a/layer_test.go b/layer_test.go index 44fc008e..ee06efde 100644 --- a/layer_test.go +++ b/layer_test.go @@ -1,7 +1,6 @@ package packit_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -21,7 +20,7 @@ func testLayer(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - layersDir, err = ioutil.TempDir("", "layers") + layersDir, err = os.MkdirTemp("", "layers") Expect(err).NotTo(HaveOccurred()) }) @@ -69,25 +68,25 @@ func testLayer(t *testing.T, context spec.G, it spec.S) { sharedEnvDir := filepath.Join(layersDir, "some-layer", "env") Expect(os.MkdirAll(sharedEnvDir, os.ModePerm)).To(Succeed()) - err := ioutil.WriteFile(filepath.Join(sharedEnvDir, "OVERRIDE_VAR.override"), []byte("override-value"), 0600) + err := os.WriteFile(filepath.Join(sharedEnvDir, "OVERRIDE_VAR.override"), []byte("override-value"), 0600) Expect(err).NotTo(HaveOccurred()) buildEnvDir := filepath.Join(layersDir, "some-layer", "env.build") Expect(os.MkdirAll(buildEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0600) + err = os.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0600) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(buildEnvDir, "INVALID_VAR.invalid"), []byte("invalid-value"), 0600) + err = os.WriteFile(filepath.Join(buildEnvDir, "INVALID_VAR.invalid"), []byte("invalid-value"), 0600) Expect(err).NotTo(HaveOccurred()) launchEnvDir := filepath.Join(layersDir, "some-layer", "env.launch") Expect(os.MkdirAll(launchEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0600) + err = os.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0600) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0600) + err = os.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0600) Expect(err).NotTo(HaveOccurred()) layer = packit.Layer{ diff --git a/layers.go b/layers.go index ef4dd27b..4f98ecca 100644 --- a/layers.go +++ b/layers.go @@ -2,7 +2,6 @@ package packit import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -52,7 +51,7 @@ func (l Layers) Get(name string) (Layer, error) { } if _, err := os.Stat(filepath.Join(l.Path, name, "env.launch")); !os.IsNotExist(err) { - paths, err := ioutil.ReadDir(filepath.Join(l.Path, name, "env.launch")) + paths, err := os.ReadDir(filepath.Join(l.Path, name, "env.launch")) if err != nil { return Layer{}, err } diff --git a/layers_test.go b/layers_test.go index d4739ec2..40458ed3 100644 --- a/layers_test.go +++ b/layers_test.go @@ -1,7 +1,6 @@ package packit_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -22,7 +21,7 @@ func testLayers(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - layersDir, err = ioutil.TempDir("", "layers") + layersDir, err = os.MkdirTemp("", "layers") Expect(err).NotTo(HaveOccurred()) layers = packit.Layers{ @@ -50,7 +49,7 @@ func testLayers(t *testing.T, context spec.G, it spec.S) { context("when the layer already exists on disk", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(layersDir, "some-layer.toml"), []byte(` + err := os.WriteFile(filepath.Join(layersDir, "some-layer.toml"), []byte(` build = true launch = true cache = true @@ -84,60 +83,60 @@ some-key = "some-value"`), 0644) sharedEnvDir := filepath.Join(layersDir, "some-layer", "env") Expect(os.MkdirAll(sharedEnvDir, os.ModePerm)).To(Succeed()) - err := ioutil.WriteFile(filepath.Join(sharedEnvDir, "OVERRIDE_VAR.override"), []byte("override-value"), 0644) + err := os.WriteFile(filepath.Join(sharedEnvDir, "OVERRIDE_VAR.override"), []byte("override-value"), 0644) Expect(err).NotTo(HaveOccurred()) buildEnvDir := filepath.Join(layersDir, "some-layer", "env.build") Expect(os.MkdirAll(buildEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0644) + err = os.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(buildEnvDir, "INVALID_VAR.invalid"), []byte("invalid-value"), 0644) + err = os.WriteFile(filepath.Join(buildEnvDir, "INVALID_VAR.invalid"), []byte("invalid-value"), 0644) Expect(err).NotTo(HaveOccurred()) launchEnvDir := filepath.Join(layersDir, "some-layer", "env.launch") Expect(os.MkdirAll(launchEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) + err = os.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) + err = os.WriteFile(filepath.Join(launchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) + err = os.WriteFile(filepath.Join(launchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(launchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) + err = os.WriteFile(filepath.Join(launchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) Expect(err).NotTo(HaveOccurred()) processLaunchEnvDir := filepath.Join(layersDir, "some-layer", "env.launch", "process") Expect(os.MkdirAll(processLaunchEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(processLaunchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) + err = os.WriteFile(filepath.Join(processLaunchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(processLaunchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) + err = os.WriteFile(filepath.Join(processLaunchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(processLaunchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) + err = os.WriteFile(filepath.Join(processLaunchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(processLaunchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) + err = os.WriteFile(filepath.Join(processLaunchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) Expect(err).NotTo(HaveOccurred()) anotherProcessLaunchEnvDir := filepath.Join(layersDir, "some-layer", "env.launch", "another-process") Expect(os.MkdirAll(anotherProcessLaunchEnvDir, os.ModePerm)).To(Succeed()) - err = ioutil.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) + err = os.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "APPEND_VAR.append"), []byte("append-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) + err = os.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "APPEND_VAR.delim"), []byte("!"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) + err = os.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "PREPEND_VAR.prepend"), []byte("prepend-value"), 0644) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) + err = os.WriteFile(filepath.Join(anotherProcessLaunchEnvDir, "PREPEND_VAR.delim"), []byte("#"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -187,7 +186,7 @@ some-key = "some-value"`), 0644) context("failure cases", func() { context("when the layers directory contains a malformed layer toml", func() { it.Before(func() { - err := ioutil.WriteFile(filepath.Join(layersDir, "some-layer.toml"), []byte("%%%"), 0644) + err := os.WriteFile(filepath.Join(layersDir, "some-layer.toml"), []byte("%%%"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -202,7 +201,7 @@ some-key = "some-value"`), 0644) it.Before(func() { sharedEnvDir := filepath.Join(layersDir, "some-layer", "env") Expect(os.MkdirAll(sharedEnvDir, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(sharedEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(sharedEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) }) it("returns a layer with the existing metadata", func() { @@ -215,7 +214,7 @@ some-key = "some-value"`), 0644) it.Before(func() { buildEnvDir := filepath.Join(layersDir, "some-layer", "env.build") Expect(os.MkdirAll(buildEnvDir, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(buildEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) }) it("returns a layer with the existing metadata", func() { @@ -228,7 +227,7 @@ some-key = "some-value"`), 0644) it.Before(func() { launchEnvDir := filepath.Join(layersDir, "some-layer", "env.launch") Expect(os.MkdirAll(launchEnvDir, os.ModePerm)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(launchEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(launchEnvDir, "DEFAULT_VAR.default"), []byte("default-value"), 0000)).To(Succeed()) }) it("returns a layer with the existing metadata", func() { diff --git a/pexec/executable_test.go b/pexec/executable_test.go index 20359d3f..1fec2ace 100644 --- a/pexec/executable_test.go +++ b/pexec/executable_test.go @@ -3,7 +3,6 @@ package pexec_test import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -28,7 +27,7 @@ func testPexec(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tmpDir, err = ioutil.TempDir("", "executable") + tmpDir, err = os.MkdirTemp("", "executable") Expect(err).NotTo(HaveOccurred()) tmpDir, err = filepath.EvalSymlinks(tmpDir) diff --git a/postal/internal/dependency_mappings.go b/postal/internal/dependency_mappings.go index b0639dfc..6a09c825 100644 --- a/postal/internal/dependency_mappings.go +++ b/postal/internal/dependency_mappings.go @@ -2,7 +2,6 @@ package internal import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -29,7 +28,7 @@ func (d DependencyMappingResolver) FindDependencyMapping(sha256, bindingPath str } for _, binding := range allBindings { - bindType, err := ioutil.ReadFile(filepath.Join(binding, "type")) + bindType, err := os.ReadFile(filepath.Join(binding, "type")) if err != nil { return "", fmt.Errorf("couldn't read binding type: %w", err) } @@ -42,7 +41,7 @@ func (d DependencyMappingResolver) FindDependencyMapping(sha256, bindingPath str continue } - uri, err := ioutil.ReadFile(filepath.Join(binding, sha256)) + uri, err := os.ReadFile(filepath.Join(binding, sha256)) if err != nil { return "", err } diff --git a/postal/internal/dependency_mappings_test.go b/postal/internal/dependency_mappings_test.go index 4d718be3..ed0cea6e 100644 --- a/postal/internal/dependency_mappings_test.go +++ b/postal/internal/dependency_mappings_test.go @@ -1,7 +1,6 @@ package internal_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -23,7 +22,7 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) { it.Before(func() { resolver = internal.NewDependencyMappingResolver() - bindingPath, err = ioutil.TempDir("", "bindings") + bindingPath, err = os.MkdirTemp("", "bindings") Expect(err).NotTo(HaveOccurred()) }) @@ -34,16 +33,16 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) { context("FindDependencyMapping", func() { it.Before(func() { Expect(os.MkdirAll(filepath.Join(bindingPath, "some-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) Expect(os.MkdirAll(filepath.Join(bindingPath, "other-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "other-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "other-binding", "other-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "other-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "other-binding", "other-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) Expect(os.MkdirAll(filepath.Join(bindingPath, "another-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "another-binding", "type"), []byte("another type"), 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "another-binding", "some-sha"), []byte("entry.tgz"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "another-binding", "type"), []byte("another type"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "another-binding", "some-sha"), []byte("entry.tgz"), 0600)).To(Succeed()) }) context("given a set of bindings and a dependency", func() { @@ -74,8 +73,8 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) { context("when type file cannot be opened", func() { it.Before(func() { Expect(os.MkdirAll(filepath.Join(bindingPath, "some-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0000)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0000)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0600)).To(Succeed()) }) it("errors", func() { _, err := resolver.FindDependencyMapping("some-sha", bindingPath) @@ -87,8 +86,8 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) { context("when SHA256 file cannot be stat", func() { it.Before(func() { Expect(os.MkdirAll(filepath.Join(bindingPath, "new-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "new-binding", "type"), []byte("dependency-mapping"), 0644)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "new-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0644)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "new-binding", "type"), []byte("dependency-mapping"), 0644)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "new-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0644)).To(Succeed()) Expect(os.Chmod(filepath.Join(bindingPath, "new-binding", "some-sha"), 0000)).To(Succeed()) }) it("errors", func() { @@ -100,8 +99,8 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) { context("when SHA256 contents cannot be opened", func() { it.Before(func() { Expect(os.MkdirAll(filepath.Join(bindingPath, "some-binding"), 0700)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) - Expect(ioutil.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0000)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "type"), []byte("dependency-mapping"), 0600)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(bindingPath, "some-binding", "some-sha"), []byte("dependency-mapping-entry.tgz"), 0000)).To(Succeed()) }) it("errors", func() { _, err := resolver.FindDependencyMapping("some-sha", bindingPath) diff --git a/postal/service_test.go b/postal/service_test.go index fccdfb9e..1460937b 100644 --- a/postal/service_test.go +++ b/postal/service_test.go @@ -8,7 +8,7 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -34,7 +34,7 @@ func testService(t *testing.T, context spec.G, it spec.S) { ) it.Before(func() { - file, err := ioutil.TempFile("", "buildpack.toml") + file, err := os.CreateTemp("", "buildpack.toml") Expect(err).NotTo(HaveOccurred()) path = file.Name() @@ -199,7 +199,7 @@ version = "4.5.6" context("when there is a default version", func() { it.Before(func() { - err := ioutil.WriteFile(path, []byte(` + err := os.WriteFile(path, []byte(` [metadata] [metadata.default-versions] some-entry = "1.2.x" @@ -267,7 +267,7 @@ version = "4.5.6" context("failure cases", func() { context("when the buildpack.toml is malformed", func() { it.Before(func() { - err := ioutil.WriteFile(path, []byte("this is not toml"), 0644) + err := os.WriteFile(path, []byte("this is not toml"), 0644) Expect(err).NotTo(HaveOccurred()) }) @@ -286,7 +286,7 @@ version = "4.5.6" context("when the dependency version is not valid", func() { it.Before(func() { - err := ioutil.WriteFile(path, []byte(` + err := os.WriteFile(path, []byte(` [[metadata.dependencies]] id = "some-entry" sha256 = "some-sha" @@ -321,7 +321,7 @@ version = "this is super not semver" it.Before(func() { var err error - layerPath, err = ioutil.TempDir("", "path") + layerPath, err = os.MkdirTemp("", "path") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -357,7 +357,7 @@ version = "this is super not semver" sum := sha256.Sum256(buffer.Bytes()) dependencySHA = hex.EncodeToString(sum[:]) - transport.DropCall.Returns.ReadCloser = ioutil.NopCloser(buffer) + transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) install = func() error { return service.Install(postal.Dependency{ @@ -447,7 +447,7 @@ version = "this is super not semver" context("when the file contents are empty", func() { it.Before(func() { buffer := bytes.NewBuffer(nil) - transport.DropCall.Returns.ReadCloser = ioutil.NopCloser(buffer) + transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) sum := sha256.Sum256(buffer.Bytes()) dependencySHA = hex.EncodeToString(sum[:]) @@ -470,7 +470,7 @@ version = "this is super not semver" Expect(gzipWriter.Close()).To(Succeed()) - transport.DropCall.Returns.ReadCloser = ioutil.NopCloser(buffer) + transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) sum := sha256.Sum256(buffer.Bytes()) dependencySHA = hex.EncodeToString(sum[:]) @@ -553,7 +553,7 @@ version = "this is super not semver" sum := sha256.Sum256(buffer.Bytes()) dependencySHA = hex.EncodeToString(sum[:]) - transport.DropCall.Returns.ReadCloser = ioutil.NopCloser(buffer) + transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) }) it("fails to extract the symlink", func() { diff --git a/run_test.go b/run_test.go index 621bd072..9efe0767 100644 --- a/run_test.go +++ b/run_test.go @@ -1,7 +1,6 @@ package packit_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -28,7 +27,7 @@ func testRun(t *testing.T, context spec.G, it spec.S) { workingDir, err = os.Getwd() Expect(err).NotTo(HaveOccurred()) - tmpDir, err = ioutil.TempDir("", "") + tmpDir, err = os.MkdirTemp("", "") Expect(err).NotTo(HaveOccurred()) tmpDir, err = filepath.EvalSymlinks(tmpDir) @@ -36,10 +35,10 @@ func testRun(t *testing.T, context spec.G, it spec.S) { Expect(os.Chdir(tmpDir)).To(Succeed()) - cnbDir, err = ioutil.TempDir("", "cnb") + cnbDir, err = os.MkdirTemp("", "cnb") Expect(err).NotTo(HaveOccurred()) - Expect(ioutil.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), []byte(` + Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), []byte(` api = "0.5" [buildpack] id = "some-id" @@ -96,7 +95,7 @@ clear-env = false ) it.Before(func() { - file, err := ioutil.TempFile("", "plan.toml") + file, err := os.CreateTemp("", "plan.toml") Expect(err).NotTo(HaveOccurred()) defer file.Close() @@ -112,7 +111,7 @@ some-key = "some-value" planPath = file.Name() - layersDir, err = ioutil.TempDir("", "layers") + layersDir, err = os.MkdirTemp("", "layers") Expect(err).NotTo(HaveOccurred()) args = []string{filepath.Join(cnbDir, "bin", "build"), layersDir, "", planPath} diff --git a/vacation/example_test.go b/vacation/example_test.go index 583960e5..a233f8be 100644 --- a/vacation/example_test.go +++ b/vacation/example_test.go @@ -6,7 +6,6 @@ import ( "bytes" "compress/gzip" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -69,7 +68,7 @@ func ExampleArchive() { zw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -157,7 +156,7 @@ func ExampleArchive_StripComponents() { zw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -222,7 +221,7 @@ func ExampleTarArchive() { tw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -283,7 +282,7 @@ func ExampleTarArchive_StripComponents() { tw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -343,7 +342,7 @@ func ExampleTarGzipArchive() { tw.Close() gw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -406,7 +405,7 @@ func ExampleTarGzipArchive_StripComponents() { tw.Close() gw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -470,7 +469,7 @@ func ExampleTarXZArchive() { tw.Close() xw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -537,7 +536,7 @@ func ExampleTarXZArchive_StripComponents() { tw.Close() xw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } @@ -597,7 +596,7 @@ func ExampleZipArchive() { zw.Close() - destination, err := ioutil.TempDir("", "destination") + destination, err := os.MkdirTemp("", "destination") if err != nil { log.Fatal(err) } diff --git a/vacation/vacation.go b/vacation/vacation.go index 3404e932..484170d0 100644 --- a/vacation/vacation.go +++ b/vacation/vacation.go @@ -12,7 +12,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -278,7 +277,7 @@ func (z ZipArchive) Decompress(destination string) error { return err } - content, err := ioutil.ReadAll(fd) + content, err := io.ReadAll(fd) if err != nil { return err } diff --git a/vacation/vacation_archive_test.go b/vacation/vacation_archive_test.go index 106d2848..33ad9985 100644 --- a/vacation/vacation_archive_test.go +++ b/vacation/vacation_archive_test.go @@ -5,7 +5,6 @@ import ( "archive/zip" "bytes" "compress/gzip" - "io/ioutil" "os" "path/filepath" "testing" @@ -31,7 +30,7 @@ func testVacationArchive(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -91,7 +90,7 @@ func testVacationArchive(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -153,7 +152,7 @@ func testVacationArchive(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -217,7 +216,7 @@ func testVacationArchive(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -262,7 +261,7 @@ func testVacationArchive(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer([]byte(`some contents`)) diff --git a/vacation/vacation_tar_gzip_test.go b/vacation/vacation_tar_gzip_test.go index 310189ba..63d2e135 100644 --- a/vacation/vacation_tar_gzip_test.go +++ b/vacation/vacation_tar_gzip_test.go @@ -5,7 +5,6 @@ import ( "bytes" "compress/gzip" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -29,7 +28,7 @@ func testVacationTarGzip(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -92,7 +91,7 @@ func testVacationTarGzip(t *testing.T, context spec.G, it spec.S) { Expect(filepath.Join(tempDir, "some-dir", "some-other-dir")).To(BeADirectory()) Expect(filepath.Join(tempDir, "some-dir", "some-other-dir", "some-file")).To(BeARegularFile()) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "symlink")) + data, err := os.ReadFile(filepath.Join(tempDir, "symlink")) Expect(err).NotTo(HaveOccurred()) Expect(data).To(Equal([]byte(`first`))) }) diff --git a/vacation/vacation_tar_test.go b/vacation/vacation_tar_test.go index bc4549e2..3dcf35c6 100644 --- a/vacation/vacation_tar_test.go +++ b/vacation/vacation_tar_test.go @@ -4,7 +4,6 @@ import ( "archive/tar" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -28,7 +27,7 @@ func testVacationTar(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -88,7 +87,7 @@ func testVacationTar(t *testing.T, context spec.G, it spec.S) { Expect(filepath.Join(tempDir, "some-dir", "some-other-dir")).To(BeADirectory()) Expect(filepath.Join(tempDir, "some-dir", "some-other-dir", "some-file")).To(BeARegularFile()) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "symlink")) + data, err := os.ReadFile(filepath.Join(tempDir, "symlink")) Expect(err).NotTo(HaveOccurred()) Expect(data).To(Equal([]byte(`first`))) }) @@ -137,7 +136,7 @@ func testVacationTar(t *testing.T, context spec.G, it spec.S) { Expect(filepath.Join(tempDir, "some-dir", "some-other-dir")).To(BeADirectory()) Expect(filepath.Join(tempDir, "some-dir", "some-other-dir", "some-file")).To(BeARegularFile()) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "sym-dir", "symlink")) + data, err := os.ReadFile(filepath.Join(tempDir, "sym-dir", "symlink")) Expect(err).NotTo(HaveOccurred()) Expect(data).To(Equal([]byte(filepath.Join("some-dir", "some-other-dir", "some-file")))) }) diff --git a/vacation/vacation_tar_xz_test.go b/vacation/vacation_tar_xz_test.go index c98c1f88..1d4e3b7a 100644 --- a/vacation/vacation_tar_xz_test.go +++ b/vacation/vacation_tar_xz_test.go @@ -4,7 +4,6 @@ import ( "archive/tar" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -29,7 +28,7 @@ func testVacationTarXZ(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -94,7 +93,7 @@ func testVacationTarXZ(t *testing.T, context spec.G, it spec.S) { Expect(filepath.Join(tempDir, "some-dir", "some-other-dir")).To(BeADirectory()) Expect(filepath.Join(tempDir, "some-dir", "some-other-dir", "some-file")).To(BeARegularFile()) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "symlink")) + data, err := os.ReadFile(filepath.Join(tempDir, "symlink")) Expect(err).NotTo(HaveOccurred()) Expect(data).To(Equal([]byte(`first`))) }) diff --git a/vacation/vacation_zip_test.go b/vacation/vacation_zip_test.go index f0f77ce8..fc6fa1ab 100644 --- a/vacation/vacation_zip_test.go +++ b/vacation/vacation_zip_test.go @@ -4,7 +4,6 @@ import ( "archive/zip" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -28,7 +27,7 @@ func testVacationZip(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - tempDir, err = ioutil.TempDir("", "vacation") + tempDir, err = os.MkdirTemp("", "vacation") Expect(err).NotTo(HaveOccurred()) buffer := bytes.NewBuffer(nil) @@ -104,7 +103,7 @@ func testVacationZip(t *testing.T, context spec.G, it spec.S) { Expect(err).NotTo(HaveOccurred()) Expect(link).To(Equal("some-dir/some-other-dir/some-file")) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "symlink")) + data, err := os.ReadFile(filepath.Join(tempDir, "symlink")) Expect(err).NotTo(HaveOccurred()) Expect(data).To(Equal([]byte("nested file"))) })