2018-02-13 05:38:14 -05:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/cli/internal/test"
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-02-13 05:38:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoveErrors(t *testing.T) {
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
|
|
|
pluginRemoveFunc func(name string, options types.PluginRemoveOptions) error
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{},
|
|
|
|
expectedError: "requires at least 1 argument",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"plugin-foo"},
|
|
|
|
pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error {
|
|
|
|
return fmt.Errorf("Error removing plugin")
|
|
|
|
},
|
|
|
|
expectedError: "Error removing plugin",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
pluginRemoveFunc: tc.pluginRemoveFunc,
|
|
|
|
})
|
|
|
|
cmd := newRemoveCommand(cli)
|
|
|
|
cmd.SetArgs(tc.args)
|
|
|
|
cmd.SetOutput(ioutil.Discard)
|
2018-03-06 14:03:47 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2018-02-13 05:38:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemove(t *testing.T) {
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
cmd := newRemoveCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"plugin-foo"})
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
2018-02-13 05:38:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveWithForceOption(t *testing.T) {
|
|
|
|
force := false
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error {
|
|
|
|
force = options.Force
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
cmd := newRemoveCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"plugin-foo"})
|
|
|
|
cmd.Flags().Set("force", "true")
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, force)
|
|
|
|
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
2018-02-13 05:38:14 -05:00
|
|
|
}
|