From 55c11587ad4dabdd6c7db728d72976df81c2aa7f Mon Sep 17 00:00:00 2001 From: QxBytes Date: Tue, 21 Jan 2025 11:06:46 -0800 Subject: [PATCH 1/3] sort set policy values before validation --- npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go index 252304cc8d..4f5bb41c2f 100644 --- a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go +++ b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go @@ -2,6 +2,8 @@ package ipsets import ( "fmt" + "sort" + "strings" "testing" "github.com/Azure/azure-container-networking/common" @@ -379,7 +381,14 @@ 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, ",") + + require.Equal(t, setObj, copyOfCachedObj, fmt.Sprintf("%s mismatch in cache", setName)) } } From e11864aa26298d808f6bfeea05b5cbc2e155b10d Mon Sep 17 00:00:00 2001 From: QxBytes Date: Tue, 21 Jan 2025 11:39:01 -0800 Subject: [PATCH 2/3] address linter issues --- npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go index 4f5bb41c2f..02cf9c5a4f 100644 --- a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go +++ b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go @@ -1,7 +1,6 @@ package ipsets import ( - "fmt" "sort" "strings" "testing" @@ -388,7 +387,7 @@ func verifyHNSCache(t *testing.T, expected map[string]hcn.SetPolicySetting, hns copyOfCachedObj := *cacheObj copyOfCachedObj.Values = strings.Join(members, ",") - require.Equal(t, setObj, copyOfCachedObj, fmt.Sprintf("%s mismatch in cache", setName)) + require.Equal(t, setObj, copyOfCachedObj, setName+" mismatch in cache") } } From 34ee01b7d8a60aadd5050585a943edfc997d04c4 Mon Sep 17 00:00:00 2001 From: QxBytes Date: Tue, 21 Jan 2025 13:41:18 -0800 Subject: [PATCH 3/3] sort expected values --- npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go index 02cf9c5a4f..5d02040b46 100644 --- a/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go +++ b/npm/pkg/dataplane/ipsets/ipsetmanager_windows_test.go @@ -387,7 +387,12 @@ func verifyHNSCache(t *testing.T, expected map[string]hcn.SetPolicySetting, hns copyOfCachedObj := *cacheObj copyOfCachedObj.Values = strings.Join(members, ",") - require.Equal(t, setObj, copyOfCachedObj, setName+" mismatch in cache") + expectedMembers := strings.Split(setObj.Values, ",") + sort.Strings(expectedMembers) + copyOfExpectedObj := setObj + copyOfExpectedObj.Values = strings.Join(expectedMembers, ",") + + require.Equal(t, copyOfExpectedObj, copyOfCachedObj, setName+" mismatch in cache") } }