Drop deprecated `io/ioutil`

The package has been deprecated since Go 1.16, see:
https://golang.org/doc/go1.16#ioutil

Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
Hidde Beydals 2021-07-29 09:58:00 +02:00
parent be5d10eaac
commit c4d7e46b90
19 changed files with 68 additions and 84 deletions

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"crypto/sha1" "crypto/sha1"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -184,7 +183,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
} }
// create tmp dir // create tmp dir
tempDir, err := ioutil.TempDir("", bucket.Name) tempDir, err := os.MkdirTemp("", bucket.Name)
if err != nil { if err != nil {
err = fmt.Errorf("tmp dir error: %w", err) err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.BucketNotReady(bucket, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.BucketNotReady(bucket, sourcev1.StorageOperationFailedReason, err.Error()), err
@ -368,7 +367,7 @@ func (r *BucketReconciler) checksum(root string) (string, error) {
if !info.Mode().IsRegular() { if !info.Mode().IsRegular() {
return nil return nil
} }
data, err := ioutil.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,6 @@ limitations under the License.
package controllers package controllers
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -51,7 +50,7 @@ func TestBucketReconciler_checksum(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
root, err := ioutil.TempDir("", "bucket-checksum-") root, err := os.MkdirTemp("", "bucket-checksum-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -76,7 +75,7 @@ func mockFile(root, path, content string) error {
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil { if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
panic(err) panic(err)
} }
if err := ioutil.WriteFile(filePath, []byte(content), 0644); err != nil { if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
panic(err) panic(err)
} }
return nil return nil

View File

@ -19,7 +19,6 @@ package controllers
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -223,7 +222,7 @@ func (r *GitRepositoryReconciler) checkDependencies(repository sourcev1.GitRepos
func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sourcev1.GitRepository) (sourcev1.GitRepository, error) { func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sourcev1.GitRepository) (sourcev1.GitRepository, error) {
// create tmp dir for the Git clone // create tmp dir for the Git clone
tmpGit, err := ioutil.TempDir("", repository.Name) tmpGit, err := os.MkdirTemp("", repository.Name)
if err != nil { if err != nil {
err = fmt.Errorf("tmp dir error: %w", err) err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.GitRepositoryNotReady(repository, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.GitRepositoryNotReady(repository, sourcev1.StorageOperationFailedReason, err.Error()), err

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -459,7 +458,7 @@ var _ = Describe("GitRepositoryReconciler", func() {
// this one is linked to a real directory, so that I can // this one is linked to a real directory, so that I can
// exec `git submodule add` later // exec `git submodule add` later
tmp, err := ioutil.TempDir("", "flux-test") tmp, err := os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
@ -697,7 +696,7 @@ var _ = Describe("GitRepositoryReconciler", func() {
res, err := http.Get(got.Status.URL) res, err := http.Get(got.Status.URL)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(res.StatusCode).To(Equal(http.StatusOK)) Expect(res.StatusCode).To(Equal(http.StatusOK))
tmp, err := ioutil.TempDir("", "flux-test") tmp, err := os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
_, err = untar.Untar(res.Body, filepath.Join(tmp, "tar")) _, err = untar.Untar(res.Body, filepath.Join(tmp, "tar"))
@ -743,7 +742,7 @@ var _ = Describe("GitRepositoryReconciler", func() {
res, err = http.Get(got.Status.URL) res, err = http.Get(got.Status.URL)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(res.StatusCode).To(Equal(http.StatusOK)) Expect(res.StatusCode).To(Equal(http.StatusOK))
tmp, err = ioutil.TempDir("", "flux-test") tmp, err = os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
_, err = untar.Untar(res.Body, filepath.Join(tmp, "tar")) _, err = untar.Untar(res.Body, filepath.Join(tmp, "tar"))

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -331,7 +330,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
} }
b, err := ioutil.ReadAll(indexFile) b, err := io.ReadAll(indexFile)
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
} }
@ -376,7 +375,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
} }
tmpFile, err := ioutil.TempFile("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name)) tmpFile, err := os.CreateTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
} }
@ -448,7 +447,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
} }
// Create temporary working directory // Create temporary working directory
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name)) tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil { if err != nil {
err = fmt.Errorf("tmp dir error: %w", err) err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
@ -491,7 +490,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context, func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
artifact sourcev1.Artifact, chart sourcev1.HelmChart, force bool) (sourcev1.HelmChart, error) { artifact sourcev1.Artifact, chart sourcev1.HelmChart, force bool) (sourcev1.HelmChart, error) {
// Create temporary working directory // Create temporary working directory
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name)) tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil { if err != nil {
err = fmt.Errorf("tmp dir error: %w", err) err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
@ -554,7 +553,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
} }
valuesData, err := ioutil.ReadFile(srcPath) valuesData, err := os.ReadFile(srcPath)
if err != nil { if err != nil {
err = fmt.Errorf("failed to read from values file '%s': %w", v, err) err = fmt.Errorf("failed to read from values file '%s': %w", v, err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
@ -659,7 +658,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
} }
b, err := ioutil.ReadAll(indexFile) b, err := io.ReadAll(indexFile)
if err != nil { if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
} }

View File

@ -19,7 +19,6 @@ package controllers
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -612,7 +611,7 @@ var _ = Describe("HelmChartReconciler", func() {
return nil return nil
} }
b, err := ioutil.ReadFile(p) b, err := os.ReadFile(p)
if err != nil { if err != nil {
return err return err
} }
@ -872,14 +871,14 @@ var _ = Describe("HelmChartReconciler", func() {
helmChart, err := loader.LoadDir(chartDir) helmChart, err := loader.LoadDir(chartDir)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
chartPackagePath, err := ioutil.TempDir("", fmt.Sprintf("chartpackage-%s-%s", helmChart.Name(), randStringRunes(5))) chartPackagePath, err := os.MkdirTemp("", fmt.Sprintf("chartpackage-%s-%s", helmChart.Name(), randStringRunes(5)))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(chartPackagePath) defer os.RemoveAll(chartPackagePath)
pkg, err := chartutil.Save(helmChart, chartPackagePath) pkg, err := chartutil.Save(helmChart, chartPackagePath)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
b, err := ioutil.ReadFile(pkg) b, err := os.ReadFile(pkg)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tgz := filepath.Base(pkg) tgz := filepath.Base(pkg)
@ -1078,7 +1077,7 @@ var _ = Describe("HelmChartReconciler", func() {
return nil return nil
} }
b, err := ioutil.ReadFile(p) b, err := os.ReadFile(p)
if err != nil { if err != nil {
return err return err
} }

View File

@ -23,7 +23,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -174,7 +173,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
} }
localPath := s.LocalPath(*artifact) localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath)) tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil { if err != nil {
return err return err
} }
@ -272,7 +271,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
// If successful, it sets the checksum and last update time on the artifact. // If successful, it sets the checksum and last update time on the artifact.
func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, mode os.FileMode) (err error) { func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, mode os.FileMode) (err error) {
localPath := s.LocalPath(*artifact) localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath)) tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil { if err != nil {
return err return err
} }
@ -311,7 +310,7 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
// If successful, it sets the checksum and last update time on the artifact. // If successful, it sets the checksum and last update time on the artifact.
func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error) { func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error) {
localPath := s.LocalPath(*artifact) localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath)) tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil { if err != nil {
return err return err
} }
@ -357,7 +356,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
// CopyToPath copies the contents of the given artifact to the path. // CopyToPath copies the contents of the given artifact to the path.
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error { func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
// create a tmp directory to store artifact // create a tmp directory to store artifact
tmp, err := ioutil.TempDir("", "flux-include") tmp, err := os.MkdirTemp("", "flux-include")
if err != nil { if err != nil {
return err return err
} }

View File

@ -21,7 +21,6 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -34,7 +33,7 @@ import (
) )
func createStoragePath() (string, error) { func createStoragePath() (string, error) {
return ioutil.TempDir("", "") return os.MkdirTemp("", "")
} }
func cleanupStoragePath(dir string) func() { func cleanupStoragePath(dir string) func() {
@ -52,7 +51,7 @@ func TestStorageConstructor(t *testing.T) {
t.Fatal("nonexistent path was allowable in storage constructor") t.Fatal("nonexistent path was allowable in storage constructor")
} }
f, err := ioutil.TempFile(dir, "") f, err := os.CreateTemp(dir, "")
if err != nil { if err != nil {
t.Fatalf("while creating temporary file: %v", err) t.Fatalf("while creating temporary file: %v", err)
} }
@ -124,7 +123,7 @@ func TestStorage_Archive(t *testing.T) {
os.RemoveAll(dir) os.RemoveAll(dir)
} }
}() }()
dir, err = ioutil.TempDir("", "archive-test-files-") dir, err = os.MkdirTemp("", "archive-test-files-")
if err != nil { if err != nil {
return return
} }
@ -244,7 +243,7 @@ func TestStorage_Archive(t *testing.T) {
func TestStorageRemoveAllButCurrent(t *testing.T) { func TestStorageRemoveAllButCurrent(t *testing.T) {
t.Run("bad directory in archive", func(t *testing.T) { t.Run("bad directory in archive", func(t *testing.T) {
dir, err := ioutil.TempDir("", "") dir, err := os.MkdirTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -17,7 +17,6 @@ limitations under the License.
package controllers package controllers
import ( import (
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@ -97,7 +96,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(loadExampleKeys()).To(Succeed()) Expect(loadExampleKeys()).To(Succeed())
tmpStoragePath, err := ioutil.TempDir("", "source-controller-storage-") tmpStoragePath, err := os.MkdirTemp("", "source-controller-storage-")
Expect(err).NotTo(HaveOccurred(), "failed to create tmp storage dir") Expect(err).NotTo(HaveOccurred(), "failed to create tmp storage dir")
storage, err = NewStorage(tmpStoragePath, "localhost:5050", time.Second*30) storage, err = NewStorage(tmpStoragePath, "localhost:5050", time.Second*30)
@ -167,15 +166,15 @@ func init() {
} }
func loadExampleKeys() (err error) { func loadExampleKeys() (err error) {
examplePublicKey, err = ioutil.ReadFile("testdata/certs/server.pem") examplePublicKey, err = os.ReadFile("testdata/certs/server.pem")
if err != nil { if err != nil {
return err return err
} }
examplePrivateKey, err = ioutil.ReadFile("testdata/certs/server-key.pem") examplePrivateKey, err = os.ReadFile("testdata/certs/server-key.pem")
if err != nil { if err != nil {
return err return err
} }
exampleCA, err = ioutil.ReadFile("testdata/certs/ca.pem") exampleCA, err = os.ReadFile("testdata/certs/ca.pem")
return err return err
} }

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -92,7 +91,7 @@ func CopyDir(src, dst string) error {
return fmt.Errorf("cannot mkdir %s: %w", dst, err) return fmt.Errorf("cannot mkdir %s: %w", dst, err)
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return fmt.Errorf("cannot read directory %s: %w", dst, err) return fmt.Errorf("cannot read directory %s: %w", dst, err)
} }

View File

@ -6,7 +6,6 @@ package fs
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -20,7 +19,7 @@ var (
) )
func TestRenameWithFallback(t *testing.T) { func TestRenameWithFallback(t *testing.T) {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -58,7 +57,7 @@ func TestRenameWithFallback(t *testing.T) {
} }
func TestCopyDir(t *testing.T) { func TestCopyDir(t *testing.T) {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -119,7 +118,7 @@ func TestCopyDir(t *testing.T) {
t.Fatalf("expected %s to be a directory", dn) t.Fatalf("expected %s to be a directory", dn)
} }
got, err := ioutil.ReadFile(fn) got, err := os.ReadFile(fn)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -156,7 +155,7 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) {
}) })
defer cleanup() defer cleanup()
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -178,7 +177,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
var srcdir, dstdir string var srcdir, dstdir string
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -203,7 +202,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
func TestCopyDirFail_SrcIsNotDir(t *testing.T) { func TestCopyDirFail_SrcIsNotDir(t *testing.T) {
var srcdir, dstdir string var srcdir, dstdir string
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -229,7 +228,7 @@ func TestCopyDirFail_SrcIsNotDir(t *testing.T) {
func TestCopyDirFail_DstExists(t *testing.T) { func TestCopyDirFail_DstExists(t *testing.T) {
var srcdir, dstdir string var srcdir, dstdir string
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -267,7 +266,7 @@ func TestCopyDirFailOpen(t *testing.T) {
var srcdir, dstdir string var srcdir, dstdir string
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -298,7 +297,7 @@ func TestCopyDirFailOpen(t *testing.T) {
} }
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -320,7 +319,7 @@ func TestCopyFile(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
got, err := ioutil.ReadFile(destf) got, err := os.ReadFile(destf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -345,7 +344,7 @@ func TestCopyFile(t *testing.T) {
} }
func TestCopyFileSymlink(t *testing.T) { func TestCopyFileSymlink(t *testing.T) {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -370,11 +369,11 @@ func TestCopyFileSymlink(t *testing.T) {
// Creating symlinks on Windows require an additional permission // Creating symlinks on Windows require an additional permission
// regular users aren't granted usually. So we copy the file // regular users aren't granted usually. So we copy the file
// content as a fall back instead of creating a real symlink. // content as a fall back instead of creating a real symlink.
srcb, err := ioutil.ReadFile(symlink) srcb, err := os.ReadFile(symlink)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)
} }
dstb, err := ioutil.ReadFile(dst) dstb, err := os.ReadFile(dst)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)
} }
@ -407,7 +406,7 @@ func TestCopyFileLongFilePath(t *testing.T) {
t.Skip("skipping on non-windows") t.Skip("skipping on non-windows")
} }
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -424,7 +423,7 @@ func TestCopyFileLongFilePath(t *testing.T) {
t.Fatalf("%+v", fmt.Errorf("unable to create temp directory: %s", fullPath)) t.Fatalf("%+v", fmt.Errorf("unable to create temp directory: %s", fullPath))
} }
err = ioutil.WriteFile(fullPath+"src", []byte(nil), 0644) err = os.WriteFile(fullPath+"src", []byte(nil), 0644)
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)
} }
@ -445,7 +444,7 @@ func TestCopyFileFail(t *testing.T) {
t.Skip("skipping on windows") t.Skip("skipping on windows")
} }
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -485,7 +484,7 @@ func TestCopyFileFail(t *testing.T) {
// files this function creates. It is the caller's responsibility to call // files this function creates. It is the caller's responsibility to call
// this function before the test is done running, whether there's an error or not. // this function before the test is done running, whether there's an error or not.
func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() { func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
return nil // keep compiler happy return nil // keep compiler happy
@ -569,7 +568,7 @@ func TestIsDir(t *testing.T) {
} }
func TestIsSymlink(t *testing.T) { func TestIsSymlink(t *testing.T) {
dir, err := ioutil.TempDir("", "dep") dir, err := os.MkdirTemp("", "dep")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -19,7 +19,7 @@ package helm
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"testing" "testing"
@ -170,7 +170,7 @@ func TestBuild_WithLocalChart(t *testing.T) {
func TestBuild_WithRemoteChart(t *testing.T) { func TestBuild_WithRemoteChart(t *testing.T) {
chart := chartFixture chart := chartFixture
b, err := ioutil.ReadFile(helmPackageFile) b, err := os.ReadFile(helmPackageFile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,7 +18,6 @@ package helm
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -80,7 +79,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret) (getter.Option, func(), err
} }
// create tmp dir for TLS files // create tmp dir for TLS files
tmp, err := ioutil.TempDir("", "helm-tls-"+secret.Name) tmp, err := os.MkdirTemp("", "helm-tls-"+secret.Name)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -90,12 +89,12 @@ func TLSClientConfigFromSecret(secret corev1.Secret) (getter.Option, func(), err
if len(certBytes) > 0 && len(keyBytes) > 0 { if len(certBytes) > 0 && len(keyBytes) > 0 {
certFile = filepath.Join(tmp, "cert.crt") certFile = filepath.Join(tmp, "cert.crt")
if err := ioutil.WriteFile(certFile, certBytes, 0644); err != nil { if err := os.WriteFile(certFile, certBytes, 0644); err != nil {
cleanup() cleanup()
return nil, nil, err return nil, nil, err
} }
keyFile = filepath.Join(tmp, "key.crt") keyFile = filepath.Join(tmp, "key.crt")
if err := ioutil.WriteFile(keyFile, keyBytes, 0644); err != nil { if err := os.WriteFile(keyFile, keyBytes, 0644); err != nil {
cleanup() cleanup()
return nil, nil, err return nil, nil, err
} }
@ -103,7 +102,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret) (getter.Option, func(), err
if len(caBytes) > 0 { if len(caBytes) > 0 {
caFile = filepath.Join(tmp, "ca.pem") caFile = filepath.Join(tmp, "ca.pem")
if err := ioutil.WriteFile(caFile, caBytes, 0644); err != nil { if err := os.WriteFile(caFile, caBytes, 0644); err != nil {
cleanup() cleanup()
return nil, nil, err return nil, nil, err
} }

View File

@ -19,7 +19,7 @@ package helm
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io"
"net/url" "net/url"
"path" "path"
"sort" "sort"
@ -209,7 +209,7 @@ func (r *ChartRepository) DownloadIndex() error {
if err != nil { if err != nil {
return err return err
} }
b, err := ioutil.ReadAll(res) b, err := io.ReadAll(res)
if err != nil { if err != nil {
return err return err
} }

View File

@ -18,8 +18,8 @@ package helm
import ( import (
"bytes" "bytes"
"io/ioutil"
"net/url" "net/url"
"os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -231,7 +231,7 @@ func TestChartRepository_DownloadChart(t *testing.T) {
} }
func TestChartRepository_DownloadIndex(t *testing.T) { func TestChartRepository_DownloadIndex(t *testing.T) {
b, err := ioutil.ReadFile(chartmuseumtestfile) b, err := os.ReadFile(chartmuseumtestfile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -270,7 +270,7 @@ func TestChartRepository_LoadIndex(t *testing.T) {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel() t.Parallel()
b, err := ioutil.ReadFile(tt.filename) b, err := os.ReadFile(tt.filename)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -292,7 +292,7 @@ func TestChartRepository_LoadIndex_Duplicates(t *testing.T) {
} }
func TestChartRepository_LoadIndex_Unordered(t *testing.T) { func TestChartRepository_LoadIndex_Unordered(t *testing.T) {
b, err := ioutil.ReadFile(unorderedtestfile) b, err := os.ReadFile(unorderedtestfile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,7 +18,6 @@ package gogit
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -30,7 +29,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
tag := CheckoutTag{ tag := CheckoutTag{
tag: "v1.7.0", tag: "v1.7.0",
} }
tmpDir, _ := ioutil.TempDir("", "test") tmpDir, _ := os.MkdirTemp("", "test")
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
cTag, _, err := tag.Checkout(context.TODO(), tmpDir, "https://github.com/projectcontour/contour", auth) cTag, _, err := tag.Checkout(context.TODO(), tmpDir, "https://github.com/projectcontour/contour", auth)
@ -41,7 +40,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
semVer := CheckoutSemVer{ semVer := CheckoutSemVer{
semVer: ">=1.0.0 <=1.7.0", semVer: ">=1.0.0 <=1.7.0",
} }
tmpDir2, _ := ioutil.TempDir("", "test") tmpDir2, _ := os.MkdirTemp("", "test")
defer os.RemoveAll(tmpDir2) defer os.RemoveAll(tmpDir2)
cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth) cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth)

View File

@ -21,7 +21,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"testing" "testing"
@ -40,7 +39,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
tag := CheckoutTag{ tag := CheckoutTag{
tag: "v1.7.0", tag: "v1.7.0",
} }
tmpDir, _ := ioutil.TempDir("", "test") tmpDir, _ := os.MkdirTemp("", "test")
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
cTag, _, err := tag.Checkout(context.TODO(), tmpDir, "https://github.com/projectcontour/contour", auth) cTag, _, err := tag.Checkout(context.TODO(), tmpDir, "https://github.com/projectcontour/contour", auth)
@ -66,7 +65,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
semVer := CheckoutSemVer{ semVer := CheckoutSemVer{
semVer: ">=1.0.0 <=1.7.0", semVer: ">=1.0.0 <=1.7.0",
} }
tmpDir2, _ := ioutil.TempDir("", "test") tmpDir2, _ := os.MkdirTemp("", "test")
defer os.RemoveAll(tmpDir2) defer os.RemoveAll(tmpDir2)
cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth) cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth)

View File

@ -19,7 +19,6 @@ package sourceignore
import ( import (
"bufio" "bufio"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -108,7 +107,7 @@ func LoadIgnorePatterns(dir string, domain []string) ([]gitignore.Pattern, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
fis, err := ioutil.ReadDir(dir) fis, err := os.ReadDir(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,7 +17,6 @@ limitations under the License.
package sourceignore package sourceignore
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -74,7 +73,7 @@ func TestReadPatterns(t *testing.T) {
} }
func TestReadIgnoreFile(t *testing.T) { func TestReadIgnoreFile(t *testing.T) {
f, err := ioutil.TempFile("", IgnoreFile) f, err := os.CreateTemp("", IgnoreFile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -198,7 +197,7 @@ func TestDefaultPatterns(t *testing.T) {
} }
func TestLoadExcludePatterns(t *testing.T) { func TestLoadExcludePatterns(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "sourceignore-load-") tmpDir, err := os.MkdirTemp("", "sourceignore-load-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }