From b43c68bc9b909a31e55b674236872aa4ad097032 Mon Sep 17 00:00:00 2001 From: Alexander <39818795+QxBytes@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:34:59 -0800 Subject: [PATCH] test: sort npm set policy values before validation (#3358) * sort set policy values before validation * address linter issues * sort expected values --- .../ipsets/ipsetmanager_windows_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go index 252304cc8d..5d02040b46 100644 --- a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go +++ b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go @@ -1,7 +1,8 @@ package ipsets import ( - "fmt" + "sort" + "strings" "testing" "github.com/Azure/azure-container-networking/common" @@ -379,7 +380,19 @@ func verifyHNSCache(t *testing.T, expected map[string]hcn.SetPolicySetting, hns for setName, setObj := range expected { cacheObj := hns.Cache.SetPolicy(setObj.Id) require.NotNil(t, cacheObj) - require.Equal(t, setObj, *cacheObj, fmt.Sprintf("%s mismatch in cache", setName)) + + // make values always sorted for testing consistency + members := strings.Split(cacheObj.Values, ",") + sort.Strings(members) + copyOfCachedObj := *cacheObj + copyOfCachedObj.Values = strings.Join(members, ",") + + expectedMembers := strings.Split(setObj.Values, ",") + sort.Strings(expectedMembers) + copyOfExpectedObj := setObj + copyOfExpectedObj.Values = strings.Join(expectedMembers, ",") + + require.Equal(t, copyOfExpectedObj, copyOfCachedObj, setName+" mismatch in cache") } }