Merge pull request #267 from fluxcd/replace-ioutils

Remove deprecated `io/ioutil`
This commit is contained in:
Stefan Prodan 2021-11-22 16:29:31 +02:00 committed by GitHub
commit fbf889ef80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 20 deletions

View File

@ -2,7 +2,6 @@ package controllers
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -41,7 +40,7 @@ func populateRepoFromFixture(repo *gogit.Repository, fixture string) error {
return fs.Symlink(target, path[len(fixture):]) return fs.Symlink(target, path[len(fixture):])
} }
fileBytes, err := ioutil.ReadFile(path) fileBytes, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }
@ -90,7 +89,7 @@ func TestRepoForFixture(t *testing.T) {
func TestIgnoreBrokenSymlink(t *testing.T) { func TestIgnoreBrokenSymlink(t *testing.T) {
// init a git repo in the filesystem so we can operate on files there // 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -145,7 +144,7 @@ func TestPushRejected(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
tmp, err := ioutil.TempDir("", "gotest-imageauto-git") tmp, err := os.MkdirTemp("", "gotest-imageauto-git")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -21,7 +21,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
@ -212,7 +211,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
tracelog.Info("using push branch from $ref.branch", "branch", pushBranch) 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 { if err != nil {
return failWithError(err) return failWithError(err)
} }

View File

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"net/url" "net/url"
"os" "os"
@ -1014,12 +1013,12 @@ func expectCommittedAndPushed(conditions []metav1.Condition) {
func replaceMarker(path string, policyKey types.NamespacedName) error { func replaceMarker(path string, policyKey types.NamespacedName) error {
// NB this requires knowledge of what's in the git repo, so a little brittle // NB this requires knowledge of what's in the git repo, so a little brittle
deployment := filepath.Join(path, "deploy.yaml") deployment := filepath.Join(path, "deploy.yaml")
filebytes, err := ioutil.ReadFile(deployment) filebytes, err := os.ReadFile(deployment)
if err != nil { if err != nil {
return err return err
} }
newfilebytes := bytes.ReplaceAll(filebytes, []byte("SETTER_SITE"), []byte(setterRef(policyKey))) 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 err
} }
return nil return nil
@ -1076,13 +1075,13 @@ func waitForNewHead(repo *git.Repository, branch string) {
} }
func compareRepoWithExpected(repoURL, branch, fixture string, changeFixture func(tmp 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()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(expected) defer os.RemoveAll(expected)
copy.Copy(fixture, expected) copy.Copy(fixture, expected)
changeFixture(expected) changeFixture(expected)
tmp, err := ioutil.TempDir("", "gotest-imageauto") tmp, err := os.MkdirTemp("", "gotest-imageauto")
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
_, err = git.PlainClone(tmp, false, &git.CloneOptions{ _, err = git.PlainClone(tmp, false, &git.CloneOptions{
@ -1094,7 +1093,7 @@ func compareRepoWithExpected(repoURL, branch, fixture string, changeFixture func
} }
func commitInRepo(repoURL, branch, msg string, changeFiles func(path string)) { 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()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
repo, err := git.PlainClone(tmp, false, &git.CloneOptions{ repo, err := git.PlainClone(tmp, false, &git.CloneOptions{

View File

@ -17,7 +17,6 @@ limitations under the License.
package test package test
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -124,11 +123,11 @@ func DiffDirectories(actual, expected string) (actualonly []string, expectedonly
// both regular files // both regular files
actualBytes, err := ioutil.ReadFile(actualPath) actualBytes, err := os.ReadFile(actualPath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
expectedBytes, err := ioutil.ReadFile(expectedPath) expectedBytes, err := os.ReadFile(expectedPath)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -19,7 +19,6 @@ package update
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -101,7 +100,7 @@ func (r *ScreeningLocalReader) Read() ([]*yaml.RNode, error) {
// To check for the token, I need the file contents. This // To check for the token, I need the file contents. This
// assumes the file is encoded as UTF8. // assumes the file is encoded as UTF8.
filebytes, err := ioutil.ReadFile(p) filebytes, err := os.ReadFile(p)
if err != nil { if err != nil {
return fmt.Errorf("reading YAML file: %w", err) return fmt.Errorf("reading YAML file: %w", err)
} }

View File

@ -17,7 +17,6 @@ limitations under the License.
package update package update
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -64,7 +63,7 @@ var _ = Describe("Update image via kyaml setters2", func() {
) )
It("updates the image marked with the image policy (setter) ref", 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()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
@ -95,7 +94,7 @@ var _ = Describe("Update image via kyaml setters2", func() {
}) })
It("gives the result of the updates", func() { It("gives the result of the updates", func() {
tmp, err := ioutil.TempDir("", "gotest") tmp, err := os.MkdirTemp("", "gotest")
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)