Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add ability for users to define their own match rule(s) #30

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release

- New `byCustomRule` function to allow users to define their own matching rule when finding a matching interaction in a cassette
- Improve error messages when a matching interaction is not found (human-readable error messages)
- Fix bug where the base URL matching rule was not comparing the scheme, host, and port of the request URL properly

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/easypost/easyvcr/MatchRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ public MatchRules byMethod() {
return this;
}

/**
* Add a rule to compare two requests by a custom rule.
* @param rule A BiFunction that accepts two Request instances and returns true if they match, false otherwise.
* The first parameter is the current in-flight request,
* the second parameter is the recorded request from the current cassette.
* @return This MatchRules factory.
*/
public MatchRules byCustomRule(BiFunction<Request, Request, Boolean> rule) {
by(rule);
return this;
}

/**
* Execute rules to determine if the received request matches the recorded request.
*
Expand Down