Skip to content

Commit

Permalink
refactor(cli): enhance grouping verification in `verifyReceiversGroup…
Browse files Browse the repository at this point in the history
…ing`

- 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 <[email protected]>
  • Loading branch information
heartwilltell committed Jan 20, 2025
1 parent 6e4384c commit a6fabf5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cli/test_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a6fabf5

Please sign in to comment.