Skip to content

Commit fbf889e

Browse files
authored
Merge pull request #267 from fluxcd/replace-ioutils
Remove deprecated `io/ioutil`
2 parents f2a48b6 + bfcb9ef commit fbf889e

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

controllers/git_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package controllers
22

33
import (
44
"context"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -41,7 +40,7 @@ func populateRepoFromFixture(repo *gogit.Repository, fixture string) error {
4140
return fs.Symlink(target, path[len(fixture):])
4241
}
4342

44-
fileBytes, err := ioutil.ReadFile(path)
43+
fileBytes, err := os.ReadFile(path)
4544
if err != nil {
4645
return err
4746
}
@@ -90,7 +89,7 @@ func TestRepoForFixture(t *testing.T) {
9089

9190
func TestIgnoreBrokenSymlink(t *testing.T) {
9291
// init a git repo in the filesystem so we can operate on files there
93-
tmp, err := ioutil.TempDir("", "flux-test")
92+
tmp, err := os.MkdirTemp("", "flux-test")
9493
if err != nil {
9594
t.Fatal(err)
9695
}
@@ -145,7 +144,7 @@ func TestPushRejected(t *testing.T) {
145144
t.Fatal(err)
146145
}
147146

148-
tmp, err := ioutil.TempDir("", "gotest-imageauto-git")
147+
tmp, err := os.MkdirTemp("", "gotest-imageauto-git")
149148
if err != nil {
150149
t.Fatal(err)
151150
}

controllers/imageupdateautomation_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
"io/ioutil"
2524
"math"
2625
"os"
2726
"path/filepath"
@@ -212,7 +211,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
212211
tracelog.Info("using push branch from $ref.branch", "branch", pushBranch)
213212
}
214213

215-
tmp, err := ioutil.TempDir("", fmt.Sprintf("%s-%s", originName.Namespace, originName.Name))
214+
tmp, err := os.MkdirTemp("", fmt.Sprintf("%s-%s", originName.Namespace, originName.Name))
216215
if err != nil {
217216
return failWithError(err)
218217
}

controllers/update_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"context"
2222
"fmt"
23-
"io/ioutil"
2423
"math/rand"
2524
"net/url"
2625
"os"
@@ -1014,12 +1013,12 @@ func expectCommittedAndPushed(conditions []metav1.Condition) {
10141013
func replaceMarker(path string, policyKey types.NamespacedName) error {
10151014
// NB this requires knowledge of what's in the git repo, so a little brittle
10161015
deployment := filepath.Join(path, "deploy.yaml")
1017-
filebytes, err := ioutil.ReadFile(deployment)
1016+
filebytes, err := os.ReadFile(deployment)
10181017
if err != nil {
10191018
return err
10201019
}
10211020
newfilebytes := bytes.ReplaceAll(filebytes, []byte("SETTER_SITE"), []byte(setterRef(policyKey)))
1022-
if err = ioutil.WriteFile(deployment, newfilebytes, os.FileMode(0666)); err != nil {
1021+
if err = os.WriteFile(deployment, newfilebytes, os.FileMode(0666)); err != nil {
10231022
return err
10241023
}
10251024
return nil
@@ -1076,13 +1075,13 @@ func waitForNewHead(repo *git.Repository, branch string) {
10761075
}
10771076

10781077
func compareRepoWithExpected(repoURL, branch, fixture string, changeFixture func(tmp string)) {
1079-
expected, err := ioutil.TempDir("", "gotest-imageauto-expected")
1078+
expected, err := os.MkdirTemp("", "gotest-imageauto-expected")
10801079
Expect(err).ToNot(HaveOccurred())
10811080
defer os.RemoveAll(expected)
10821081
copy.Copy(fixture, expected)
10831082
changeFixture(expected)
10841083

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

10961095
func commitInRepo(repoURL, branch, msg string, changeFiles func(path string)) {
1097-
tmp, err := ioutil.TempDir("", "gotest-imageauto")
1096+
tmp, err := os.MkdirTemp("", "gotest-imageauto")
10981097
Expect(err).ToNot(HaveOccurred())
10991098
defer os.RemoveAll(tmp)
11001099
repo, err := git.PlainClone(tmp, false, &git.CloneOptions{

pkg/test/files.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package test
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"strings"
@@ -124,11 +123,11 @@ func DiffDirectories(actual, expected string) (actualonly []string, expectedonly
124123

125124
// both regular files
126125

127-
actualBytes, err := ioutil.ReadFile(actualPath)
126+
actualBytes, err := os.ReadFile(actualPath)
128127
if err != nil {
129128
panic(err)
130129
}
131-
expectedBytes, err := ioutil.ReadFile(expectedPath)
130+
expectedBytes, err := os.ReadFile(expectedPath)
132131
if err != nil {
133132
panic(err)
134133
}

pkg/update/filereader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package update
1919
import (
2020
"bytes"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524

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

102101
// To check for the token, I need the file contents. This
103102
// assumes the file is encoded as UTF8.
104-
filebytes, err := ioutil.ReadFile(p)
103+
filebytes, err := os.ReadFile(p)
105104
if err != nil {
106105
return fmt.Errorf("reading YAML file: %w", err)
107106
}

pkg/update/update_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package update
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"testing"
2322

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

6665
It("updates the image marked with the image policy (setter) ref", func() {
67-
tmp, err := ioutil.TempDir("", "gotest")
66+
tmp, err := os.MkdirTemp("", "gotest")
6867
Expect(err).ToNot(HaveOccurred())
6968
defer os.RemoveAll(tmp)
7069

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

9796
It("gives the result of the updates", func() {
98-
tmp, err := ioutil.TempDir("", "gotest")
97+
tmp, err := os.MkdirTemp("", "gotest")
9998
Expect(err).ToNot(HaveOccurred())
10099
defer os.RemoveAll(tmp)
101100

0 commit comments

Comments
 (0)