diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index b02850acd..048811cc6 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -21,7 +21,6 @@ import ( "crypto/sha1" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -197,7 +196,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, obj *sourcev1.Bucket) } // Create temp dir for the bucket objects - tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-%s-", obj.Kind, obj.Namespace, obj.Name)) + tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-%s-", obj.Kind, obj.Namespace, obj.Name)) if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.StorageOperationFailedReason, "Failed to create temporary directory: %s", err) return ctrl.Result{}, err diff --git a/controllers/bucket_controller_test.go b/controllers/bucket_controller_test.go index 2991b272e..be883384d 100644 --- a/controllers/bucket_controller_test.go +++ b/controllers/bucket_controller_test.go @@ -20,7 +20,6 @@ import ( "context" "crypto/md5" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -397,7 +396,7 @@ func TestBucketReconciler_reconcileSource(t *testing.T) { Client: builder.Build(), Storage: storage, } - tmpDir, err := ioutil.TempDir("", "reconcile-bucket-source-") + tmpDir, err := os.MkdirTemp("", "reconcile-bucket-source-") g.Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpDir) @@ -499,7 +498,7 @@ func TestBucketReconciler_reconcileArtifact(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "reconcile-bucket-artifact-") + tmpDir, err := os.MkdirTemp("", "reconcile-bucket-artifact-") g.Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpDir) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 2fa014cc5..a768ccc45 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - "io/ioutil" "os" "strings" "time" @@ -206,7 +205,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G } // Create temp dir for Git clone - tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-%s-", obj.Kind, obj.Namespace, obj.Name)) + tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-%s-", obj.Kind, obj.Namespace, obj.Name)) if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.StorageOperationFailedReason, "Failed to create temporary directory: %s", err) return ctrl.Result{}, err diff --git a/controllers/gitrepository_controller_test.go b/controllers/gitrepository_controller_test.go index 634459252..fdb07fcd9 100644 --- a/controllers/gitrepository_controller_test.go +++ b/controllers/gitrepository_controller_test.go @@ -18,7 +18,6 @@ package controllers import ( "fmt" - "io/ioutil" "net/url" "os" "path/filepath" @@ -385,7 +384,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) { t.Skipf("Skipped for Git implementation %q", i) } - tmpDir, err := ioutil.TempDir("", "auth-strategy-") + tmpDir, err := os.MkdirTemp("", "auth-strategy-") g.Expect(err).To(BeNil()) defer os.RemoveAll(tmpDir) @@ -527,7 +526,7 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T) t.Run(i, func(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "checkout-strategy-") + tmpDir, err := os.MkdirTemp("", "checkout-strategy-") g.Expect(err).NotTo(HaveOccurred()) obj := obj.DeepCopy() @@ -832,7 +831,7 @@ func TestGitRepositoryReconciler_reconcileInclude(t *testing.T) { obj.Spec.Include = append(obj.Spec.Include, incl) } - tmpDir, err := ioutil.TempDir("", "include-") + tmpDir, err := os.MkdirTemp("", "include-") g.Expect(err).NotTo(HaveOccurred()) var artifacts artifactSet @@ -1081,7 +1080,7 @@ func commitFromFixture(repo *gogit.Repository, fixture string) error { return fs.MkdirAll(fs.Join(path[len(fixture):]), info.Mode()) } - fileBytes, err := ioutil.ReadFile(path) + fileBytes, err := os.ReadFile(path) if err != nil { return err } diff --git a/controllers/helmchart_controller_chart.go b/controllers/helmchart_controller_chart.go index 885a15c60..60c42d02c 100644 --- a/controllers/helmchart_controller_chart.go +++ b/controllers/helmchart_controller_chart.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -84,7 +83,7 @@ func (r *HelmChartReconciler) reconcileChart(ctx context.Context, obj *sourcev1. // We need to (re)package the chart if conditions.IsTrue(obj, sourcev1.DependenciesBuildCondition) || conditions.IsTrue(obj, sourcev1.ValuesFilesMergedCondition) { - tmpDir, err := ioutil.TempDir("", "helm-chart-pkg-") + tmpDir, err := os.MkdirTemp("", "helm-chart-pkg-") if err != nil { conditions.MarkFalse(obj, sourcev1.ChartPackagedCondition, sourcev1.StorageOperationFailedReason, "Could not create temporary directory for packaging operation: %s", err.Error()) return ctrl.Result{}, err @@ -146,7 +145,7 @@ func (r *HelmChartReconciler) buildChartDependencies(ctx context.Context, obj *s Chart: chart, } - tmpDir, err := ioutil.TempDir("", "build-chart-deps-") + tmpDir, err := os.MkdirTemp("", "build-chart-deps-") if err != nil { conditions.MarkFalse(obj, sourcev1.ChartReconciled, sourcev1.StorageOperationFailedReason, "Could not create temporary directory for dependency credentials: %s", err.Error()) return ctrl.Result{}, err @@ -347,7 +346,7 @@ func mergeFileValues(dir string, valuesFiles []string) (map[string]interface{}, return nil, fmt.Errorf("invalid values file path %q", p) } - b, err := ioutil.ReadFile(secureP) + b, err := os.ReadFile(secureP) if err != nil { return nil, fmt.Errorf("could not read values from file %q: %w", p, err) } diff --git a/controllers/helmchart_controller_source.go b/controllers/helmchart_controller_source.go index a8a2a07c2..1c4b838f2 100644 --- a/controllers/helmchart_controller_source.go +++ b/controllers/helmchart_controller_source.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/url" "os" @@ -105,7 +104,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context, o } // Get client options from secret - tmpDir, err := ioutil.TempDir("", "helm-client-") + tmpDir, err := os.MkdirTemp("", "helm-client-") if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.AuthenticationFailedReason, "Could not create temporary directory for : %s", err.Error()) return ctrl.Result{}, err @@ -151,7 +150,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context, o } // Create a new temporary file for the chart and download it - f, err := ioutil.TempFile("", fmt.Sprintf("%s-%s-", obj.Name, obj.Namespace)) + f, err := os.CreateTemp("", fmt.Sprintf("%s-%s-", obj.Name, obj.Namespace)) if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.ChartPullFailedReason, "Chart download for %q version %q failed: %s", obj.Spec.Chart, chartVer.Version, err.Error()) return ctrl.Result{}, err @@ -182,7 +181,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context, return ctrl.Result{}, err } - dir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-", obj.Name, obj.Namespace)) + dir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", obj.Name, obj.Namespace)) if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.StorageOperationFailedReason, "Could not create temporary working directory: %s", err.Error()) return ctrl.Result{}, err diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index 0475a7b63..c4c563fef 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -20,7 +20,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "net/url" "os" "time" @@ -265,7 +264,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou } // Get client options from secret - tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-source-", obj.Name, obj.Namespace)) + tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-source-", obj.Name, obj.Namespace)) if err != nil { conditions.MarkFalse(obj, sourcev1.SourceAvailableCondition, sourcev1.StorageOperationFailedReason, "Could not create temporary directory for credentials: %s", err.Error()) r.Events.Event(ctx, obj, events.EventSeverityError, sourcev1.AuthenticationFailedReason, conditions.Get(obj, sourcev1.SourceAvailableCondition).Message) diff --git a/controllers/storage.go b/controllers/storage.go index 0bea42d1d..ba1d27972 100644 --- a/controllers/storage.go +++ b/controllers/storage.go @@ -23,7 +23,6 @@ import ( "fmt" "hash" "io" - "io/ioutil" "net/url" "os" "path/filepath" @@ -179,7 +178,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv } localPath := s.LocalPath(*artifact) - tf, err := ioutil.TempFile(filepath.Split(localPath)) + tf, err := os.CreateTemp(filepath.Split(localPath)) if err != nil { return err } @@ -277,7 +276,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. func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, mode os.FileMode) (err error) { localPath := s.LocalPath(*artifact) - tf, err := ioutil.TempFile(filepath.Split(localPath)) + tf, err := os.CreateTemp(filepath.Split(localPath)) if err != nil { return err } @@ -316,7 +315,7 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, // 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) { localPath := s.LocalPath(*artifact) - tf, err := ioutil.TempFile(filepath.Split(localPath)) + tf, err := os.CreateTemp(filepath.Split(localPath)) if err != nil { return err } @@ -363,7 +362,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er // given path. func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error { // create a tmp directory to store artifact - tmp, err := ioutil.TempDir("", "flux-include-") + tmp, err := os.MkdirTemp("", "flux-include-") if err != nil { return err } diff --git a/controllers/storage_test.go b/controllers/storage_test.go index a79df6a14..8da8d49df 100644 --- a/controllers/storage_test.go +++ b/controllers/storage_test.go @@ -21,7 +21,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -34,7 +33,7 @@ import ( ) func createStoragePath() (string, error) { - return ioutil.TempDir("", "") + return os.MkdirTemp("", "") } func cleanupStoragePath(dir string) func() { @@ -52,7 +51,7 @@ func TestStorageConstructor(t *testing.T) { t.Fatal("nonexistent path was allowable in storage constructor") } - f, err := ioutil.TempFile(dir, "") + f, err := os.CreateTemp(dir, "") if err != nil { t.Fatalf("while creating temporary file: %v", err) } @@ -124,7 +123,7 @@ func TestStorage_Archive(t *testing.T) { os.RemoveAll(dir) } }() - dir, err = ioutil.TempDir("", "archive-test-files-") + dir, err = os.MkdirTemp("", "archive-test-files-") if err != nil { return } @@ -244,7 +243,7 @@ func TestStorage_Archive(t *testing.T) { func TestStorageRemoveAllButCurrent(t *testing.T) { t.Run("bad directory in archive", func(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index b3df85469..1e4d72b5f 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -18,7 +18,6 @@ package controllers import ( "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -154,15 +153,15 @@ func TestMain(m *testing.M) { func initTestTLS() { var err error - tlsPublicKey, err = ioutil.ReadFile("testdata/certs/server.pem") + tlsPublicKey, err = os.ReadFile("testdata/certs/server.pem") if err != nil { panic(err) } - tlsPrivateKey, err = ioutil.ReadFile("testdata/certs/server-key.pem") + tlsPrivateKey, err = os.ReadFile("testdata/certs/server-key.pem") if err != nil { panic(err) } - tlsCA, err = ioutil.ReadFile("testdata/certs/ca.pem") + tlsCA, err = os.ReadFile("testdata/certs/ca.pem") if err != nil { panic(err) } diff --git a/internal/fs/fs.go b/internal/fs/fs.go index c8ece049d..21cf96e69 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -92,7 +91,7 @@ func CopyDir(src, dst string) error { return fmt.Errorf("cannot mkdir %s: %w", dst, err) } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return fmt.Errorf("cannot read directory %s: %w", dst, err) } diff --git a/internal/fs/fs_test.go b/internal/fs/fs_test.go index eba87eba0..250556bc2 100644 --- a/internal/fs/fs_test.go +++ b/internal/fs/fs_test.go @@ -6,7 +6,6 @@ package fs import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ var ( ) func TestRenameWithFallback(t *testing.T) { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -58,7 +57,7 @@ func TestRenameWithFallback(t *testing.T) { } func TestCopyDir(t *testing.T) { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -119,7 +118,7 @@ func TestCopyDir(t *testing.T) { t.Fatalf("expected %s to be a directory", dn) } - got, err := ioutil.ReadFile(fn) + got, err := os.ReadFile(fn) if err != nil { t.Fatal(err) } @@ -156,7 +155,7 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) { }) defer cleanup() - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -178,7 +177,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) { var srcdir, dstdir string - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -203,7 +202,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) { func TestCopyDirFail_SrcIsNotDir(t *testing.T) { var srcdir, dstdir string - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -229,7 +228,7 @@ func TestCopyDirFail_SrcIsNotDir(t *testing.T) { func TestCopyDirFail_DstExists(t *testing.T) { var srcdir, dstdir string - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -267,7 +266,7 @@ func TestCopyDirFailOpen(t *testing.T) { var srcdir, dstdir string - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -298,7 +297,7 @@ func TestCopyDirFailOpen(t *testing.T) { } func TestCopyFile(t *testing.T) { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -320,7 +319,7 @@ func TestCopyFile(t *testing.T) { t.Fatal(err) } - got, err := ioutil.ReadFile(destf) + got, err := os.ReadFile(destf) if err != nil { t.Fatal(err) } @@ -345,7 +344,7 @@ func TestCopyFile(t *testing.T) { } func TestCopyFileSymlink(t *testing.T) { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -370,11 +369,11 @@ func TestCopyFileSymlink(t *testing.T) { // Creating symlinks on Windows require an additional permission // regular users aren't granted usually. So we copy the file // content as a fall back instead of creating a real symlink. - srcb, err := ioutil.ReadFile(symlink) + srcb, err := os.ReadFile(symlink) if err != nil { t.Fatalf("%+v", err) } - dstb, err := ioutil.ReadFile(dst) + dstb, err := os.ReadFile(dst) if err != nil { t.Fatalf("%+v", err) } @@ -407,7 +406,7 @@ func TestCopyFileLongFilePath(t *testing.T) { t.Skip("skipping on non-windows") } - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -424,7 +423,7 @@ func TestCopyFileLongFilePath(t *testing.T) { 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 { t.Fatalf("%+v", err) } @@ -445,7 +444,7 @@ func TestCopyFileFail(t *testing.T) { t.Skip("skipping on windows") } - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } @@ -485,7 +484,7 @@ func TestCopyFileFail(t *testing.T) { // 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. func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) return nil // keep compiler happy @@ -569,7 +568,7 @@ func TestIsDir(t *testing.T) { } func TestIsSymlink(t *testing.T) { - dir, err := ioutil.TempDir("", "dep") + dir, err := os.MkdirTemp("", "dep") if err != nil { t.Fatal(err) } diff --git a/internal/helm/dependency_manager_test.go b/internal/helm/dependency_manager_test.go index a66977751..5a5def3c2 100644 --- a/internal/helm/dependency_manager_test.go +++ b/internal/helm/dependency_manager_test.go @@ -19,7 +19,7 @@ package helm import ( "context" "fmt" - "io/ioutil" + "os" "strings" "testing" @@ -170,7 +170,7 @@ func TestBuild_WithLocalChart(t *testing.T) { func TestBuild_WithRemoteChart(t *testing.T) { chart := chartFixture - b, err := ioutil.ReadFile(helmPackageFile) + b, err := os.ReadFile(helmPackageFile) if err != nil { t.Fatal(err) } diff --git a/internal/helm/getter.go b/internal/helm/getter.go index 932bc9092..c92351184 100644 --- a/internal/helm/getter.go +++ b/internal/helm/getter.go @@ -20,7 +20,7 @@ import ( "bytes" "fmt" "io" - "io/ioutil" + "os" "helm.sh/helm/v3/pkg/getter" corev1 "k8s.io/api/core/v1" @@ -82,7 +82,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret, dir string) (getter.Option, var certFile, keyFile, caFile string if len(certBytes) > 0 && len(keyBytes) > 0 { - f, err := ioutil.TempFile(dir, "cert-") + f, err := os.CreateTemp(dir, "cert-") if err != nil { } @@ -93,7 +93,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret, dir string) (getter.Option, f.Close() certFile = f.Name() - f, err = ioutil.TempFile(dir, "key-") + f, err = os.CreateTemp(dir, "key-") if err != nil { f.Close() return nil, err @@ -107,7 +107,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret, dir string) (getter.Option, } if len(caBytes) > 0 { - f, err := ioutil.TempFile(dir, "ca-") + f, err := os.CreateTemp(dir, "ca-") if err != nil { f.Close() return nil, err diff --git a/internal/helm/getter_test.go b/internal/helm/getter_test.go index 353854c2a..baf5c423a 100644 --- a/internal/helm/getter_test.go +++ b/internal/helm/getter_test.go @@ -17,7 +17,6 @@ limitations under the License. package helm import ( - "io/ioutil" "os" "testing" @@ -58,7 +57,7 @@ func TestClientOptionsFromSecret(t *testing.T) { secret.Data[k] = v } } - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Failed to create temporary directory: %v", err) } @@ -127,7 +126,7 @@ func TestTLSClientConfigFromSecret(t *testing.T) { if tt.modify != nil { tt.modify(secret) } - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Failed to create temporary directory: %v", err) } diff --git a/internal/helm/repository.go b/internal/helm/repository.go index 9f9e667fd..b964e5ac0 100644 --- a/internal/helm/repository.go +++ b/internal/helm/repository.go @@ -20,8 +20,9 @@ import ( "bytes" "crypto/sha1" "fmt" - "io/ioutil" + "io" "net/url" + "os" "path" "sort" "strings" @@ -179,7 +180,7 @@ func (r *ChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer // LoadIndexFile takes a file at the given path and loads it using LoadIndex. func (r *ChartRepository) LoadIndexFile(path string) error { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return err } @@ -221,7 +222,7 @@ func (r *ChartRepository) DownloadIndex() error { if err != nil { return err } - b, err := ioutil.ReadAll(res) + b, err := io.ReadAll(res) if err != nil { return err } diff --git a/internal/helm/repository_test.go b/internal/helm/repository_test.go index 468866674..c51a19d40 100644 --- a/internal/helm/repository_test.go +++ b/internal/helm/repository_test.go @@ -18,8 +18,8 @@ package helm import ( "bytes" - "io/ioutil" "net/url" + "os" "reflect" "strings" "testing" @@ -231,7 +231,7 @@ func TestChartRepository_DownloadChart(t *testing.T) { } func TestChartRepository_DownloadIndex(t *testing.T) { - b, err := ioutil.ReadFile(chartmuseumtestfile) + b, err := os.ReadFile(chartmuseumtestfile) if err != nil { t.Fatal(err) } @@ -270,7 +270,7 @@ func TestChartRepository_LoadIndex(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - b, err := ioutil.ReadFile(tt.filename) + b, err := os.ReadFile(tt.filename) if err != nil { t.Fatal(err) } @@ -292,7 +292,7 @@ func TestChartRepository_LoadIndex_Duplicates(t *testing.T) { } func TestChartRepository_LoadIndex_Unordered(t *testing.T) { - b, err := ioutil.ReadFile(unorderedtestfile) + b, err := os.ReadFile(unorderedtestfile) if err != nil { t.Fatal(err) } diff --git a/pkg/git/gogit/checkout_test.go b/pkg/git/gogit/checkout_test.go index aa1c3ca71..eaa12c556 100644 --- a/pkg/git/gogit/checkout_test.go +++ b/pkg/git/gogit/checkout_test.go @@ -18,7 +18,6 @@ package gogit import ( "context" - "io/ioutil" "os" "testing" @@ -30,7 +29,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) { tag := CheckoutTag{ tag: "v1.7.0", } - tmpDir, _ := ioutil.TempDir("", "test") + tmpDir, _ := os.MkdirTemp("", "test") defer os.RemoveAll(tmpDir) 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: ">=1.0.0 <=1.7.0", } - tmpDir2, _ := ioutil.TempDir("", "test") + tmpDir2, _ := os.MkdirTemp("", "test") defer os.RemoveAll(tmpDir2) cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth) diff --git a/pkg/git/libgit2/checkout_test.go b/pkg/git/libgit2/checkout_test.go index 8c9d94839..6de5484d8 100644 --- a/pkg/git/libgit2/checkout_test.go +++ b/pkg/git/libgit2/checkout_test.go @@ -21,7 +21,6 @@ import ( "crypto/sha256" "encoding/hex" "io" - "io/ioutil" "os" "path" "testing" @@ -40,7 +39,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) { tag := CheckoutTag{ tag: "v1.7.0", } - tmpDir, _ := ioutil.TempDir("", "test") + tmpDir, _ := os.MkdirTemp("", "test") defer os.RemoveAll(tmpDir) 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: ">=1.0.0 <=1.7.0", } - tmpDir2, _ := ioutil.TempDir("", "test") + tmpDir2, _ := os.MkdirTemp("", "test") defer os.RemoveAll(tmpDir2) cSemVer, _, err := semVer.Checkout(context.TODO(), tmpDir2, "https://github.com/projectcontour/contour", auth) diff --git a/pkg/sourceignore/sourceignore.go b/pkg/sourceignore/sourceignore.go index b4e0bf50f..f4d98e471 100644 --- a/pkg/sourceignore/sourceignore.go +++ b/pkg/sourceignore/sourceignore.go @@ -19,7 +19,6 @@ package sourceignore import ( "bufio" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -108,7 +107,7 @@ func LoadIgnorePatterns(dir string, domain []string) ([]gitignore.Pattern, error if err != nil { return nil, err } - fis, err := ioutil.ReadDir(dir) + fis, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/pkg/sourceignore/sourceignore_test.go b/pkg/sourceignore/sourceignore_test.go index 98a88d7e0..786868ba1 100644 --- a/pkg/sourceignore/sourceignore_test.go +++ b/pkg/sourceignore/sourceignore_test.go @@ -17,7 +17,6 @@ limitations under the License. package sourceignore import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -74,7 +73,7 @@ func TestReadPatterns(t *testing.T) { } func TestReadIgnoreFile(t *testing.T) { - f, err := ioutil.TempFile("", IgnoreFile) + f, err := os.CreateTemp("", IgnoreFile) if err != nil { t.Fatal(err) } @@ -198,7 +197,7 @@ func TestDefaultPatterns(t *testing.T) { } func TestLoadExcludePatterns(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "sourceignore-load-") + tmpDir, err := os.MkdirTemp("", "sourceignore-load-") if err != nil { t.Fatal(err) }