refactor: move from io/ioutil to io and os package (#1245)

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2021-09-29 15:17:02 +08:00
committed by GitHub
parent 6bcb4af10f
commit bbcce9f7b7
13 changed files with 42 additions and 52 deletions

View File

@@ -4,7 +4,7 @@
package integration
import (
"io/ioutil"
"io"
"os"
"strings"
"testing"
@@ -377,7 +377,7 @@ func TestRun_WithTar(t *testing.T) {
// Setup CLI App
app := commands.NewApp("dev")
app.Writer = ioutil.Discard
app.Writer = io.Discard
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
@@ -402,7 +402,7 @@ func TestRun_WithTar(t *testing.T) {
}
if len(c.testArgs.IgnoreIDs) != 0 {
trivyIgnore := ".trivyignore"
err := ioutil.WriteFile(trivyIgnore, []byte(strings.Join(c.testArgs.IgnoreIDs, "\n")), 0444)
err := os.WriteFile(trivyIgnore, []byte(strings.Join(c.testArgs.IgnoreIDs, "\n")), 0444)
assert.NoError(t, err, "failed to write .trivyignore")
defer os.Remove(trivyIgnore)
}
@@ -427,7 +427,7 @@ func TestRun_WithTar(t *testing.T) {
if *update {
outputFile = c.golden
} else {
output, _ := ioutil.TempFile("", "integration")
output, _ := os.CreateTemp("", "integration")
assert.Nil(t, output.Close())
defer os.Remove(output.Name())
outputFile = output.Name()
@@ -439,9 +439,9 @@ func TestRun_WithTar(t *testing.T) {
assert.Nil(t, app.Run(osArgs))
// Compare want and got
want, err := ioutil.ReadFile(c.golden)
want, err := os.ReadFile(c.golden)
assert.NoError(t, err)
got, err := ioutil.ReadFile(outputFile)
got, err := os.ReadFile(outputFile)
assert.NoError(t, err)
assert.JSONEq(t, string(want), string(got))