Skip to content

Commit

Permalink
Merge pull request #267 from fluxcd/replace-ioutils
Browse files Browse the repository at this point in the history
Remove deprecated `io/ioutil`
  • Loading branch information
stefanprodan authored Nov 22, 2021
2 parents f2a48b6 + bfcb9ef commit fbf889e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
7 changes: 3 additions & 4 deletions controllers/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -41,7 +40,7 @@ func populateRepoFromFixture(repo *gogit.Repository, fixture string) error {
return fs.Symlink(target, path[len(fixture):])
}

fileBytes, err := ioutil.ReadFile(path)
fileBytes, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestRepoForFixture(t *testing.T) {

func TestIgnoreBrokenSymlink(t *testing.T) {
// init a git repo in the filesystem so we can operate on files there
tmp, err := ioutil.TempDir("", "flux-test")
tmp, err := os.MkdirTemp("", "flux-test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -145,7 +144,7 @@ func TestPushRejected(t *testing.T) {
t.Fatal(err)
}

tmp, err := ioutil.TempDir("", "gotest-imageauto-git")
tmp, err := os.MkdirTemp("", "gotest-imageauto-git")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/imageupdateautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -212,7 +211,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
tracelog.Info("using push branch from $ref.branch", "branch", pushBranch)
}

tmp, err := ioutil.TempDir("", fmt.Sprintf("%s-%s", originName.Namespace, originName.Name))
tmp, err := os.MkdirTemp("", fmt.Sprintf("%s-%s", originName.Namespace, originName.Name))
if err != nil {
return failWithError(err)
}
Expand Down
11 changes: 5 additions & 6 deletions controllers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math/rand"
"net/url"
"os"
Expand Down Expand Up @@ -1014,12 +1013,12 @@ func expectCommittedAndPushed(conditions []metav1.Condition) {
func replaceMarker(path string, policyKey types.NamespacedName) error {
// NB this requires knowledge of what's in the git repo, so a little brittle
deployment := filepath.Join(path, "deploy.yaml")
filebytes, err := ioutil.ReadFile(deployment)
filebytes, err := os.ReadFile(deployment)
if err != nil {
return err
}
newfilebytes := bytes.ReplaceAll(filebytes, []byte("SETTER_SITE"), []byte(setterRef(policyKey)))
if err = ioutil.WriteFile(deployment, newfilebytes, os.FileMode(0666)); err != nil {
if err = os.WriteFile(deployment, newfilebytes, os.FileMode(0666)); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -1076,13 +1075,13 @@ func waitForNewHead(repo *git.Repository, branch string) {
}

func compareRepoWithExpected(repoURL, branch, fixture string, changeFixture func(tmp string)) {
expected, err := ioutil.TempDir("", "gotest-imageauto-expected")
expected, err := os.MkdirTemp("", "gotest-imageauto-expected")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(expected)
copy.Copy(fixture, expected)
changeFixture(expected)

tmp, err := ioutil.TempDir("", "gotest-imageauto")
tmp, err := os.MkdirTemp("", "gotest-imageauto")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp)
_, err = git.PlainClone(tmp, false, &git.CloneOptions{
Expand All @@ -1094,7 +1093,7 @@ func compareRepoWithExpected(repoURL, branch, fixture string, changeFixture func
}

func commitInRepo(repoURL, branch, msg string, changeFiles func(path string)) {
tmp, err := ioutil.TempDir("", "gotest-imageauto")
tmp, err := os.MkdirTemp("", "gotest-imageauto")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp)
repo, err := git.PlainClone(tmp, false, &git.CloneOptions{
Expand Down
5 changes: 2 additions & 3 deletions pkg/test/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package test

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -124,11 +123,11 @@ func DiffDirectories(actual, expected string) (actualonly []string, expectedonly

// both regular files

actualBytes, err := ioutil.ReadFile(actualPath)
actualBytes, err := os.ReadFile(actualPath)
if err != nil {
panic(err)
}
expectedBytes, err := ioutil.ReadFile(expectedPath)
expectedBytes, err := os.ReadFile(expectedPath)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/update/filereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package update
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -101,7 +100,7 @@ func (r *ScreeningLocalReader) Read() ([]*yaml.RNode, error) {

// To check for the token, I need the file contents. This
// assumes the file is encoded as UTF8.
filebytes, err := ioutil.ReadFile(p)
filebytes, err := os.ReadFile(p)
if err != nil {
return fmt.Errorf("reading YAML file: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package update

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -64,7 +63,7 @@ var _ = Describe("Update image via kyaml setters2", func() {
)

It("updates the image marked with the image policy (setter) ref", func() {
tmp, err := ioutil.TempDir("", "gotest")
tmp, err := os.MkdirTemp("", "gotest")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp)

Expand Down Expand Up @@ -95,7 +94,7 @@ var _ = Describe("Update image via kyaml setters2", func() {
})

It("gives the result of the updates", func() {
tmp, err := ioutil.TempDir("", "gotest")
tmp, err := os.MkdirTemp("", "gotest")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp)

Expand Down

0 comments on commit fbf889e

Please # to comment.