mirror of https://github.com/docker/cli.git
Merge pull request #187 from dnephin/small-cleanup-to-image-remove
Fix some problems with image force remove
This commit is contained in:
commit
d209929aab
|
@ -59,9 +59,6 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
dels, err := client.ImageRemove(ctx, img, options)
|
dels, err := client.ImageRemove(ctx, img, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if opts.force {
|
|
||||||
fmt.Fprintf(dockerCli.Out(), "NotFound: %s\n", img)
|
|
||||||
}
|
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else {
|
} else {
|
||||||
for _, del := range dels {
|
for _, del := range dels {
|
||||||
|
@ -74,8 +71,12 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.force && len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errors.Errorf("%s", strings.Join(errs, "\n"))
|
msg := strings.Join(errs, "\n")
|
||||||
|
if !opts.force {
|
||||||
|
return errors.New(msg)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(dockerCli.Err(), msg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
|
imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
|
||||||
|
expectedErrMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Image Deleted",
|
name: "Image Deleted",
|
||||||
|
@ -74,6 +75,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
||||||
assert.Equal(t, "image1", image)
|
assert.Equal(t, "image1", image)
|
||||||
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
|
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
|
||||||
},
|
},
|
||||||
|
expectedErrMsg: "error removing image",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Image Untagged",
|
name: "Image Untagged",
|
||||||
|
@ -96,12 +98,16 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
|
errBuf := new(bytes.Buffer)
|
||||||
imageRemoveFunc: tc.imageRemoveFunc,
|
fakeCli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc}, buf)
|
||||||
}, buf))
|
fakeCli.SetErr(errBuf)
|
||||||
|
cmd := NewRemoveCommand(fakeCli)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
|
if tc.expectedErrMsg != "" {
|
||||||
|
assert.Equal(t, tc.expectedErrMsg, errBuf.String())
|
||||||
|
}
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := string(golden.Get(t, []byte(actual), fmt.Sprintf("remove-command-success.%s.golden", tc.name))[:])
|
expected := string(golden.Get(t, []byte(actual), fmt.Sprintf("remove-command-success.%s.golden", tc.name))[:])
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, expected)
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, expected)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
NotFound:image1
|
|
Loading…
Reference in New Issue