libnet: de-flake TestNetworkStore

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton
2025-04-07 15:07:37 +02:00
parent 1c79c893b1
commit 40650c6982

View File

@@ -3,6 +3,7 @@ package libnetwork
import (
"context"
"slices"
"strings"
"testing"
"github.com/docker/docker/libnetwork/config"
@@ -25,16 +26,6 @@ func TestNetworkStore(t *testing.T) {
err = c.storeNetwork(context.Background(), nw2)
assert.NilError(t, err)
netSorter := func(a, b *Network) int {
if a.name < b.name {
return -1
}
if a.name > b.name {
return 1
}
return 0
}
for _, tc := range []struct {
name string
filter func(nw *Network) bool
@@ -54,9 +45,9 @@ func TestNetworkStore(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
found := c.findNetworks(tc.filter)
assert.Equal(t, len(found), len(tc.expNetworks))
slices.SortFunc(found, netSorter)
slices.SortFunc(found, func(a, b *Network) int { return strings.Compare(a.id, b.id) })
for i, nw := range tc.expNetworks {
assert.Check(t, found[i] == nw, "got: %s; expected: %s", found[i].name, nw.name)
assert.Check(t, found[i] == nw, "got: %s; expected: %s", found[i].id, nw.id)
}
})
}