mirror of https://github.com/docker/cli.git
Merge pull request #1377 from adshmh/migrate-TestExportContainerWithOutputAndImportImage-from-moby
add a unit test to cover container export command output file option
This commit is contained in:
commit
3993346fc6
|
@ -24,6 +24,7 @@ type fakeClient struct {
|
||||||
logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error)
|
logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||||
waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error)
|
waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error)
|
||||||
containerListFunc func(types.ContainerListOptions) ([]types.Container, error)
|
containerListFunc func(types.ContainerListOptions) ([]types.Container, error)
|
||||||
|
containerExportFunc func(string) (io.ReadCloser, error)
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,3 +125,10 @@ func (f *fakeClient) ContainerStart(_ context.Context, container string, options
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.ReadCloser, error) {
|
||||||
|
if f.containerExportFunc != nil {
|
||||||
|
return f.containerExportFunc(container)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
Loading…
Reference in New Issue