Merge pull request #3753 from thaJeztah/20.10_backport_fix_TestRemoveForce

[20.10 backport] fix race condition in TestRemoveForce
This commit is contained in:
Sebastiaan van Stijn 2022-08-26 14:06:43 +02:00 committed by GitHub
commit fe0cdaf027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 10 deletions

View File

@ -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
},
@ -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"})
})
}