(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestVolumePruneErrors(t *testing.T) { |
| 23 | testCases := []struct { |
| 24 | name string |
| 25 | args []string |
| 26 | flags map[string]string |
| 27 | pruneFunc func(client.VolumePruneOptions) (client.VolumePruneResult, error) |
| 28 | expectedError string |
| 29 | }{ |
| 30 | { |
| 31 | name: "accepts no arguments", |
| 32 | args: []string{"foo"}, |
| 33 | expectedError: "accepts no argument", |
| 34 | }, |
| 35 | { |
| 36 | name: "forced but other error", |
| 37 | flags: map[string]string{ |
| 38 | "force": "true", |
| 39 | }, |
| 40 | pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) { |
| 41 | return client.VolumePruneResult{}, errors.New("error pruning volumes") |
| 42 | }, |
| 43 | expectedError: "error pruning volumes", |
| 44 | }, |
| 45 | { |
| 46 | name: "conflicting options", |
| 47 | flags: map[string]string{ |
| 48 | "all": "true", |
| 49 | "filter": "all=1", |
| 50 | }, |
| 51 | expectedError: "conflicting options: cannot specify both --all and --filter all=1", |
| 52 | }, |
| 53 | } |
| 54 | for _, tc := range testCases { |
| 55 | t.Run(tc.name, func(t *testing.T) { |
| 56 | cmd := newPruneCommand( |
| 57 | test.NewFakeCli(&fakeClient{ |
| 58 | volumePruneFunc: tc.pruneFunc, |
| 59 | }), |
| 60 | ) |
| 61 | cmd.SetArgs(tc.args) |
| 62 | for key, value := range tc.flags { |
| 63 | 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 | |
| 72 | func TestVolumePruneSuccess(t *testing.T) { |
| 73 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…