github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/cli/command/plugin/remove_test.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "testing" 7 8 "github.com/docker/cli/internal/test" 9 "github.com/docker/docker/api/types" 10 "gotest.tools/assert" 11 is "gotest.tools/assert/cmp" 12 ) 13 14 func TestRemoveErrors(t *testing.T) { 15 16 testCases := []struct { 17 args []string 18 pluginRemoveFunc func(name string, options types.PluginRemoveOptions) error 19 expectedError string 20 }{ 21 { 22 args: []string{}, 23 expectedError: "requires at least 1 argument", 24 }, 25 { 26 args: []string{"plugin-foo"}, 27 pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error { 28 return fmt.Errorf("Error removing plugin") 29 }, 30 expectedError: "Error removing plugin", 31 }, 32 } 33 34 for _, tc := range testCases { 35 cli := test.NewFakeCli(&fakeClient{ 36 pluginRemoveFunc: tc.pluginRemoveFunc, 37 }) 38 cmd := newRemoveCommand(cli) 39 cmd.SetArgs(tc.args) 40 cmd.SetOutput(ioutil.Discard) 41 assert.ErrorContains(t, cmd.Execute(), tc.expectedError) 42 } 43 } 44 45 func TestRemove(t *testing.T) { 46 cli := test.NewFakeCli(&fakeClient{ 47 pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error { 48 return nil 49 }, 50 }) 51 cmd := newRemoveCommand(cli) 52 cmd.SetArgs([]string{"plugin-foo"}) 53 assert.NilError(t, cmd.Execute()) 54 assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String())) 55 } 56 57 func TestRemoveWithForceOption(t *testing.T) { 58 force := false 59 cli := test.NewFakeCli(&fakeClient{ 60 pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error { 61 force = options.Force 62 return nil 63 }, 64 }) 65 cmd := newRemoveCommand(cli) 66 cmd.SetArgs([]string{"plugin-foo"}) 67 cmd.Flags().Set("force", "true") 68 assert.NilError(t, cmd.Execute()) 69 assert.Check(t, force) 70 assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String())) 71 }