From 9a5d49774ec97a5e57e860d4f519aac79aaab18d Mon Sep 17 00:00:00 2001 From: nichady <57887348+nichady@users.noreply.github.com> Date: Mon, 20 Dec 2021 20:00:34 -0600 Subject: [PATCH] replace usages of ioutil with io and os --- init.go | 3 +- internal/status/checksum.go | 5 ++-- task_test.go | 56 ++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/init.go b/init.go index 642a326c..1c1d043f 100644 --- a/init.go +++ b/init.go @@ -3,7 +3,6 @@ package task import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" ) @@ -30,7 +29,7 @@ func InitTaskfile(w io.Writer, dir string) error { return ErrTaskfileAlreadyExists } - if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil { + if err := os.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil { return err } fmt.Fprintf(w, "Taskfile.yml created in the current directory\n") diff --git a/internal/status/checksum.go b/internal/status/checksum.go index 2ab6a9ff..ab608a8d 100644 --- a/internal/status/checksum.go +++ b/internal/status/checksum.go @@ -4,7 +4,6 @@ import ( "crypto/md5" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -30,7 +29,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { checksumFile := c.checksumFilePath() - data, _ := ioutil.ReadFile(checksumFile) + data, _ := os.ReadFile(checksumFile) oldMd5 := strings.TrimSpace(string(data)) sources, err := globs(c.TaskDir, c.Sources) @@ -45,7 +44,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { if !c.Dry { _ = os.MkdirAll(filepath.Join(c.BaseDir, ".task", "checksum"), 0755) - if err = ioutil.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil { + if err = os.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil { return false, err } } diff --git a/task_test.go b/task_test.go index 97558950..db83a851 100644 --- a/task_test.go +++ b/task_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "runtime" @@ -41,15 +41,15 @@ func (fct fileContentTest) Run(t *testing.T) { e := &task.Executor{ Dir: fct.Dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup(), "e.Setup()") assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: fct.Target}), "e.Run(target)") for name, expectContent := range fct.Files { t.Run(fct.name(name), func(t *testing.T) { - b, err := ioutil.ReadFile(filepath.Join(fct.Dir, name)) + b, err := os.ReadFile(filepath.Join(fct.Dir, name)) assert.NoError(t, err, "Error reading file") s := string(b) if fct.TrimSpace { @@ -63,8 +63,8 @@ func (fct fileContentTest) Run(t *testing.T) { func TestEmptyTask(t *testing.T) { e := &task.Executor{ Dir: "testdata/empty_task", - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup(), "e.Setup()") assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"})) @@ -168,8 +168,8 @@ func TestVarsInvalidTmpl(t *testing.T) { e := &task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup(), "e.Setup()") assert.EqualError(t, e.Run(context.Background(), taskfile.Call{Task: target}), expectError, "e.Run(target)") @@ -183,8 +183,8 @@ func TestConcurrency(t *testing.T) { e := &task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, Concurrency: 1, } assert.NoError(t, e.Setup(), "e.Setup()") @@ -236,8 +236,8 @@ func TestDeps(t *testing.T) { e := &task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"})) @@ -557,7 +557,7 @@ func TestInit(t *testing.T) { t.Errorf("Taskfile.yml should not exist") } - if err := task.InitTaskfile(ioutil.Discard, dir); err != nil { + if err := task.InitTaskfile(io.Discard, dir); err != nil { t.Error(err) } @@ -571,8 +571,8 @@ func TestCyclicDep(t *testing.T) { e := task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup()) assert.IsType(t, &task.MaximumTaskCallExceededError{}, e.Run(context.Background(), taskfile.Call{Task: "task-1"})) @@ -590,8 +590,8 @@ func TestTaskVersion(t *testing.T) { t.Run(test.Dir, func(t *testing.T) { e := task.Executor{ Dir: test.Dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup()) assert.Equal(t, test.Version, e.Taskfile.Version) @@ -605,8 +605,8 @@ func TestTaskIgnoreErrors(t *testing.T) { e := task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } assert.NoError(t, e.Setup()) @@ -668,8 +668,8 @@ func TestDryChecksum(t *testing.T) { e := task.Executor{ Dir: dir, - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, Dry: true, } assert.NoError(t, e.Setup()) @@ -769,8 +769,8 @@ func TestIncludesOptional(t *testing.T) { func TestIncludesOptionalImplicitFalse(t *testing.T) { e := task.Executor{ Dir: "testdata/includes_optional_implicit_false", - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } err := e.Setup() @@ -781,8 +781,8 @@ func TestIncludesOptionalImplicitFalse(t *testing.T) { func TestIncludesOptionalExplicitFalse(t *testing.T) { e := task.Executor{ Dir: "testdata/includes_optional_explicit_false", - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } err := e.Setup() @@ -804,7 +804,7 @@ func TestSummary(t *testing.T) { assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}, taskfile.Call{Task: "other-task-with-summary"})) - data, err := ioutil.ReadFile(filepath.Join(dir, "task-with-summary.txt")) + data, err := os.ReadFile(filepath.Join(dir, "task-with-summary.txt")) assert.NoError(t, err) expectedOutput := string(data) @@ -895,8 +895,8 @@ func TestDynamicVariablesShouldRunOnTheTaskDir(t *testing.T) { func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) { e := task.Executor{ Dir: "testdata/version/v1", - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, + Stdout: io.Discard, + Stderr: io.Discard, } err := e.Setup() assert.Error(t, err)