Merge pull request #3520 from thaJeztah/fix_TestRemoveForce

fix race condition in TestRemoveForce
This commit is contained in:
Sebastiaan van Stijn 2022-04-08 16:53:11 +02:00 committed by GitHub
commit 78da8e3ef3
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) { func TestRemoveForce(t *testing.T) {
var removed []string var (
removed1 []string
removed2 []string
)
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerRemoveFunc: func(ctx context.Context, container string, options types.ContainerRemoveOptions) error { 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" { 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 return nil
}, },
@ -31,16 +35,16 @@ func TestRemoveForce(t *testing.T) {
t.Run("without force", func(t *testing.T) { t.Run("without force", func(t *testing.T) {
cmd.SetArgs([]string{"nosuchcontainer", "mycontainer"}) cmd.SetArgs([]string{"nosuchcontainer", "mycontainer"})
removed = []string{} removed1 = []string{}
assert.ErrorContains(t, cmd.Execute(), "No such container") assert.ErrorContains(t, cmd.Execute(), "no such container")
sort.Strings(removed) sort.Strings(removed1)
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"}) assert.DeepEqual(t, removed1, []string{"mycontainer", "nosuchcontainer"})
}) })
t.Run("with force", func(t *testing.T) { t.Run("with force", func(t *testing.T) {
cmd.SetArgs([]string{"--force", "nosuchcontainer", "mycontainer"}) cmd.SetArgs([]string{"--force", "nosuchcontainer", "mycontainer"})
removed = []string{} removed2 = []string{}
assert.NilError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
sort.Strings(removed) sort.Strings(removed2)
assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"}) assert.DeepEqual(t, removed2, []string{"mycontainer", "nosuchcontainer"})
}) })
} }