(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestVolumeInspectErrors(t *testing.T) { |
| 19 | testCases := []struct { |
| 20 | args []string |
| 21 | flags map[string]string |
| 22 | volumeInspectFunc func(volumeID string) (client.VolumeInspectResult, error) |
| 23 | expectedError string |
| 24 | }{ |
| 25 | { |
| 26 | expectedError: "requires at least 1 argument", |
| 27 | }, |
| 28 | { |
| 29 | args: []string{"foo"}, |
| 30 | volumeInspectFunc: func(volumeID string) (client.VolumeInspectResult, error) { |
| 31 | return client.VolumeInspectResult{}, errors.New("error while inspecting the volume") |
| 32 | }, |
| 33 | expectedError: "error while inspecting the volume", |
| 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 | volumeInspectFunc: func(volumeID string) (client.VolumeInspectResult, error) { |
| 45 | if volumeID == "foo" { |
| 46 | return client.VolumeInspectResult{ |
| 47 | Volume: volume.Volume{ |
| 48 | Name: "foo", |
| 49 | }, |
| 50 | }, nil |
| 51 | } |
| 52 | return client.VolumeInspectResult{}, errors.New("error while inspecting the volume") |
| 53 | }, |
| 54 | expectedError: "error while inspecting the volume", |
| 55 | }, |
| 56 | } |
| 57 | for _, tc := range testCases { |
| 58 | cmd := newInspectCommand( |
| 59 | test.NewFakeCli(&fakeClient{ |
| 60 | volumeInspectFunc: tc.volumeInspectFunc, |
| 61 | }), |
| 62 | ) |
| 63 | cmd.SetArgs(tc.args) |
| 64 | for key, value := range tc.flags { |
| 65 | assert.Check(t, cmd.Flags().Set(key, value)) |
| 66 | } |
| 67 | cmd.SetOut(io.Discard) |
| 68 | cmd.SetErr(io.Discard) |
| 69 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestVolumeInspectWithoutFormat(t *testing.T) { |
| 74 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…