Replaced deprecated io/ioutil functions (#768)

Signed-off-by: slab713 <109306207+slab713@users.noreply.github.com>
This commit is contained in:
slab713
2022-09-02 14:56:02 +02:00
committed by GitHub
parent 6ae793eb51
commit 8ffb053cec
36 changed files with 249 additions and 280 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
"os/exec"
@@ -157,7 +157,7 @@ func signUsingCosign(port string) error {
defer func() { _ = os.Chdir(cwd) }()
tdir, err := ioutil.TempDir("", "cosign")
tdir, err := os.MkdirTemp("", "cosign")
if err != nil {
return err
}
@@ -194,7 +194,7 @@ func signUsingNotary(port string) error {
defer func() { _ = os.Chdir(cwd) }()
tdir, err := ioutil.TempDir("", "notation")
tdir, err := os.MkdirTemp("", "notation")
if err != nil {
return err
}
@@ -653,7 +653,7 @@ func TestExpandedRepoInfo(t *testing.T) {
indexPath := path.Join(tempDir, repo1, "index.json")
indexFile, err := os.Open(indexPath)
So(err, ShouldBeNil)
buf, err := ioutil.ReadAll(indexFile)
buf, err := io.ReadAll(indexFile)
So(err, ShouldBeNil)
var index ispec.Index
+6 -7
View File
@@ -8,7 +8,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
@@ -75,7 +74,7 @@ type CVE struct {
}
func testSetup() error {
dir, err := ioutil.TempDir("", "util_test")
dir, err := os.MkdirTemp("", "util_test")
if err != nil {
return err
}
@@ -128,7 +127,7 @@ func generateTestData() error { // nolint: gocyclo
return err
}
if err = ioutil.WriteFile(path.Join(dbDir, "zot-nonreadable-test", "index.json"), buf, 0o111); err != nil {
if err = os.WriteFile(path.Join(dbDir, "zot-nonreadable-test", "index.json"), buf, 0o111); err != nil {
return err
}
@@ -194,7 +193,7 @@ func generateTestData() error { // nolint: gocyclo
return err
}
if err = ioutil.WriteFile(path.Join(dbDir, "zot-squashfs-test", "oci-layout"), buf, 0o644); err != nil { //nolint: gosec
if err = os.WriteFile(path.Join(dbDir, "zot-squashfs-test", "oci-layout"), buf, 0o644); err != nil { //nolint: gosec
return err
}
@@ -312,7 +311,7 @@ func generateTestData() error { // nolint: gocyclo
}
func makeTestFile(fileName, content string) error {
if err := ioutil.WriteFile(fileName, []byte(content), 0o600); err != nil {
if err := os.WriteFile(fileName, []byte(content), 0o600); err != nil {
panic(err)
}
@@ -680,12 +679,12 @@ func TestHTTPOptionsResponse(t *testing.T) {
ctlr := api.NewController(conf)
firstDir, err := ioutil.TempDir("", "oci-repo-test")
firstDir, err := os.MkdirTemp("", "oci-repo-test")
if err != nil {
panic(err)
}
secondDir, err := ioutil.TempDir("", "oci-repo-test")
secondDir, err := os.MkdirTemp("", "oci-repo-test")
if err != nil {
panic(err)
}
+3 -4
View File
@@ -7,7 +7,6 @@ package digestinfo_test
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"
"time"
@@ -63,12 +62,12 @@ func init() {
}
func testSetup() error {
dir, err := ioutil.TempDir("", "digest_test")
dir, err := os.MkdirTemp("", "digest_test")
if err != nil {
return err
}
subDir, err := ioutil.TempDir("", "sub_digest_test")
subDir, err := os.MkdirTemp("", "sub_digest_test")
if err != nil {
return err
}
@@ -305,7 +304,7 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
ctlr := api.NewController(conf)
globalDir, err := ioutil.TempDir("", "digest_test")
globalDir, err := os.MkdirTemp("", "digest_test")
if err != nil {
panic(err)
}