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

@@ -9,7 +9,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@@ -236,7 +236,7 @@ func scan(t *testing.T, imageRef name.Reference, baseDir, goldenFile string, opt
if *update && goldenFile != "" {
outputFile = goldenFile
} else {
output, err := ioutil.TempFile("", "integration")
output, err := os.CreateTemp("", "integration")
if err != nil {
return "", cleanup, err
}
@@ -256,7 +256,7 @@ func scan(t *testing.T, imageRef name.Reference, baseDir, goldenFile string, opt
// Setup CLI App
app := commands.NewApp("dev")
app.Writer = ioutil.Discard
app.Writer = io.Discard
osArgs := []string{"trivy", "--cache-dir", cacheDir, "--format", "json", "--skip-update", "--output", outputFile, imageRef.Name()}
@@ -306,7 +306,7 @@ func unsetEnv() error {
func requestRegistryToken(imageRef name.Reference, baseDir string, opt registryOption) (string, error) {
// Create a CA certificate pool and add cert.pem to it
caCert, err := ioutil.ReadFile(filepath.Join(baseDir, "data", "certs", "cert.pem"))
caCert, err := os.ReadFile(filepath.Join(baseDir, "data", "certs", "cert.pem"))
if err != nil {
return "", err
}