Skip to content

Commit

Permalink
Merge pull request #319 from tienvx/match-string-value-using-content-…
Browse files Browse the repository at this point in the history
…type

fix: Allow matching string values using content type matching rule
  • Loading branch information
rholshausen authored Sep 21, 2023
2 parents e7b5cce + 63b7cf9 commit b6cb715
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit b6cb715

Please sign in to comment.