MCPcopy Index your code
hub / github.com/docker/cli / TestPluginEnableErrors

Function TestPluginEnableErrors

cli/command/plugin/enable_test.go:14–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestPluginEnableErrors(t *testing.T) {
15 testCases := []struct {
16 args []string
17 flags map[string]string
18 pluginEnableFunc func(name string, options client.PluginEnableOptions) (client.PluginEnableResult, error)
19 expectedError string
20 }{
21 {
22 args: []string{},
23 expectedError: "requires 1 argument",
24 },
25 {
26 args: []string{"too-many", "arguments"},
27 expectedError: "requires 1 argument",
28 },
29 {
30 args: []string{"plugin-foo"},
31 pluginEnableFunc: func(name string, options client.PluginEnableOptions) (client.PluginEnableResult, error) {
32 return client.PluginEnableResult{}, errors.New("failed to enable plugin")
33 },
34 expectedError: "failed to enable plugin",
35 },
36 {
37 args: []string{"plugin-foo"},
38 flags: map[string]string{
39 "timeout": "-1",
40 },
41 expectedError: "negative timeout -1 is invalid",
42 },
43 }
44
45 for _, tc := range testCases {
46 cmd := newEnableCommand(test.NewFakeCli(&fakeClient{
47 pluginEnableFunc: tc.pluginEnableFunc,
48 }))
49 cmd.SetArgs(tc.args)
50 for key, value := range tc.flags {
51 assert.NilError(t, cmd.Flags().Set(key, value))
52 }
53 cmd.SetOut(io.Discard)
54 cmd.SetErr(io.Discard)
55 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
56 }
57}
58
59func TestPluginEnable(t *testing.T) {
60 cli := test.NewFakeCli(&fakeClient{

Callers

nothing calls this directly

Calls 5

newEnableCommandFunction · 0.85
SetArgsMethod · 0.80
SetMethod · 0.45
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…