Skip to content

Commit

Permalink
Merge pull request #3753 from thaJeztah/20.10_backport_fix_TestRemove…
Browse files Browse the repository at this point in the history
…Force

[20.10 backport] fix race condition in TestRemoveForce
  • Loading branch information
thaJeztah committed Aug 26, 2022
2 parents 0785bd7 + 6b25bc3 commit fe0cdaf
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cli/command/container/rm_test.go
Expand Up @@ -14,13 +14,17 @@ import (
)

func TestRemoveForce(t *testing.T) {
var removed []string
var (
removed1 []string
removed2 []string
)

cli := test.NewFakeCli(&fakeClient{
containerRemoveFunc: func(ctx context.Context, container string, options types.ContainerRemoveOptions) error {
removed = append(removed, container)
removed1 = append(removed1, container)
removed2 = append(removed2, container)
if container == "nosuchcontainer" {
return errdefs.NotFound(fmt.Errorf("Error: No such container: " + container))
return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container))
}
return nil
},
Expand All @@ -31,16 +35,16 @@ func TestRemoveForce(t *testing.T) {

t.Run("without force", func(t *testing.T) {
cmd.SetArgs([]string{"nosuchcontainer", "mycontainer"})
removed = []string{}
assert.ErrorContains(t, cmd.Execute(), "No such container")
sort.Strings(removed)
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"})
removed1 = []string{}
assert.ErrorContains(t, cmd.Execute(), "no such container")
sort.Strings(removed1)
assert.DeepEqual(t, removed1, []string{"mycontainer", "nosuchcontainer"})
})
t.Run("with force", func(t *testing.T) {
cmd.SetArgs([]string{"--force", "nosuchcontainer", "mycontainer"})
removed = []string{}
removed2 = []string{}
assert.NilError(t, cmd.Execute())
sort.Strings(removed)
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"})
sort.Strings(removed2)
assert.DeepEqual(t, removed2, []string{"mycontainer", "nosuchcontainer"})
})
}

0 comments on commit fe0cdaf

Please sign in to comment.