(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…