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

fix: Allow matching string values using content type matching rule #319

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions rust/pact_ffi/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,19 @@ mod tests {
let string = unsafe { CString::from_raw(err_result as *mut c_char) };
expect!(string.to_string_lossy()).to(be_equal_to("Failed to parse actual JSON: EOF while parsing a string at line 1 column 11"));
}

#[test_log::test]
fn pactffi_matches_string_value_using_content_type_matching_rule_test() {
let rule = MatchingRule::ContentType("text/plain".to_string());
let rule_ptr = &rule as *const MatchingRule;
let value = CString::new("testing").unwrap();

let exact_value = CString::new("testing").unwrap();
let exact_result = pactffi_matches_string_value(rule_ptr, value.as_ptr(), exact_value.as_ptr(), 0);
expect!(exact_result.is_null()).to(be_true());

let different_value = CString::new("testing_123").unwrap();
let different_result = pactffi_matches_string_value(rule_ptr, value.as_ptr(), different_value.as_ptr(), 0);
expect!(different_result.is_null()).to(be_true());
}
}
1 change: 1 addition & 0 deletions rust/pact_matching/src/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ impl Matches<&str> for &str {
Err(err) => Err(anyhow!("'{}' is not a valid semantic version - {}", actual, err))
}
}
MatchingRule::ContentType(content_type) => match_content_type(actual.as_bytes(), content_type),
_ => if !cascaded || matcher.can_cascade() {
Err(anyhow!("Unable to match '{}' using {:?}", self, matcher))
} else {
Expand Down