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

Function TestRemoveForce

cli/command/container/rm_test.go:16–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestRemoveForce(t *testing.T) {
17 for _, tc := range []struct {
18 name string
19 args []string
20 expectedErr string
21 }{
22 {name: "without force", args: []string{"nosuchcontainer", "mycontainer"}, expectedErr: "no such container"},
23 {name: "with force", args: []string{"--force", "nosuchcontainer", "mycontainer"}, expectedErr: ""},
24 } {
25 t.Run(tc.name, func(t *testing.T) {
26 var removed []string
27 mutex := new(sync.Mutex)
28
29 cli := test.NewFakeCli(&fakeClient{
30 containerRemoveFunc: func(ctx context.Context, container string, options client.ContainerRemoveOptions) (client.ContainerRemoveResult, error) {
31 // containerRemoveFunc is called in parallel for each container
32 // by the remove command so append must be synchronized.
33 mutex.Lock()
34 removed = append(removed, container)
35 mutex.Unlock()
36
37 if container == "nosuchcontainer" {
38 return client.ContainerRemoveResult{}, notFound(errors.New("Error: no such container: " + container))
39 }
40 return client.ContainerRemoveResult{}, nil
41 },
42 Version: "1.36",
43 })
44 cmd := newRmCommand(cli)
45 cmd.SetOut(io.Discard)
46 cmd.SetErr(io.Discard)
47 cmd.SetArgs(tc.args)
48
49 err := cmd.Execute()
50 if tc.expectedErr != "" {
51 assert.ErrorContains(t, err, tc.expectedErr)
52 } else {
53 assert.NilError(t, err)
54 }
55 sort.Strings(removed)
56 assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"})
57 })
58 }
59}

Callers

nothing calls this directly

Calls 5

newRmCommandFunction · 0.85
SetArgsMethod · 0.80
notFoundFunction · 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…