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