MCPcopy Index your code
hub / github.com/docker/cli / TestNewPruneCommandErrors

Function TestNewPruneCommandErrors

cli/command/image/prune_test.go:19–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewPruneCommandErrors(t *testing.T) {
20 testCases := []struct {
21 name string
22 args []string
23 expectedError string
24 imagePruneFunc func(client.ImagePruneOptions) (client.ImagePruneResult, error)
25 }{
26 {
27 name: "wrong-args",
28 args: []string{"something"},
29 expectedError: "accepts no arguments",
30 },
31 {
32 name: "prune-error",
33 args: []string{"--force"},
34 expectedError: "something went wrong",
35 imagePruneFunc: func(client.ImagePruneOptions) (client.ImagePruneResult, error) {
36 return client.ImagePruneResult{}, errors.New("something went wrong")
37 },
38 },
39 }
40 for _, tc := range testCases {
41 t.Run(tc.name, func(t *testing.T) {
42 cmd := newPruneCommand(test.NewFakeCli(&fakeClient{
43 imagePruneFunc: tc.imagePruneFunc,
44 }))
45 cmd.SetOut(io.Discard)
46 cmd.SetErr(io.Discard)
47 cmd.SetArgs(tc.args)
48 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
49 })
50 }
51}
52
53func TestNewPruneCommandSuccess(t *testing.T) {
54 testCases := []struct {

Callers

nothing calls this directly

Calls 4

SetArgsMethod · 0.80
newPruneCommandFunction · 0.70
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…