diff options
author | Eng Zer Jun <engzerjun@gmail.com> | 2021-08-24 18:10:50 +0800 |
---|---|---|
committer | Eng Zer Jun <engzerjun@gmail.com> | 2021-08-27 14:56:57 +0800 |
commit | c55a4ac7795c7606b548b38e24673733481e2167 (patch) | |
tree | 8ea03bdc842959cd3d04a3e37a4ce2a71fa77dbb /integration/plugin | |
parent | 2b70006e3bfa492b8641ff443493983d832955f4 (diff) | |
download | docker-c55a4ac7795c7606b548b38e24673733481e2167.tar.gz |
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>
Diffstat (limited to 'integration/plugin')
-rw-r--r-- | integration/plugin/authz/authz_plugin_test.go | 11 | ||||
-rw-r--r-- | integration/plugin/authz/authz_plugin_v2_test.go | 4 | ||||
-rw-r--r-- | integration/plugin/authz/main_test.go | 6 | ||||
-rw-r--r-- | integration/plugin/common/plugin_test.go | 13 | ||||
-rw-r--r-- | integration/plugin/graphdriver/external_test.go | 9 | ||||
-rw-r--r-- | integration/plugin/logging/cmd/discard/driver.go | 3 | ||||
-rw-r--r-- | integration/plugin/volumes/mounts_test.go | 3 |
7 files changed, 22 insertions, 27 deletions
diff --git a/integration/plugin/authz/authz_plugin_test.go b/integration/plugin/authz/authz_plugin_test.go index 6cce66cd6c..3c8cfc6a65 100644 --- a/integration/plugin/authz/authz_plugin_test.go +++ b/integration/plugin/authz/authz_plugin_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httputil" @@ -61,7 +60,7 @@ func setupTestV1(t *testing.T) func() { assert.NilError(t, err) fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", testAuthZPlugin) - err = ioutil.WriteFile(fileName, []byte(server.URL), 0644) + err = os.WriteFile(fileName, []byte(server.URL), 0644) assert.NilError(t, err) return func() { @@ -336,7 +335,7 @@ func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) { c := d.NewClientT(t) ctx := context.Background() - tmp, err := ioutil.TempDir("", "test-authz-load-import") + tmp, err := os.MkdirTemp("", "test-authz-load-import") assert.NilError(t, err) defer os.RemoveAll(tmp) @@ -370,11 +369,11 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) { ctrl.resRes.Allow = true d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin) - dir, err := ioutil.TempDir("", t.Name()) + dir, err := os.MkdirTemp("", t.Name()) assert.NilError(t, err) defer os.RemoveAll(dir) - f, err := ioutil.TempFile(dir, "send") + f, err := os.CreateTemp(dir, "send") assert.NilError(t, err) defer f.Close() @@ -409,7 +408,7 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) { rdr, _, err := c.CopyFromContainer(ctx, cID, "/test") assert.NilError(t, err) - _, err = io.Copy(ioutil.Discard, rdr) + _, err = io.Copy(io.Discard, rdr) assert.NilError(t, err) } diff --git a/integration/plugin/authz/authz_plugin_v2_test.go b/integration/plugin/authz/authz_plugin_v2_test.go index f567f5a448..173d0a5df6 100644 --- a/integration/plugin/authz/authz_plugin_v2_test.go +++ b/integration/plugin/authz/authz_plugin_v2_test.go @@ -6,7 +6,7 @@ package authz // import "github.com/docker/docker/integration/plugin/authz" import ( "context" "fmt" - "io/ioutil" + "io" "os" "strings" "testing" @@ -166,6 +166,6 @@ func pluginInstallGrantAllPermissions(client client.APIClient, name string) erro // we have to read the response out here because the client API // actually starts a goroutine which we can only be sure has // completed when we get EOF from reading responseBody - _, err = ioutil.ReadAll(responseReader) + _, err = io.ReadAll(responseReader) return err } diff --git a/integration/plugin/authz/main_test.go b/integration/plugin/authz/main_test.go index ff39d61372..b4e6564081 100644 --- a/integration/plugin/authz/main_test.go +++ b/integration/plugin/authz/main_test.go @@ -6,7 +6,7 @@ package authz // import "github.com/docker/docker/integration/plugin/authz" import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -77,7 +77,7 @@ func setupSuite() { mux.HandleFunc("/AuthZPlugin.AuthZReq", func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic("could not read body for /AuthZPlugin.AuthZReq: " + err.Error()) } @@ -115,7 +115,7 @@ func setupSuite() { mux.HandleFunc("/AuthZPlugin.AuthZRes", func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic("could not read body for /AuthZPlugin.AuthZRes: " + err.Error()) } diff --git a/integration/plugin/common/plugin_test.go b/integration/plugin/common/plugin_test.go index 83e060f82e..72b1b8264d 100644 --- a/integration/plugin/common/plugin_test.go +++ b/integration/plugin/common/plugin_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -81,7 +80,7 @@ func TestPluginInstall(t *testing.T) { assert.NilError(t, err) defer rdr.Close() - _, err = io.Copy(ioutil.Discard, rdr) + _, err = io.Copy(io.Discard, rdr) assert.NilError(t, err) _, _, err = client.PluginInspectWithRaw(ctx, repo) @@ -110,7 +109,7 @@ func TestPluginInstall(t *testing.T) { assert.NilError(t, err) defer rdr.Close() - _, err = io.Copy(ioutil.Discard, rdr) + _, err = io.Copy(io.Discard, rdr) assert.NilError(t, err) _, _, err = client.PluginInspectWithRaw(ctx, repo) @@ -158,7 +157,7 @@ func TestPluginInstall(t *testing.T) { assert.NilError(t, err) defer rdr.Close() - _, err = io.Copy(ioutil.Discard, rdr) + _, err = io.Copy(io.Discard, rdr) assert.NilError(t, err) _, _, err = client.PluginInspectWithRaw(ctx, repo) @@ -172,7 +171,7 @@ func TestPluginsWithRuntimes(t *testing.T) { skip.If(t, testEnv.IsRootless, "Test not supported on rootless due to buggy daemon setup in rootless mode due to daemon restart") skip.If(t, testEnv.OSType == "windows") - dir, err := ioutil.TempDir("", t.Name()) + dir, err := os.MkdirTemp("", t.Name()) assert.NilError(t, err) defer os.RemoveAll(dir) @@ -202,7 +201,7 @@ func TestPluginsWithRuntimes(t *testing.T) { exec runc $@ `, dir) - assert.NilError(t, ioutil.WriteFile(p, []byte(script), 0777)) + assert.NilError(t, os.WriteFile(p, []byte(script), 0777)) type config struct { Runtimes map[string]types.Runtime `json:"runtimes"` @@ -215,7 +214,7 @@ func TestPluginsWithRuntimes(t *testing.T) { }, }) configPath := filepath.Join(dir, "config.json") - ioutil.WriteFile(configPath, cfg, 0644) + os.WriteFile(configPath, cfg, 0644) t.Run("No Args", func(t *testing.T) { d.Restart(t, "--default-runtime=myrt", "--config-file="+configPath) diff --git a/integration/plugin/graphdriver/external_test.go b/integration/plugin/graphdriver/external_test.go index 87ce1b82d7..57fb27856d 100644 --- a/integration/plugin/graphdriver/external_test.go +++ b/integration/plugin/graphdriver/external_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -145,7 +144,7 @@ func setupPlugin(t *testing.T, ec map[string]*graphEventsCounter, ext string, mu return nil } - base, err := ioutil.TempDir("", name) + base, err := os.MkdirTemp("", name) assert.NilError(t, err) vfsProto, err := vfs.Init(base, []string{}, nil, nil) assert.NilError(t, err, "error initializing graph driver") @@ -349,7 +348,7 @@ func setupPlugin(t *testing.T, ec map[string]*graphEventsCounter, ext string, mu assert.NilError(t, err) specFile := "/etc/docker/plugins/" + name + "." + ext - err = ioutil.WriteFile(specFile, b, 0644) + err = os.WriteFile(specFile, b, 0644) assert.NilError(t, err) } @@ -397,7 +396,7 @@ func testGraphDriverPull(c client.APIClient, d *daemon.Daemon) func(*testing.T) r, err := c.ImagePull(ctx, "busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209", types.ImagePullOptions{}) assert.NilError(t, err) - _, err = io.Copy(ioutil.Discard, r) + _, err = io.Copy(io.Discard, r) assert.NilError(t, err) container.Run(ctx, t, c, container.WithImage("busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209")) @@ -428,7 +427,7 @@ func TestGraphdriverPluginV2(t *testing.T) { assert.NilError(t, err) defer responseReader.Close() // ensure it's done by waiting for EOF on the response - _, err = io.Copy(ioutil.Discard, responseReader) + _, err = io.Copy(io.Discard, responseReader) assert.NilError(t, err) // restart the daemon with the plugin set as the storage driver diff --git a/integration/plugin/logging/cmd/discard/driver.go b/integration/plugin/logging/cmd/discard/driver.go index e02b56e88f..bbdebaf443 100644 --- a/integration/plugin/logging/cmd/discard/driver.go +++ b/integration/plugin/logging/cmd/discard/driver.go @@ -3,7 +3,6 @@ package main import ( "encoding/json" "io" - "io/ioutil" "net/http" "os" "sync" @@ -47,7 +46,7 @@ func handle(mux *http.ServeMux) { d.logs[req.File] = f d.mu.Unlock() - go io.Copy(ioutil.Discard, f) + go io.Copy(io.Discard, f) respond(err, w) }) diff --git a/integration/plugin/volumes/mounts_test.go b/integration/plugin/volumes/mounts_test.go index 991b1e1105..c80c4cd79c 100644 --- a/integration/plugin/volumes/mounts_test.go +++ b/integration/plugin/volumes/mounts_test.go @@ -2,7 +2,6 @@ package volumes import ( "context" - "io/ioutil" "os" "testing" @@ -28,7 +27,7 @@ func TestPluginWithDevMounts(t *testing.T) { c := d.NewClientT(t) ctx := context.Background() - testDir, err := ioutil.TempDir("", "test-dir") + testDir, err := os.MkdirTemp("", "test-dir") assert.NilError(t, err) defer os.RemoveAll(testDir) |