Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <[email protected]>
  • Loading branch information
testwill committed Aug 31, 2023
1 parent 3340aa2 commit 8078d45
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cmd/check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -163,7 +163,7 @@ func fetchDigest(client *http.Client, manifestURL, repository, tag string) (stri

ctHeader := manifestResponse.Header.Get("Content-Type")

bytes, err := ioutil.ReadAll(manifestResponse.Body)
bytes, err := io.ReadAll(manifestResponse.Body)
fatalIf("failed to read response body", err)

_, desc, err := distribution.UnmarshalManifest(ctHeader, bytes)
Expand Down
3 changes: 1 addition & 2 deletions cmd/print-metadata/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -41,7 +40,7 @@ var _ = Describe("print-metadata", func() {
Context("when user file exists", func() {
BeforeEach(func() {
var err error
userFile, err = ioutil.TempFile("", "print-metadata-test")
userFile, err = os.CreateTemp("", "print-metadata-test")
Expect(err).NotTo(HaveOccurred())

cmd = exec.Command(printMetadataPath, "-userFile", userFile.Name())
Expand Down
5 changes: 2 additions & 3 deletions cmd/print-metadata/passwd/passwd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package passwd_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -26,7 +25,7 @@ var _ = Describe("Passwd", func() {
})

JustBeforeEach(func() {
path, err := ioutil.TempDir("", "passwd")
path, err := os.MkdirTemp("", "passwd")
Expect(err).ToNot(HaveOccurred())

etcPasswdDir = path
Expand All @@ -36,7 +35,7 @@ var _ = Describe("Passwd", func() {
etcPasswdContents += fmt.Sprintf("%s:*:%d:1:User Name:/dev/null:/usr/bin/false\n", user.Username, user.ID)
}

err = ioutil.WriteFile(etcPasswdPath, []byte(etcPasswdContents), 0600)
err = os.WriteFile(etcPasswdPath, []byte(etcPasswdContents), 0600)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
41 changes: 20 additions & 21 deletions tests/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package docker_image_resource_test
import (
"bytes"
"fmt"
"io/ioutil"
"os/exec"

"encoding/json"
Expand Down Expand Up @@ -529,22 +528,22 @@ var _ = Describe("Out", func() {
BeforeEach(func() {
os.Mkdir("/tmp/expected_base_1", os.ModeDir)
// this image should really be an actual tarball, but the test passes with text. :shrug:
ioutil.WriteFile("/tmp/expected_base_1/image", []byte("some-image-1"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_1/repository", []byte("some-repository-1"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_1/image-id", []byte("some-image-id-1"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_1/tag", []byte("some-tag-1"), os.ModePerm)
os.WriteFile("/tmp/expected_base_1/image", []byte("some-image-1"), os.ModePerm)
os.WriteFile("/tmp/expected_base_1/repository", []byte("some-repository-1"), os.ModePerm)
os.WriteFile("/tmp/expected_base_1/image-id", []byte("some-image-id-1"), os.ModePerm)
os.WriteFile("/tmp/expected_base_1/tag", []byte("some-tag-1"), os.ModePerm)

os.Mkdir("/tmp/expected_base_2", os.ModeDir)
ioutil.WriteFile("/tmp/expected_base_2/image", []byte("some-image-2"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_2/repository", []byte("some-repository-2"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_2/image-id", []byte("some-image-id-2"), os.ModePerm)
ioutil.WriteFile("/tmp/expected_base_2/tag", []byte("some-tag-2"), os.ModePerm)
os.WriteFile("/tmp/expected_base_2/image", []byte("some-image-2"), os.ModePerm)
os.WriteFile("/tmp/expected_base_2/repository", []byte("some-repository-2"), os.ModePerm)
os.WriteFile("/tmp/expected_base_2/image-id", []byte("some-image-id-2"), os.ModePerm)
os.WriteFile("/tmp/expected_base_2/tag", []byte("some-tag-2"), os.ModePerm)

os.Mkdir("/tmp/unexpected_base", os.ModeDir)
ioutil.WriteFile("/tmp/unexpected_base/image", []byte("some-image-3"), os.ModePerm)
ioutil.WriteFile("/tmp/unexpected_base/repository", []byte("some-repository-3"), os.ModePerm)
ioutil.WriteFile("/tmp/unexpected_base/image-id", []byte("some-image-id-3"), os.ModePerm)
ioutil.WriteFile("/tmp/unexpected_base/tag", []byte("some-tag-3"), os.ModePerm)
os.WriteFile("/tmp/unexpected_base/image", []byte("some-image-3"), os.ModePerm)
os.WriteFile("/tmp/unexpected_base/repository", []byte("some-repository-3"), os.ModePerm)
os.WriteFile("/tmp/unexpected_base/image-id", []byte("some-image-id-3"), os.ModePerm)
os.WriteFile("/tmp/unexpected_base/tag", []byte("some-tag-3"), os.ModePerm)
})

AfterEach(func() {
Expand Down Expand Up @@ -612,16 +611,16 @@ var _ = Describe("Out", func() {
BeforeEach(func() {
os.Mkdir("/tmp/cache_from_1", os.ModeDir)
// this image should really be an actual tarball, but the test passes with text. :shrug:
ioutil.WriteFile("/tmp/cache_from_1/image", []byte("some-image-1"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_1/repository", []byte("some-repository-1"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_1/image-id", []byte("some-image-id-1"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_1/tag", []byte("some-tag-1"), os.ModePerm)
os.WriteFile("/tmp/cache_from_1/image", []byte("some-image-1"), os.ModePerm)
os.WriteFile("/tmp/cache_from_1/repository", []byte("some-repository-1"), os.ModePerm)
os.WriteFile("/tmp/cache_from_1/image-id", []byte("some-image-id-1"), os.ModePerm)
os.WriteFile("/tmp/cache_from_1/tag", []byte("some-tag-1"), os.ModePerm)

os.Mkdir("/tmp/cache_from_2", os.ModeDir)
ioutil.WriteFile("/tmp/cache_from_2/image", []byte("some-image-2"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_2/repository", []byte("some-repository-2"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_2/image-id", []byte("some-image-id-2"), os.ModePerm)
ioutil.WriteFile("/tmp/cache_from_2/tag", []byte("some-tag-2"), os.ModePerm)
os.WriteFile("/tmp/cache_from_2/image", []byte("some-image-2"), os.ModePerm)
os.WriteFile("/tmp/cache_from_2/repository", []byte("some-repository-2"), os.ModePerm)
os.WriteFile("/tmp/cache_from_2/image-id", []byte("some-image-id-2"), os.ModePerm)
os.WriteFile("/tmp/cache_from_2/tag", []byte("some-tag-2"), os.ModePerm)
})

AfterEach(func() {
Expand Down

0 comments on commit 8078d45

Please sign in to comment.