Skip to content

test(middleware/selector): add assertions for TestMatch and TestMatchClient#3811

Open
sevico wants to merge 1 commit into
go-kratos:mainfrom
sevico:test-selector-match
Open

test(middleware/selector): add assertions for TestMatch and TestMatchClient#3811
sevico wants to merge 1 commit into
go-kratos:mainfrom
sevico:test-selector-match

Conversation

@sevico
Copy link
Copy Markdown

@sevico sevico commented Apr 5, 2026

Summary

  • The existing TestMatch and TestMatchClient had test cases but lacked assertions — they only called the handler without verifying whether the middleware was actually applied based on matching rules.
  • Added a middlewareApplied flag and expected want field to each test case, verifying that Prefix, Regex, and Path matching rules work correctly for both server and client selectors.
  • Removed stale // TODO: Add test cases. comments.

Test plan

  • go test ./middleware/selector/ -v -run "TestMatch" passes
  • All existing tests in the package remain green

…Client

The existing TestMatch and TestMatchClient had test cases but lacked
assertions to verify whether the middleware was actually applied based
on the matching rules (Prefix, Regex, Path). This made the tests
unable to catch regressions in the selector matching logic.

Add a middlewareApplied flag and expected want field to each test case,
verifying that:
- Prefix("/hello/") matches operations starting with /hello/
- Regex(`/test/[0-9]+`) matches numeric test paths
- Path("/example/kratos") matches exact paths
- Non-matching operations are correctly skipped
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant