From 7c6baba23bd8fb4172e6b601f86e6c72856df95e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Feb 2022 14:31:31 +0100 Subject: [PATCH] cli/command/stack: remove deprecated io/ioutil Signed-off-by: Sebastiaan van Stijn (cherry picked from commit d59330f40d0dd95dff6f6c64f12824089c01065d) Signed-off-by: Cory Snider --- cli/command/stack/deploy_test.go | 4 ++-- cli/command/stack/kubernetes/convert.go | 3 +-- cli/command/stack/kubernetes/convert_test.go | 13 +++++++------ cli/command/stack/kubernetes/list.go | 4 ++-- cli/command/stack/kubernetes/stack.go | 6 +++--- cli/command/stack/kubernetes/stackclient_test.go | 6 +++--- cli/command/stack/list_test.go | 4 ++-- cli/command/stack/loader/loader.go | 5 ++--- cli/command/stack/ps_test.go | 6 +++--- cli/command/stack/remove_test.go | 6 +++--- cli/command/stack/services_test.go | 6 +++--- 11 files changed, 31 insertions(+), 32 deletions(-) diff --git a/cli/command/stack/deploy_test.go b/cli/command/stack/deploy_test.go index cc27e12f68..a8f88d5120 100644 --- a/cli/command/stack/deploy_test.go +++ b/cli/command/stack/deploy_test.go @@ -1,7 +1,7 @@ package stack import ( - "io/ioutil" + "io" "testing" "github.com/docker/cli/internal/test" @@ -11,7 +11,7 @@ import ( func TestDeployWithEmptyName(t *testing.T) { cmd := newDeployCommand(test.NewFakeCli(&fakeClient{}), nil) cmd.SetArgs([]string{"' '"}) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), `invalid stack name: "' '"`) } diff --git a/cli/command/stack/kubernetes/convert.go b/cli/command/stack/kubernetes/convert.go index 60c2c88447..aa66e16b9b 100644 --- a/cli/command/stack/kubernetes/convert.go +++ b/cli/command/stack/kubernetes/convert.go @@ -2,7 +2,6 @@ package kubernetes import ( "io" - "io/ioutil" "regexp" "strconv" "strings" @@ -115,7 +114,7 @@ func stackFromV1beta1(in *v1beta1.Stack) (Stack, error) { if err != nil { return Stack{}, err } - spec, err := fromComposeConfig(ioutil.Discard, cfg, v1beta1Capabilities) + spec, err := fromComposeConfig(io.Discard, cfg, v1beta1Capabilities) if err != nil { return Stack{}, err } diff --git a/cli/command/stack/kubernetes/convert_test.go b/cli/command/stack/kubernetes/convert_test.go index aaab4eb812..868a919a40 100644 --- a/cli/command/stack/kubernetes/convert_test.go +++ b/cli/command/stack/kubernetes/convert_test.go @@ -2,7 +2,8 @@ package kubernetes import ( "fmt" - "io/ioutil" + "io" + "os" "path/filepath" "testing" @@ -170,7 +171,7 @@ func TestConvertFromToV1alpha3(t *testing.T) { func loadTestStackWith(t *testing.T, with string) *composetypes.Config { t.Helper() filePath := fmt.Sprintf("testdata/compose-with-%s.yml", with) - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) assert.NilError(t, err) yamlData, err := loader.ParseYAML(data) assert.NilError(t, err) @@ -199,7 +200,7 @@ func TestHandlePullSecret(t *testing.T) { t.Run(c.version, func(t *testing.T) { conv, err := NewStackConverter(c.version) assert.NilError(t, err) - s, err := conv.FromCompose(ioutil.Discard, "test", testData) + s, err := conv.FromCompose(io.Discard, "test", testData) if c.err != "" { assert.Error(t, err, c.err) @@ -227,7 +228,7 @@ func TestHandlePullPolicy(t *testing.T) { t.Run(c.version, func(t *testing.T) { conv, err := NewStackConverter(c.version) assert.NilError(t, err) - s, err := conv.FromCompose(ioutil.Discard, "test", testData) + s, err := conv.FromCompose(io.Discard, "test", testData) if c.err != "" { assert.Error(t, err, c.err) @@ -299,7 +300,7 @@ func TestIgnoreExpose(t *testing.T) { for _, version := range []string{"v1beta1", "v1beta2"} { conv, err := NewStackConverter(version) assert.NilError(t, err) - s, err := conv.FromCompose(ioutil.Discard, "test", testData) + s, err := conv.FromCompose(io.Discard, "test", testData) assert.NilError(t, err) assert.Equal(t, len(s.Spec.Services[0].InternalPorts), 0) } @@ -309,7 +310,7 @@ func TestParseExpose(t *testing.T) { testData := loadTestStackWith(t, "expose") conv, err := NewStackConverter("v1alpha3") assert.NilError(t, err) - s, err := conv.FromCompose(ioutil.Discard, "test", testData) + s, err := conv.FromCompose(io.Discard, "test", testData) assert.NilError(t, err) expected := []v1alpha3.InternalPort{ { diff --git a/cli/command/stack/kubernetes/list.go b/cli/command/stack/kubernetes/list.go index facd401bb9..ea176019e0 100644 --- a/cli/command/stack/kubernetes/list.go +++ b/cli/command/stack/kubernetes/list.go @@ -3,7 +3,7 @@ package kubernetes import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -87,7 +87,7 @@ func getUserVisibleNamespaces(dockerCli command.Cli) ([]string, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, errors.Wrapf(err, "received %d status and unable to read response", resp.StatusCode) } diff --git a/cli/command/stack/kubernetes/stack.go b/cli/command/stack/kubernetes/stack.go index e368d718de..8c304d65b5 100644 --- a/cli/command/stack/kubernetes/stack.go +++ b/cli/command/stack/kubernetes/stack.go @@ -1,7 +1,7 @@ package kubernetes import ( - "io/ioutil" + "os" "path/filepath" "sort" @@ -59,7 +59,7 @@ func (s *Stack) createFileBasedConfigMaps(configMaps corev1.ConfigMapInterface) } fileName := filepath.Base(config.File) - content, err := ioutil.ReadFile(config.File) + content, err := os.ReadFile(config.File) if err != nil { return resources, err } @@ -116,7 +116,7 @@ func (s *Stack) createFileBasedSecrets(secrets corev1.SecretInterface) ([]childR } fileName := filepath.Base(secret.File) - content, err := ioutil.ReadFile(secret.File) + content, err := os.ReadFile(secret.File) if err != nil { return resources, err } diff --git a/cli/command/stack/kubernetes/stackclient_test.go b/cli/command/stack/kubernetes/stackclient_test.go index 354d8c3897..18c27b5760 100644 --- a/cli/command/stack/kubernetes/stackclient_test.go +++ b/cli/command/stack/kubernetes/stackclient_test.go @@ -1,7 +1,7 @@ package kubernetes import ( - "io/ioutil" + "io" "testing" composetypes "github.com/docker/cli/cli/compose/types" @@ -10,7 +10,7 @@ import ( func TestFromCompose(t *testing.T) { stackClient := &stackV1Beta1{} - s, err := stackClient.FromCompose(ioutil.Discard, "foo", &composetypes.Config{ + s, err := stackClient.FromCompose(io.Discard, "foo", &composetypes.Config{ Version: "3.1", Filename: "banana", Services: []composetypes.ServiceConfig{ @@ -37,7 +37,7 @@ services: func TestFromComposeUnsupportedVersion(t *testing.T) { stackClient := &stackV1Beta1{} - _, err := stackClient.FromCompose(ioutil.Discard, "foo", &composetypes.Config{ + _, err := stackClient.FromCompose(io.Discard, "foo", &composetypes.Config{ Version: "3.6", Filename: "banana", Services: []composetypes.ServiceConfig{ diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index e9c653329a..c2bcee8e1f 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -1,7 +1,7 @@ package stack import ( - "io/ioutil" + "io" "testing" "github.com/docker/cli/cli/command" @@ -54,7 +54,7 @@ func TestListErrors(t *testing.T) { serviceListFunc: tc.serviceListFunc, }), &orchestrator) cmd.SetArgs(tc.args) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) for key, value := range tc.flags { cmd.Flags().Set(key, value) } diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader/loader.go index 0874d6bf6b..a61efc7bd7 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -3,7 +3,6 @@ package loader import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "sort" @@ -133,9 +132,9 @@ func loadConfigFile(filename string, stdin io.Reader) (*composetypes.ConfigFile, var err error if filename == "-" { - bytes, err = ioutil.ReadAll(stdin) + bytes, err = io.ReadAll(stdin) } else { - bytes, err = ioutil.ReadFile(filename) + bytes, err = os.ReadFile(filename) } if err != nil { return nil, err diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 58a651252b..d93ebc19d9 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -1,7 +1,7 @@ package stack import ( - "io/ioutil" + "io" "testing" "time" @@ -45,7 +45,7 @@ func TestStackPsErrors(t *testing.T) { taskListFunc: tc.taskListFunc, }), &orchestrator) cmd.SetArgs(tc.args) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -169,7 +169,7 @@ func TestStackPs(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) if tc.expectedErr != "" { assert.Error(t, cmd.Execute(), tc.expectedErr) diff --git a/cli/command/stack/remove_test.go b/cli/command/stack/remove_test.go index 0f10c55b24..f533a94339 100644 --- a/cli/command/stack/remove_test.go +++ b/cli/command/stack/remove_test.go @@ -2,7 +2,7 @@ package stack import ( "errors" - "io/ioutil" + "io" "strings" "testing" @@ -44,7 +44,7 @@ func fakeClientForRemoveStackTest(version string) *fakeClient { func TestRemoveWithEmptyName(t *testing.T) { cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}), &orchestrator) cmd.SetArgs([]string{"good", "' '", "alsogood"}) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), `invalid stack name: "' '"`) } @@ -155,7 +155,7 @@ func TestRemoveContinueAfterError(t *testing.T) { }, } cmd := newRemoveCommand(test.NewFakeCli(cli), &orchestrator) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) cmd.SetArgs([]string{"foo", "bar"}) assert.Error(t, cmd.Execute(), "Failed to remove some resources from stack: foo") diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index 1962dd245f..42fcb3c7c4 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -1,7 +1,7 @@ package stack import ( - "io/ioutil" + "io" "testing" "github.com/docker/cli/cli/config/configfile" @@ -79,7 +79,7 @@ func TestStackServicesErrors(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) }) } @@ -88,7 +88,7 @@ func TestStackServicesErrors(t *testing.T) { func TestRunServicesWithEmptyName(t *testing.T) { cmd := newServicesCommand(test.NewFakeCli(&fakeClient{}), &orchestrator) cmd.SetArgs([]string{"' '"}) - cmd.SetOut(ioutil.Discard) + cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), `invalid stack name: "' '"`) }