Skip to content

Commit 78da8e3

Browse files
authored
Merge pull request #3520 from thaJeztah/fix_TestRemoveForce
fix race condition in TestRemoveForce
2 parents 2784bb5 + 9688f62 commit 78da8e3

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

cli/command/container/rm_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ import (
1414
)
1515

1616
func TestRemoveForce(t *testing.T) {
17-
var removed []string
17+
var (
18+
removed1 []string
19+
removed2 []string
20+
)
1821

1922
cli := test.NewFakeCli(&fakeClient{
2023
containerRemoveFunc: func(ctx context.Context, container string, options types.ContainerRemoveOptions) error {
21-
removed = append(removed, container)
24+
removed1 = append(removed1, container)
25+
removed2 = append(removed2, container)
2226
if container == "nosuchcontainer" {
23-
return errdefs.NotFound(fmt.Errorf("Error: No such container: " + container))
27+
return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container))
2428
}
2529
return nil
2630
},
@@ -31,16 +35,16 @@ func TestRemoveForce(t *testing.T) {
3135

3236
t.Run("without force", func(t *testing.T) {
3337
cmd.SetArgs([]string{"nosuchcontainer", "mycontainer"})
34-
removed = []string{}
35-
assert.ErrorContains(t, cmd.Execute(), "No such container")
36-
sort.Strings(removed)
37-
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"})
38+
removed1 = []string{}
39+
assert.ErrorContains(t, cmd.Execute(), "no such container")
40+
sort.Strings(removed1)
41+
assert.DeepEqual(t, removed1, []string{"mycontainer", "nosuchcontainer"})
3842
})
3943
t.Run("with force", func(t *testing.T) {
4044
cmd.SetArgs([]string{"--force", "nosuchcontainer", "mycontainer"})
41-
removed = []string{}
45+
removed2 = []string{}
4246
assert.NilError(t, cmd.Execute())
43-
sort.Strings(removed)
44-
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"})
47+
sort.Strings(removed2)
48+
assert.DeepEqual(t, removed2, []string{"mycontainer", "nosuchcontainer"})
4549
})
4650
}

0 commit comments

Comments
 (0)