From fc1e11d46ad7a1d2c090919afc3319d881c4a286 Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Tue, 18 Sep 2018 12:29:56 -0400 Subject: [PATCH] moved integration test TestExportContainerWithOutputAndImportImage from moby/moby to docker/cli. The integration test TestExportContainerWithOutputAndImportImage in moby/moby is the same as TestExportContainerAndImportImage, except for the output file option. Adding a unit test to cover the output file option of the export command here allows the removal of the redundant integration test TestExportContainerWithOutputAndImportImage. Signed-off-by: Arash Deshmeh --- cli/command/container/client_test.go | 8 +++++++ cli/command/container/export_test.go | 33 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 cli/command/container/export_test.go diff --git a/cli/command/container/client_test.go b/cli/command/container/client_test.go index a2c39bc6ff..3ff1792d51 100644 --- a/cli/command/container/client_test.go +++ b/cli/command/container/client_test.go @@ -24,6 +24,7 @@ type fakeClient struct { logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error) waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error) containerListFunc func(types.ContainerListOptions) ([]types.Container, error) + containerExportFunc func(string) (io.ReadCloser, error) Version string } @@ -124,3 +125,10 @@ func (f *fakeClient) ContainerStart(_ context.Context, container string, options } return nil } + +func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.ReadCloser, error) { + if f.containerExportFunc != nil { + return f.containerExportFunc(container) + } + return nil, nil +} diff --git a/cli/command/container/export_test.go b/cli/command/container/export_test.go new file mode 100644 index 0000000000..b961ec7630 --- /dev/null +++ b/cli/command/container/export_test.go @@ -0,0 +1,33 @@ +package container + +import ( + "io" + "io/ioutil" + "strings" + "testing" + + "github.com/docker/cli/internal/test" + "gotest.tools/assert" + "gotest.tools/fs" +) + +func TestContainerExportOutputToFile(t *testing.T) { + dir := fs.NewDir(t, "export-test") + defer dir.Remove() + + cli := test.NewFakeCli(&fakeClient{ + containerExportFunc: func(container string) (io.ReadCloser, error) { + return ioutil.NopCloser(strings.NewReader("bar")), nil + }, + }) + cmd := NewExportCommand(cli) + cmd.SetOutput(ioutil.Discard) + cmd.SetArgs([]string{"-o", dir.Join("foo"), "container"}) + assert.NilError(t, cmd.Execute()) + + expected := fs.Expected(t, + fs.WithFile("foo", "bar", fs.MatchAnyFileMode), + ) + + assert.Assert(t, fs.Equal(dir.Path(), expected)) +}