MCPcopy Create free account
hub / github.com/docker/cli / TestVolumePruneErrors

Function TestVolumePruneErrors

cli/command/volume/prune_test.go:22–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func 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
72func TestVolumePruneSuccess(t *testing.T) {
73 testCases := []struct {

Callers

nothing calls this directly

Calls 5

SetArgsMethod · 0.80
newPruneCommandFunction · 0.70
SetMethod · 0.45
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…