refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated in Go 1.16. 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-08-24 18:10:50 +08:00
parent 2b70006e3b
commit c55a4ac779
397 changed files with 1371 additions and 1606 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -29,20 +28,20 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
tmp, err := ioutil.TempDir("", "integration-cli-")
tmp, err := os.MkdirTemp("", "integration-cli-")
assert.NilError(c, err)
defer os.RemoveAll(tmp)
externalAuthConfig := `{ "credsStore": "shell-test" }`
configPath := filepath.Join(tmp, "config.json")
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
err = os.WriteFile(configPath, []byte(externalAuthConfig), 0644)
assert.NilError(c, err)
_, err = s.d.Cmd("--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
assert.NilError(c, err)
b, err := ioutil.ReadFile(configPath)
b, err := os.ReadFile(configPath)
assert.NilError(c, err)
assert.Assert(c, !strings.Contains(string(b), `"auth":`))
assert.Assert(c, strings.Contains(string(b), privateRegistryURL))
@@ -54,7 +53,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
_, err = s.d.Cmd("--config", tmp, "logout", privateRegistryURL)
assert.NilError(c, err)
b, err = ioutil.ReadFile(configPath)
b, err = os.ReadFile(configPath)
assert.NilError(c, err)
assert.Assert(c, !strings.Contains(string(b), privateRegistryURL))
@@ -82,25 +81,25 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *
cmd.Stdin = stdin
assert.NilError(c, cmd.Run())
tmp, err := ioutil.TempDir("", "integration-cli-")
tmp, err := os.MkdirTemp("", "integration-cli-")
assert.NilError(c, err)
externalAuthConfig := fmt.Sprintf(`{ "auths": {"https://%s": {}}, "credsStore": "shell-test" }`, privateRegistryURL)
configPath := filepath.Join(tmp, "config.json")
err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
err = os.WriteFile(configPath, []byte(externalAuthConfig), 0644)
assert.NilError(c, err)
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
b, err := ioutil.ReadFile(configPath)
b, err := os.ReadFile(configPath)
assert.NilError(c, err)
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
b, err = ioutil.ReadFile(configPath)
b, err = os.ReadFile(configPath)
assert.NilError(c, err)
assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))