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

Function TestNewRemoveCommandErrors

cli/command/image/remove_test.go:35–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestNewRemoveCommandErrors(t *testing.T) {
36 testCases := []struct {
37 name string
38 args []string
39 expectedError string
40 imageRemoveFunc func(img string, options client.ImageRemoveOptions) (client.ImageRemoveResult, error)
41 }{
42 {
43 name: "wrong args",
44 expectedError: "requires at least 1 argument",
45 },
46 {
47 name: "ImageRemove fail with force option",
48 args: []string{"-f", "image1"},
49 expectedError: "error removing image",
50 imageRemoveFunc: func(img string, options client.ImageRemoveOptions) (client.ImageRemoveResult, error) {
51 assert.Check(t, is.Equal("image1", img))
52 return client.ImageRemoveResult{}, errors.New("error removing image")
53 },
54 },
55 {
56 name: "ImageRemove fail",
57 args: []string{"arg1"},
58 expectedError: "error removing image",
59 imageRemoveFunc: func(img string, options client.ImageRemoveOptions) (client.ImageRemoveResult, error) {
60 assert.Check(t, !options.Force)
61 assert.Check(t, options.PruneChildren)
62 return client.ImageRemoveResult{}, errors.New("error removing image")
63 },
64 },
65 }
66 for _, tc := range testCases {
67 t.Run(tc.name, func(t *testing.T) {
68 cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{
69 imageRemoveFunc: tc.imageRemoveFunc,
70 }))
71 cmd.SetOut(io.Discard)
72 cmd.SetErr(io.Discard)
73 cmd.SetArgs(nilToEmptySlice(tc.args))
74 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
75 })
76 }
77}
78
79func TestNewRemoveCommandSuccess(t *testing.T) {
80 testCases := []struct {

Callers

nothing calls this directly

Calls 5

nilToEmptySliceFunction · 0.85
SetArgsMethod · 0.80
newRemoveCommandFunction · 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…