cli/command/container: remove deprecated io/ioutil

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-25 13:05:59 +01:00
parent bc1790c5c2
commit e946bf0804
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
13 changed files with 30 additions and 34 deletions

View File

@ -2,7 +2,7 @@ package container
import (
"fmt"
"io/ioutil"
"io"
"testing"
"github.com/docker/cli/cli"
@ -71,7 +71,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
}
for _, tc := range testCases {
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}

View File

@ -2,7 +2,6 @@ package container
import (
"io"
"io/ioutil"
"os"
"runtime"
"strings"
@ -54,7 +53,7 @@ func TestRunCopyFromContainerToStdout(t *testing.T) {
fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Check(t, is.Equal("container", container))
return ioutil.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
return io.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
},
}
options := copyOptions{source: "container:/path", destination: "-"}
@ -84,7 +83,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
assert.Check(t, is.Equal("", cli.OutBuffer().String()))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
content, err := ioutil.ReadFile(destDir.Join("file1"))
content, err := os.ReadFile(destDir.Join("file1"))
assert.NilError(t, err)
assert.Check(t, is.Equal("content\n", string(content)))
}

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"sort"
@ -67,7 +66,7 @@ func TestCIDFileCloseWithWrite(t *testing.T) {
content := "id"
assert.NilError(t, file.Write(content))
actual, err := ioutil.ReadFile(path)
actual, err := os.ReadFile(path)
assert.NilError(t, err)
assert.Check(t, is.Equal(content, string(actual)))
@ -130,7 +129,7 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
},
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
defer func() { pullCounter++ }()
return ioutil.NopCloser(strings.NewReader("")), nil
return io.NopCloser(strings.NewReader("")), nil
},
infoFunc: func() (types.Info, error) {
return types.Info{IndexServerAddress: "https://indexserver.example.com"}, nil
@ -194,7 +193,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
}, test.EnableContentTrust)
cli.SetNotaryClient(tc.notaryFunc)
cmd := NewCreateCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.ErrorContains(t, err, tc.expectedError)
@ -254,7 +253,7 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
},
})
cmd := NewCreateCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
err := cmd.Execute()
assert.NilError(t, err)
@ -306,7 +305,7 @@ func TestCreateContainerWithProxyConfig(t *testing.T) {
},
})
cmd := NewCreateCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"image:tag"})
err := cmd.Execute()
assert.NilError(t, err)

View File

@ -2,7 +2,7 @@ package container
import (
"context"
"io/ioutil"
"io"
"os"
"testing"
@ -267,7 +267,7 @@ func TestNewExecCommandErrors(t *testing.T) {
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc})
cmd := NewExecCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}

View File

@ -2,7 +2,6 @@ package container
import (
"io"
"io/ioutil"
"strings"
"testing"
@ -17,11 +16,11 @@ func TestContainerExportOutputToFile(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
containerExportFunc: func(container string) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("bar")), nil
return io.NopCloser(strings.NewReader("bar")), nil
},
})
cmd := NewExportCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"-o", dir.Join("foo"), "container"})
assert.NilError(t, cmd.Execute())
@ -35,11 +34,11 @@ func TestContainerExportOutputToFile(t *testing.T) {
func TestContainerExportOutputToIrregularFile(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
containerExportFunc: func(container string) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("foo")), nil
return io.NopCloser(strings.NewReader("foo")), nil
},
})
cmd := NewExportCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs([]string{"-o", "/dev/random", "container"})
err := cmd.Execute()

View File

@ -2,7 +2,7 @@ package container
import (
"context"
"io/ioutil"
"io"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
@ -89,7 +89,7 @@ func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, er
// This shouldn't error out but swallowing the error makes it harder
// to track down if preProcessor issues come up.
if err := tmpl.Execute(ioutil.Discard, optionsProcessor); err != nil {
if err := tmpl.Execute(io.Discard, optionsProcessor); err != nil {
return nil, errors.Wrap(err, "failed to execute template")
}

View File

@ -2,7 +2,7 @@ package container
import (
"fmt"
"io/ioutil"
"io"
"testing"
"github.com/docker/cli/cli/config/configfile"
@ -161,7 +161,7 @@ func TestContainerListErrors(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)
}
}

View File

@ -2,7 +2,6 @@ package container
import (
"io"
"io/ioutil"
"strings"
"testing"
@ -15,7 +14,7 @@ import (
var logFn = func(expectedOut string) func(string, types.ContainerLogsOptions) (io.ReadCloser, error) {
return func(container string, opts types.ContainerLogsOptions) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader(expectedOut)), nil
return io.NopCloser(strings.NewReader(expectedOut)), nil
}
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
"regexp"
@ -845,7 +845,7 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
}
}
if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := ioutil.ReadFile(con[1])
f, err := os.ReadFile(con[1])
if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
}

View File

@ -2,7 +2,7 @@ package container
import (
"fmt"
"io/ioutil"
"io"
"os"
"runtime"
"strings"
@ -58,7 +58,7 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network
func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
flags := pflag.NewFlagSet("run", pflag.ContinueOnError)
flags.SetOutput(ioutil.Discard)
flags.SetOutput(io.Discard)
flags.Usage = nil
copts := addFlags(flags)
return flags, copts

View File

@ -1,7 +1,7 @@
package container
import (
"io/ioutil"
"io"
"testing"
"github.com/docker/cli/internal/test"
@ -47,7 +47,7 @@ func TestNewPortCommandOutput(t *testing.T) {
},
}, test.EnableContentTrust)
cmd := NewPortCommand(cli)
cmd.SetErr(ioutil.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"some_container", "80"})
err := cmd.Execute()
assert.NilError(t, err)

View File

@ -3,7 +3,7 @@ package container
import (
"context"
"fmt"
"io/ioutil"
"io"
"sort"
"testing"
@ -27,7 +27,7 @@ func TestRemoveForce(t *testing.T) {
Version: "1.36",
})
cmd := NewRmCommand(cli)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
t.Run("without force", func(t *testing.T) {
cmd.SetArgs([]string{"nosuchcontainer", "mycontainer"})

View File

@ -2,7 +2,7 @@ package container
import (
"fmt"
"io/ioutil"
"io"
"testing"
"github.com/docker/cli/internal/test"
@ -68,7 +68,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
cli.SetNotaryClient(tc.notaryFunc)
cmd := NewRunCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
err := cmd.Execute()
assert.Assert(t, err != nil)
assert.Assert(t, is.Contains(cli.ErrBuffer().String(), tc.expectedError))