Deflake TestVolumeCreateClusterOpts

Add Secret sorting prior to request to prevent flakiness in CI

Signed-off-by: Phong Tran <tran.pho@northeastern.edu>

Co-authored-by: Sebastiaan van Stijn <thaJeztah@users.noreply.github.com>
Signed-off-by: Phong Tran <tran.pho@northeastern.edu>
This commit is contained in:
Phong Tran 2022-05-31 18:52:00 +07:00 committed by Sebastiaan van Stijn
parent df3c2f171d
commit 1d85b4d0ec
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 8 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package volume
import (
"context"
"fmt"
"sort"
"strings"
"github.com/docker/cli/cli"
@ -153,6 +154,9 @@ func runCreate(dockerCli command.Cli, options createOptions) error {
},
)
}
sort.SliceStable(volOpts.ClusterVolumeSpec.Secrets, func(i, j int) bool {
return volOpts.ClusterVolumeSpec.Secrets[i].Key < volOpts.ClusterVolumeSpec.Secrets[j].Key
})
// TODO(dperny): ignore if no topology specified
topology := &volume.TopologyRequirement{}

View File

@ -3,6 +3,7 @@ package volume
import (
"io"
"reflect"
"sort"
"strings"
"testing"
@ -192,6 +193,9 @@ func TestVolumeCreateClusterOpts(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) {
sort.SliceStable(body.ClusterVolumeSpec.Secrets, func(i, j int) bool {
return body.ClusterVolumeSpec.Secrets[i].Key < body.ClusterVolumeSpec.Secrets[j].Key
})
assert.DeepEqual(t, body, expectedBody)
return volume.Volume{}, nil
},