mirror of https://github.com/docker/cli.git
cli/command/image: remove deprecated io/ioutil and use t.TempDir()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
76b47359cb
commit
d14b5bff80
|
@ -8,7 +8,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -298,7 +297,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dockerfileCtx = ioutil.NopCloser(bytes.NewBuffer(newDockerfile))
|
dockerfileCtx = io.NopCloser(bytes.NewBuffer(newDockerfile))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +393,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
|
||||||
if imageID == "" {
|
if imageID == "" {
|
||||||
return errors.Errorf("Server did not provide an image ID. Cannot write %s", options.imageIDFile)
|
return errors.Errorf("Server did not provide an image ID. Cannot write %s", options.imageIDFile)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(options.imageIDFile, []byte(imageID), 0666); err != nil {
|
if err := os.WriteFile(options.imageIDFile, []byte(imageID), 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -117,13 +116,13 @@ func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool,
|
||||||
// temporary directory containing the Dockerfile.
|
// temporary directory containing the Dockerfile.
|
||||||
func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
|
func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
|
||||||
// err is a named return value, due to the defer call below.
|
// err is a named return value, due to the defer call below.
|
||||||
dockerfileDir, err = ioutil.TempDir("", "docker-build-tempdockerfile-")
|
dockerfileDir, err = os.MkdirTemp("", "docker-build-tempdockerfile-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Errorf("unable to create temporary context directory: %v", err)
|
return "", errors.Errorf("unable to create temporary context directory: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(dockerfileDir)
|
_ = os.RemoveAll(dockerfileDir)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -240,7 +239,7 @@ func getWithStatusError(url string) (resp *http.Response, err error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("failed to GET %s with status %s", url, resp.Status)
|
msg := fmt.Sprintf("failed to GET %s with status %s", url, resp.Status)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "%s: error reading body", msg)
|
return nil, errors.Wrapf(err, "%s: error reading body", msg)
|
||||||
|
@ -372,7 +371,7 @@ func isUNC(path string) bool {
|
||||||
// AddDockerfileToBuildContext from a ReadCloser, returns a new archive and
|
// AddDockerfileToBuildContext from a ReadCloser, returns a new archive and
|
||||||
// the relative path to the dockerfile in the context.
|
// the relative path to the dockerfile in the context.
|
||||||
func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCloser) (io.ReadCloser, string, error) {
|
func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCloser) (io.ReadCloser, string, error) {
|
||||||
file, err := ioutil.ReadAll(dockerfileCtx)
|
file, err := io.ReadAll(dockerfileCtx)
|
||||||
dockerfileCtx.Close()
|
dockerfileCtx.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -19,40 +18,34 @@ import (
|
||||||
|
|
||||||
const dockerfileContents = "FROM busybox"
|
const dockerfileContents = "FROM busybox"
|
||||||
|
|
||||||
var prepareEmpty = func(t *testing.T) (string, func()) {
|
func prepareEmpty(t *testing.T) string {
|
||||||
return "", func() {}
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepareNoFiles = func(t *testing.T) (string, func()) {
|
func prepareNoFiles(t *testing.T) string {
|
||||||
return createTestTempDir(t, "builder-context-test")
|
return createTestTempDir(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepareOneFile = func(t *testing.T) (string, func()) {
|
func prepareOneFile(t *testing.T) string {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
return contextDir, cleanup
|
return contextDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (string, func()), excludes []string) {
|
func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) string, excludes []string) {
|
||||||
contextDir, cleanup := prepare(t)
|
contextDir := prepare(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
err := ValidateContextDirectory(contextDir, excludes)
|
err := ValidateContextDirectory(contextDir, excludes)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
|
func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
_, _, err := GetContextFromLocalDir(contextDir, "")
|
_, _, err := GetContextFromLocalDir(contextDir, "")
|
||||||
assert.ErrorContains(t, err, "Dockerfile")
|
assert.ErrorContains(t, err, "Dockerfile")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirNotExistingDir(t *testing.T) {
|
func TestGetContextFromLocalDirNotExistingDir(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
fakePath := filepath.Join(contextDir, "fake")
|
fakePath := filepath.Join(contextDir, "fake")
|
||||||
|
|
||||||
_, _, err := GetContextFromLocalDir(fakePath, "")
|
_, _, err := GetContextFromLocalDir(fakePath, "")
|
||||||
|
@ -60,9 +53,7 @@ func TestGetContextFromLocalDirNotExistingDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) {
|
func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
fakePath := filepath.Join(contextDir, "fake")
|
fakePath := filepath.Join(contextDir, "fake")
|
||||||
|
|
||||||
_, _, err := GetContextFromLocalDir(contextDir, fakePath)
|
_, _, err := GetContextFromLocalDir(contextDir, fakePath)
|
||||||
|
@ -70,13 +61,10 @@ func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
|
func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
|
||||||
contextDir, dirCleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer dirCleanup()
|
|
||||||
|
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
|
|
||||||
chdirCleanup := chdir(t, contextDir)
|
chdir(t, contextDir)
|
||||||
defer chdirCleanup()
|
|
||||||
|
|
||||||
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
@ -86,9 +74,7 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
|
func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
|
|
||||||
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
||||||
|
@ -99,9 +85,7 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirLocalFile(t *testing.T) {
|
func TestGetContextFromLocalDirLocalFile(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
testFilename := createTestTempFile(t, contextDir, "tmpTest", "test")
|
testFilename := createTestTempFile(t, contextDir, "tmpTest", "test")
|
||||||
|
|
||||||
|
@ -121,11 +105,8 @@ func TestGetContextFromLocalDirLocalFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
|
func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
chdir(t, contextDir)
|
||||||
|
|
||||||
chdirCleanup := chdir(t, contextDir)
|
|
||||||
defer chdirCleanup()
|
|
||||||
|
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
|
|
||||||
|
@ -137,7 +118,7 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromReaderString(t *testing.T) {
|
func TestGetContextFromReaderString(t *testing.T) {
|
||||||
tarArchive, relDockerfile, err := GetContextFromReader(ioutil.NopCloser(strings.NewReader(dockerfileContents)), "")
|
tarArchive, relDockerfile, err := GetContextFromReader(io.NopCloser(strings.NewReader(dockerfileContents)), "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error when executing GetContextFromReader: %s", err)
|
t.Fatalf("Error when executing GetContextFromReader: %s", err)
|
||||||
|
@ -173,9 +154,7 @@ func TestGetContextFromReaderString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContextFromReaderTar(t *testing.T) {
|
func TestGetContextFromReaderTar(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "builder-context-test")
|
contextDir := createTestTempDir(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents)
|
||||||
|
|
||||||
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
||||||
|
@ -238,23 +217,24 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) {
|
||||||
testValidateContextDirectory(t, prepareOneFile, []string{DefaultDockerfileName})
|
testValidateContextDirectory(t, prepareOneFile, []string{DefaultDockerfileName})
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTestTempDir creates a temporary directory for testing.
|
// createTestTempDir creates a temporary directory for testing. It returns the
|
||||||
// It returns the created path and a cleanup function which is meant to be used as deferred call.
|
// created path. When an error occurs, it terminates the test.
|
||||||
// When an error occurs, it terminates the test.
|
func createTestTempDir(t *testing.T) string {
|
||||||
//nolint: unparam
|
t.Helper()
|
||||||
func createTestTempDir(t *testing.T, prefix string) (string, func()) {
|
path := t.TempDir()
|
||||||
path, err := ioutil.TempDir("", prefix)
|
|
||||||
|
// Eval Symlinks is needed to account for macOS TMP using symlinks
|
||||||
|
path, err := filepath.EvalSymlinks(path)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
path, err = filepath.EvalSymlinks(path)
|
return path
|
||||||
assert.NilError(t, err)
|
|
||||||
return path, func() { assert.NilError(t, os.RemoveAll(path)) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTestTempFile creates a temporary file within dir with specific contents and permissions.
|
// createTestTempFile creates a temporary file within dir with specific contents and permissions.
|
||||||
// When an error occurs, it terminates the test
|
// When an error occurs, it terminates the test
|
||||||
func createTestTempFile(t *testing.T, dir, filename, contents string) string {
|
func createTestTempFile(t *testing.T, dir, filename, contents string) string {
|
||||||
|
t.Helper()
|
||||||
filePath := filepath.Join(dir, filename)
|
filePath := filepath.Join(dir, filename)
|
||||||
err := ioutil.WriteFile(filePath, []byte(contents), 0777)
|
err := os.WriteFile(filePath, []byte(contents), 0777)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
return filePath
|
return filePath
|
||||||
}
|
}
|
||||||
|
@ -263,11 +243,13 @@ func createTestTempFile(t *testing.T, dir, filename, contents string) string {
|
||||||
// It returns a function which changes working directory back to the previous one.
|
// It returns a function which changes working directory back to the previous one.
|
||||||
// This function is meant to be executed as a deferred call.
|
// This function is meant to be executed as a deferred call.
|
||||||
// When an error occurs, it terminates the test.
|
// When an error occurs, it terminates the test.
|
||||||
func chdir(t *testing.T, dir string) func() {
|
func chdir(t *testing.T, dir string) {
|
||||||
workingDirectory, err := os.Getwd()
|
workingDirectory, err := os.Getwd()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.NilError(t, os.Chdir(dir))
|
assert.NilError(t, os.Chdir(dir))
|
||||||
return func() { assert.NilError(t, os.Chdir(workingDirectory)) }
|
t.Cleanup(func() {
|
||||||
|
assert.NilError(t, os.Chdir(workingDirectory))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsArchive(t *testing.T) {
|
func TestIsArchive(t *testing.T) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -39,7 +38,7 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
||||||
FROM alpine:3.6
|
FROM alpine:3.6
|
||||||
COPY foo /
|
COPY foo /
|
||||||
`)
|
`)
|
||||||
cli.SetIn(streams.NewIn(ioutil.NopCloser(dockerfile)))
|
cli.SetIn(streams.NewIn(io.NopCloser(dockerfile)))
|
||||||
|
|
||||||
dir := fs.NewDir(t, t.Name(),
|
dir := fs.NewDir(t, t.Name(),
|
||||||
fs.WithFile("foo", "some content"))
|
fs.WithFile("foo", "some content"))
|
||||||
|
@ -128,7 +127,7 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
||||||
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
// Clone a small repo that exists so git doesn't prompt for credentials
|
// Clone a small repo that exists so git doesn't prompt for credentials
|
||||||
cmd.SetArgs([]string{"github.com/docker/for-win"})
|
cmd.SetArgs([]string{"github.com/docker/for-win"})
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.ErrorContains(t, err, "unable to prepare context")
|
assert.ErrorContains(t, err, "unable to prepare context")
|
||||||
assert.ErrorContains(t, err, "docker-build-git")
|
assert.ErrorContains(t, err, "docker-build-git")
|
||||||
|
@ -139,20 +138,17 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
||||||
// case.
|
// case.
|
||||||
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
||||||
tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-")
|
|
||||||
assert.NilError(t, err)
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository")
|
buildDir := filepath.Join(t.TempDir(), "github.com", "docker", "no-such-repository")
|
||||||
err = os.MkdirAll(buildDir, 0777)
|
err := os.MkdirAll(buildDir, 0777)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
err = ioutil.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644)
|
err = os.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
client := test.NewFakeCli(&fakeClient{})
|
client := test.NewFakeCli(&fakeClient{})
|
||||||
cmd := NewBuildCommand(client)
|
cmd := NewBuildCommand(client)
|
||||||
cmd.SetArgs([]string{buildDir})
|
cmd.SetArgs([]string{buildDir})
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
err = cmd.Execute()
|
err = cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -193,7 +189,7 @@ func (f *fakeBuild) build(_ context.Context, context io.Reader, options types.Im
|
||||||
f.context = tar.NewReader(context)
|
f.context = tar.NewReader(context)
|
||||||
f.options = options
|
f.options = options
|
||||||
body := new(bytes.Buffer)
|
body := new(bytes.Buffer)
|
||||||
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
|
return types.ImageBuildResponse{Body: io.NopCloser(body)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeBuild) headers(t *testing.T) []*tar.Header {
|
func (f *fakeBuild) headers(t *testing.T) []*tar.Header {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package image
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ func (cli *fakeClient) ImageSave(_ context.Context, images []string) (io.ReadClo
|
||||||
if cli.imageSaveFunc != nil {
|
if cli.imageSaveFunc != nil {
|
||||||
return cli.imageSaveFunc(images)
|
return cli.imageSaveFunc(images)
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *fakeClient) ImageRemove(_ context.Context, image string,
|
func (cli *fakeClient) ImageRemove(_ context.Context, image string,
|
||||||
|
@ -56,7 +55,7 @@ func (cli *fakeClient) ImagePush(_ context.Context, ref string, options types.Im
|
||||||
if cli.imagePushFunc != nil {
|
if cli.imagePushFunc != nil {
|
||||||
return cli.imagePushFunc(ref, options)
|
return cli.imagePushFunc(ref, options)
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *fakeClient) Info(_ context.Context) (types.Info, error) {
|
func (cli *fakeClient) Info(_ context.Context) (types.Info, error) {
|
||||||
|
@ -70,7 +69,7 @@ func (cli *fakeClient) ImagePull(_ context.Context, ref string, options types.Im
|
||||||
if cli.imagePullFunc != nil {
|
if cli.imagePullFunc != nil {
|
||||||
cli.imagePullFunc(ref, options)
|
cli.imagePullFunc(ref, options)
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error) {
|
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error) {
|
||||||
|
@ -106,7 +105,7 @@ func (cli *fakeClient) ImageImport(_ context.Context, source types.ImageImportSo
|
||||||
if cli.imageImportFunc != nil {
|
if cli.imageImportFunc != nil {
|
||||||
return cli.imageImportFunc(source, ref, options)
|
return cli.imageImportFunc(source, ref, options)
|
||||||
}
|
}
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *fakeClient) ImageHistory(_ context.Context, img string) ([]image.HistoryResponseItem, error) {
|
func (cli *fakeClient) ImageHistory(_ context.Context, img string) ([]image.HistoryResponseItem, error) {
|
||||||
|
@ -120,5 +119,5 @@ func (cli *fakeClient) ImageBuild(ctx context.Context, context io.Reader, option
|
||||||
if cli.imageBuildFunc != nil {
|
if cli.imageBuildFunc != nil {
|
||||||
return cli.imageBuildFunc(ctx, context, options)
|
return cli.imageBuildFunc(ctx, context, options)
|
||||||
}
|
}
|
||||||
return types.ImageBuildResponse{Body: ioutil.NopCloser(strings.NewReader(""))}, nil
|
return types.ImageBuildResponse{Body: io.NopCloser(strings.NewReader(""))}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := NewHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
|
cmd := NewHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
|
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
|
||||||
cmd := NewHistoryCommand(cli)
|
cmd := NewHistoryCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ func TestNewImportCommandErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
|
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +43,7 @@ func TestNewImportCommandErrors(t *testing.T) {
|
||||||
|
|
||||||
func TestNewImportCommandInvalidFile(t *testing.T) {
|
func TestNewImportCommandInvalidFile(t *testing.T) {
|
||||||
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs([]string{"testdata/import-command-success.unexistent-file"})
|
cmd.SetArgs([]string{"testdata/import-command-success.unexistent-file"})
|
||||||
assert.ErrorContains(t, cmd.Execute(), "testdata/import-command-success.unexistent-file")
|
assert.ErrorContains(t, cmd.Execute(), "testdata/import-command-success.unexistent-file")
|
||||||
}
|
}
|
||||||
|
@ -68,7 +67,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
||||||
args: []string{"-", "image:local"},
|
args: []string{"-", "image:local"},
|
||||||
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||||
assert.Check(t, is.Equal("image:local", ref))
|
assert.Check(t, is.Equal("image:local", ref))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -76,7 +75,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
||||||
args: []string{"--message", "test message", "-"},
|
args: []string{"--message", "test message", "-"},
|
||||||
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||||
assert.Check(t, is.Equal("test message", options.Message))
|
assert.Check(t, is.Equal("test message", options.Message))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,7 +83,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
||||||
args: []string{"--change", "ENV DEBUG=true", "-"},
|
args: []string{"--change", "ENV DEBUG=true", "-"},
|
||||||
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||||
assert.Check(t, is.Equal("ENV DEBUG=true", options.Changes[0]))
|
assert.Check(t, is.Equal("ENV DEBUG=true", options.Changes[0]))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -92,13 +91,13 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
||||||
args: []string{"--change", "ENV DEBUG true", "-"},
|
args: []string{"--change", "ENV DEBUG true", "-"},
|
||||||
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||||
assert.Check(t, is.Equal("ENV DEBUG true", options.Changes[0]))
|
assert.Check(t, is.Equal("ENV DEBUG true", options.Changes[0]))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
|
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
|
@ -26,7 +26,7 @@ func TestNewInspectCommandErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := newInspectCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := newInspectCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
||||||
imageInspectInvocationCount = 0
|
imageInspectInvocationCount = 0
|
||||||
cli := test.NewFakeCli(&fakeClient{imageInspectFunc: tc.imageInspectFunc})
|
cli := test.NewFakeCli(&fakeClient{imageInspectFunc: tc.imageInspectFunc})
|
||||||
cmd := newInspectCommand(cli)
|
cmd := newInspectCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
|
@ -36,7 +36,7 @@ func TestNewImagesCommandErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := NewImagesCommand(test.NewFakeCli(&fakeClient{imageListFunc: tc.imageListFunc}))
|
cmd := NewImagesCommand(test.NewFakeCli(&fakeClient{imageListFunc: tc.imageListFunc}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageListFunc: tc.imageListFunc})
|
cli := test.NewFakeCli(&fakeClient{imageListFunc: tc.imageListFunc})
|
||||||
cli.SetConfigFile(&configfile.ConfigFile{ImagesFormat: tc.imageFormat})
|
cli.SetConfigFile(&configfile.ConfigFile{ImagesFormat: tc.imageFormat})
|
||||||
cmd := NewImagesCommand(cli)
|
cmd := NewImagesCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package image
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc})
|
cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc})
|
||||||
cli.In().SetIsTerminal(tc.isTerminalIn)
|
cli.In().SetIsTerminal(tc.isTerminalIn)
|
||||||
cmd := NewLoadCommand(cli)
|
cmd := NewLoadCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +52,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
|
||||||
func TestNewLoadCommandInvalidInput(t *testing.T) {
|
func TestNewLoadCommandInvalidInput(t *testing.T) {
|
||||||
expectedError := "open *"
|
expectedError := "open *"
|
||||||
cmd := NewLoadCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := NewLoadCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs([]string{"--input", "*"})
|
cmd.SetArgs([]string{"--input", "*"})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.ErrorContains(t, err, expectedError)
|
assert.ErrorContains(t, err, expectedError)
|
||||||
|
@ -68,7 +67,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "simple",
|
name: "simple",
|
||||||
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
||||||
return types.ImageLoadResponse{Body: ioutil.NopCloser(strings.NewReader("Success"))}, nil
|
return types.ImageLoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -76,7 +75,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
|
||||||
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
||||||
json := "{\"ID\": \"1\"}"
|
json := "{\"ID\": \"1\"}"
|
||||||
return types.ImageLoadResponse{
|
return types.ImageLoadResponse{
|
||||||
Body: ioutil.NopCloser(strings.NewReader(json)),
|
Body: io.NopCloser(strings.NewReader(json)),
|
||||||
JSON: true,
|
JSON: true,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
@ -85,14 +84,14 @@ func TestNewLoadCommandSuccess(t *testing.T) {
|
||||||
name: "input-file",
|
name: "input-file",
|
||||||
args: []string{"--input", "testdata/load-command-success.input.txt"},
|
args: []string{"--input", "testdata/load-command-success.input.txt"},
|
||||||
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
imageLoadFunc: func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
||||||
return types.ImageLoadResponse{Body: ioutil.NopCloser(strings.NewReader("Success"))}, nil
|
return types.ImageLoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc})
|
cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc})
|
||||||
cmd := NewLoadCommand(cli)
|
cmd := NewLoadCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
|
@ -39,7 +39,7 @@ func TestNewPruneCommandErrors(t *testing.T) {
|
||||||
cmd := NewPruneCommand(test.NewFakeCli(&fakeClient{
|
cmd := NewPruneCommand(test.NewFakeCli(&fakeClient{
|
||||||
imagesPruneFunc: tc.imagesPruneFunc,
|
imagesPruneFunc: tc.imagesPruneFunc,
|
||||||
}))
|
}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{imagesPruneFunc: tc.imagesPruneFunc})
|
cli := test.NewFakeCli(&fakeClient{imagesPruneFunc: tc.imagesPruneFunc})
|
||||||
cmd := NewPruneCommand(cli)
|
cmd := NewPruneCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package image
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ func TestNewPullCommandErrors(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{})
|
cli := test.NewFakeCli(&fakeClient{})
|
||||||
cmd := NewPullCommand(cli)
|
cmd := NewPullCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -72,11 +71,11 @@ func TestNewPullCommandSuccess(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
||||||
assert.Check(t, is.Equal(tc.expectedTag, ref), tc.name)
|
assert.Check(t, is.Equal(tc.expectedTag, ref), tc.name)
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := NewPullCommand(cli)
|
cmd := NewPullCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
@ -113,12 +112,12 @@ func TestNewPullCommandWithContentTrustErrors(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image")
|
return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image")
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
cli.SetNotaryClient(tc.notaryFunc)
|
cli.SetNotaryClient(tc.notaryFunc)
|
||||||
cmd := NewPullCommand(cli)
|
cmd := NewPullCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.ErrorContains(t, err, tc.expectedError)
|
assert.ErrorContains(t, err, tc.expectedError)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package image
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
@ -93,7 +93,7 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.quiet {
|
if opts.quiet {
|
||||||
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(ioutil.Discard), nil)
|
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(io.Discard), nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Fprintln(dockerCli.Out(), ref.String())
|
fmt.Fprintln(dockerCli.Out(), ref.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -34,14 +33,14 @@ func TestNewPushCommandErrors(t *testing.T) {
|
||||||
args: []string{"image:repo"},
|
args: []string{"image:repo"},
|
||||||
expectedError: "Failed to push",
|
expectedError: "Failed to push",
|
||||||
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(strings.NewReader("")), errors.Errorf("Failed to push")
|
return io.NopCloser(strings.NewReader("")), errors.Errorf("Failed to push")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{imagePushFunc: tc.imagePushFunc})
|
cli := test.NewFakeCli(&fakeClient{imagePushFunc: tc.imagePushFunc})
|
||||||
cmd := NewPushCommand(cli)
|
cmd := NewPushCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +68,7 @@ func TestNewPushCommandSuccess(t *testing.T) {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := NewPushCommand(cli)
|
cmd := NewPushCommand(cli)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
|
@ -68,7 +68,7 @@ func TestNewRemoveCommandErrors(t *testing.T) {
|
||||||
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
|
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
|
||||||
imageRemoveFunc: tc.imageRemoveFunc,
|
imageRemoveFunc: tc.imageRemoveFunc,
|
||||||
}))
|
}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
})
|
})
|
||||||
|
@ -124,7 +124,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc})
|
cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc})
|
||||||
cmd := NewRemoveCommand(cli)
|
cmd := NewRemoveCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
assert.Check(t, is.Equal(tc.expectedStderr, cli.ErrBuffer().String()))
|
assert.Check(t, is.Equal(tc.expectedStderr, cli.ErrBuffer().String()))
|
||||||
|
|
|
@ -2,7 +2,6 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -38,7 +37,7 @@ func TestNewSaveCommandErrors(t *testing.T) {
|
||||||
isTerminal: false,
|
isTerminal: false,
|
||||||
expectedError: "error saving image",
|
expectedError: "error saving image",
|
||||||
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(strings.NewReader("")), errors.Errorf("error saving image")
|
return io.NopCloser(strings.NewReader("")), errors.Errorf("error saving image")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -56,7 +55,7 @@ func TestNewSaveCommandErrors(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{imageSaveFunc: tc.imageSaveFunc})
|
cli := test.NewFakeCli(&fakeClient{imageSaveFunc: tc.imageSaveFunc})
|
||||||
cli.Out().SetIsTerminal(tc.isTerminal)
|
cli.Out().SetIsTerminal(tc.isTerminal)
|
||||||
cmd := NewSaveCommand(cli)
|
cmd := NewSaveCommand(cli)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +74,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
|
||||||
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
||||||
assert.Assert(t, is.Len(images, 1))
|
assert.Assert(t, is.Len(images, 1))
|
||||||
assert.Check(t, is.Equal("arg1", images[0]))
|
assert.Check(t, is.Equal("arg1", images[0]))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
deferredFunc: func() {
|
deferredFunc: func() {
|
||||||
os.Remove("save_tmp_file")
|
os.Remove("save_tmp_file")
|
||||||
|
@ -88,17 +87,17 @@ func TestNewSaveCommandSuccess(t *testing.T) {
|
||||||
assert.Assert(t, is.Len(images, 2))
|
assert.Assert(t, is.Len(images, 2))
|
||||||
assert.Check(t, is.Equal("arg1", images[0]))
|
assert.Check(t, is.Equal("arg1", images[0]))
|
||||||
assert.Check(t, is.Equal("arg2", images[1]))
|
assert.Check(t, is.Equal("arg2", images[1]))
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := NewSaveCommand(test.NewFakeCli(&fakeClient{
|
cmd := NewSaveCommand(test.NewFakeCli(&fakeClient{
|
||||||
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
if tc.deferredFunc != nil {
|
if tc.deferredFunc != nil {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
|
@ -19,7 +19,7 @@ func TestCliNewTagCommandErrors(t *testing.T) {
|
||||||
for _, args := range testCases {
|
for _, args := range testCases {
|
||||||
cmd := NewTagCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := NewTagCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
assert.ErrorContains(t, cmd.Execute(), expectedError)
|
assert.ErrorContains(t, cmd.Execute(), expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func TestCliNewTagCommand(t *testing.T) {
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
cmd.SetArgs([]string{"image1", "image2"})
|
cmd.SetArgs([]string{"image1", "image2"})
|
||||||
cmd.SetOut(ioutil.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
value, _ := cmd.Flags().GetBool("interspersed")
|
value, _ := cmd.Flags().GetBool("interspersed")
|
||||||
assert.Check(t, !value)
|
assert.Check(t, !value)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
@ -283,7 +282,7 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru
|
||||||
|
|
||||||
out := cli.Out()
|
out := cli.Out()
|
||||||
if opts.quiet {
|
if opts.quiet {
|
||||||
out = streams.NewOut(ioutil.Discard)
|
out = streams.NewOut(io.Discard)
|
||||||
}
|
}
|
||||||
return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil)
|
return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/trust"
|
"github.com/docker/cli/cli/trust"
|
||||||
|
@ -51,11 +49,7 @@ func TestNonOfficialTrustServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTargetToAllSignableRolesError(t *testing.T) {
|
func TestAddTargetToAllSignableRolesError(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "notary-test-")
|
notaryRepo, err := client.NewFileCachedRepository(t.TempDir(), "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
|
||||||
assert.NilError(t, err)
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
|
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
target := client.Target{}
|
target := client.Target{}
|
||||||
err = AddTargetToAllSignableRoles(notaryRepo, &target)
|
err = AddTargetToAllSignableRoles(notaryRepo, &target)
|
||||||
|
|
Loading…
Reference in New Issue