Merge pull request #267 from fluxcd/replace-ioutils
Remove deprecated `io/ioutil`
This commit is contained in:
commit
fbf889ef80
|
@ -2,7 +2,6 @@ package controllers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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{
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package update
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package update
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"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() {
|
||||
tmp, err := ioutil.TempDir("", "gotest")
|
||||
tmp, err := os.MkdirTemp("", "gotest")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue