From 88b026430ad2aac64c9ce194f0c5c0ec994e1b62 Mon Sep 17 00:00:00 2001 From: Serhii Mariiekha Date: Mon, 20 Jan 2025 23:29:12 +0100 Subject: [PATCH] refactor(cli): enhance grouping verification in `verifyReceiversGrouping` - Improved the logic for matching actual groupings against expected ones by sorting both expected and actual groups before comparison. - Added comments for clarity, ensuring that the purpose of each step in the verification process is well-documented. - This update enhances the accuracy and readability of the receiver grouping verification process in the routing test command. Signed-off-by: heartwilltell --- cli/test_routing.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/test_routing.go b/cli/test_routing.go index f1f501a03f..cf97fcf162 100644 --- a/cli/test_routing.go +++ b/cli/test_routing.go @@ -276,15 +276,22 @@ func verifyReceiversGrouping(receiversGrouping map[string][]string, finalRoutes receiver := route.RouteOpts.Receiver actualGroups := sortGroupLabels(route.RouteOpts.GroupBy) - // Skip if no grouping expectations for this receiver + // Skip if no grouping expectations for this receiver. if _, exists := expectedGroupings[receiver]; !exists { continue } - // Try to match with any of the expected groupings + // Try to match with any of the expected groupings. matched := false + for _, expectedGroups := range expectedGroupings[receiver] { - if slices.Equal[[]string](expectedGroups, actualGroups) { + sortedExpected := slices.Clone(expectedGroups) + sortedActual := slices.Clone(actualGroups) + + slices.Sort[[]string](sortedExpected) + slices.Sort[[]string](sortedActual) + + if slices.Equal(sortedExpected, sortedActual) { matched = true break }