(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestConfigInspectErrors(t *testing.T) { |
| 19 | testCases := []struct { |
| 20 | args []string |
| 21 | flags map[string]string |
| 22 | configInspectFunc func(_ context.Context, configID string, _ client.ConfigInspectOptions) (client.ConfigInspectResult, error) |
| 23 | expectedError string |
| 24 | }{ |
| 25 | { |
| 26 | expectedError: "requires at least 1 argument", |
| 27 | }, |
| 28 | { |
| 29 | args: []string{"foo"}, |
| 30 | configInspectFunc: func(context.Context, string, client.ConfigInspectOptions) (client.ConfigInspectResult, error) { |
| 31 | return client.ConfigInspectResult{}, errors.New("error while inspecting the config") |
| 32 | }, |
| 33 | expectedError: "error while inspecting the config", |
| 34 | }, |
| 35 | { |
| 36 | args: []string{"foo"}, |
| 37 | flags: map[string]string{ |
| 38 | "format": "{{invalid format}}", |
| 39 | }, |
| 40 | expectedError: "template parsing error", |
| 41 | }, |
| 42 | { |
| 43 | args: []string{"foo", "bar"}, |
| 44 | configInspectFunc: func(_ context.Context, configID string, _ client.ConfigInspectOptions) (client.ConfigInspectResult, error) { |
| 45 | if configID == "foo" { |
| 46 | return client.ConfigInspectResult{ |
| 47 | Config: *builders.Config(builders.ConfigName("foo")), |
| 48 | }, nil |
| 49 | } |
| 50 | return client.ConfigInspectResult{}, errors.New("error while inspecting the config") |
| 51 | }, |
| 52 | expectedError: "error while inspecting the config", |
| 53 | }, |
| 54 | } |
| 55 | for _, tc := range testCases { |
| 56 | cmd := newConfigInspectCommand( |
| 57 | test.NewFakeCli(&fakeClient{ |
| 58 | configInspectFunc: tc.configInspectFunc, |
| 59 | }), |
| 60 | ) |
| 61 | cmd.SetArgs(tc.args) |
| 62 | for key, value := range tc.flags { |
| 63 | assert.Check(t, cmd.Flags().Set(key, value)) |
| 64 | } |
| 65 | cmd.SetOut(io.Discard) |
| 66 | cmd.SetErr(io.Discard) |
| 67 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestConfigInspectWithoutFormat(t *testing.T) { |
| 72 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…