(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func TestInspectErrors(t *testing.T) { |
| 40 | testCases := []struct { |
| 41 | description string |
| 42 | args []string |
| 43 | flags map[string]string |
| 44 | expectedError string |
| 45 | inspectFunc func(name string) (client.PluginInspectResult, error) |
| 46 | }{ |
| 47 | { |
| 48 | description: "too few arguments", |
| 49 | args: []string{}, |
| 50 | expectedError: "requires at least 1 argument", |
| 51 | }, |
| 52 | { |
| 53 | description: "error inspecting plugin", |
| 54 | args: []string{"foo"}, |
| 55 | expectedError: "error inspecting plugin", |
| 56 | inspectFunc: func(string) (client.PluginInspectResult, error) { |
| 57 | return client.PluginInspectResult{}, errors.New("error inspecting plugin") |
| 58 | }, |
| 59 | }, |
| 60 | { |
| 61 | description: "invalid format", |
| 62 | args: []string{"foo"}, |
| 63 | flags: map[string]string{ |
| 64 | "format": "{{invalid format}}", |
| 65 | }, |
| 66 | expectedError: "template parsing error", |
| 67 | inspectFunc: func(string) (client.PluginInspectResult, error) { |
| 68 | return client.PluginInspectResult{}, errors.New("this function should not be called in this test") |
| 69 | }, |
| 70 | }, |
| 71 | } |
| 72 | |
| 73 | for _, tc := range testCases { |
| 74 | t.Run(tc.description, func(t *testing.T) { |
| 75 | cli := test.NewFakeCli(&fakeClient{pluginInspectFunc: tc.inspectFunc}) |
| 76 | cmd := newInspectCommand(cli) |
| 77 | cmd.SetArgs(tc.args) |
| 78 | for key, value := range tc.flags { |
| 79 | assert.NilError(t, cmd.Flags().Set(key, value)) |
| 80 | } |
| 81 | cmd.SetOut(io.Discard) |
| 82 | cmd.SetErr(io.Discard) |
| 83 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 84 | }) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestInspect(t *testing.T) { |
| 89 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…