| 70 | } |
| 71 | |
| 72 | func TestVolumePruneSuccess(t *testing.T) { |
| 73 | testCases := []struct { |
| 74 | name string |
| 75 | args []string |
| 76 | input string |
| 77 | pruneFunc func(client.VolumePruneOptions) (client.VolumePruneResult, error) |
| 78 | }{ |
| 79 | { |
| 80 | name: "all", |
| 81 | args: []string{"--all"}, |
| 82 | input: "y", |
| 83 | pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) { |
| 84 | assert.Check(t, is.DeepEqual(opts.Filters["all"], map[string]bool{"true": true})) |
| 85 | return client.VolumePruneResult{}, nil |
| 86 | }, |
| 87 | }, |
| 88 | { |
| 89 | name: "all-forced", |
| 90 | args: []string{"--all", "--force"}, |
| 91 | pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) { |
| 92 | return client.VolumePruneResult{}, nil |
| 93 | }, |
| 94 | }, |
| 95 | { |
| 96 | name: "label-filter", |
| 97 | args: []string{"--filter", "label=foobar"}, |
| 98 | input: "y", |
| 99 | pruneFunc: func(opts client.VolumePruneOptions) (client.VolumePruneResult, error) { |
| 100 | assert.Check(t, is.DeepEqual(opts.Filters["label"], map[string]bool{"foobar": true})) |
| 101 | return client.VolumePruneResult{}, nil |
| 102 | }, |
| 103 | }, |
| 104 | } |
| 105 | for _, tc := range testCases { |
| 106 | t.Run(tc.name, func(t *testing.T) { |
| 107 | cli := test.NewFakeCli(&fakeClient{volumePruneFunc: tc.pruneFunc}) |
| 108 | cmd := newPruneCommand(cli) |
| 109 | if tc.input != "" { |
| 110 | cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(tc.input)))) |
| 111 | } |
| 112 | cmd.SetOut(io.Discard) |
| 113 | cmd.SetArgs(tc.args) |
| 114 | err := cmd.Execute() |
| 115 | assert.NilError(t, err) |
| 116 | golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-prune-success.%s.golden", tc.name)) |
| 117 | }) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func TestVolumePruneForce(t *testing.T) { |
| 122 | testCases := []struct { |