github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cli/command/plugin/disable_test.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 "io" 6 "testing" 7 8 "github.com/docker/cli/internal/test" 9 "github.com/docker/docker/api/types" 10 "gotest.tools/v3/assert" 11 is "gotest.tools/v3/assert/cmp" 12 ) 13 14 func TestPluginDisableErrors(t *testing.T) { 15 testCases := []struct { 16 args []string 17 expectedError string 18 pluginDisableFunc func(name string, disableOptions types.PluginDisableOptions) error 19 }{ 20 { 21 args: []string{}, 22 expectedError: "requires exactly 1 argument", 23 }, 24 { 25 args: []string{"too", "many", "arguments"}, 26 expectedError: "requires exactly 1 argument", 27 }, 28 { 29 args: []string{"plugin-foo"}, 30 expectedError: "Error disabling plugin", 31 pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error { 32 return fmt.Errorf("Error disabling plugin") 33 }, 34 }, 35 } 36 37 for _, tc := range testCases { 38 cmd := newDisableCommand( 39 test.NewFakeCli(&fakeClient{ 40 pluginDisableFunc: tc.pluginDisableFunc, 41 })) 42 cmd.SetArgs(tc.args) 43 cmd.SetOut(io.Discard) 44 assert.ErrorContains(t, cmd.Execute(), tc.expectedError) 45 } 46 } 47 48 func TestPluginDisable(t *testing.T) { 49 cli := test.NewFakeCli(&fakeClient{ 50 pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error { 51 return nil 52 }, 53 }) 54 cmd := newDisableCommand(cli) 55 cmd.SetArgs([]string{"plugin-foo"}) 56 assert.NilError(t, cmd.Execute()) 57 assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String())) 58 }