-
Notifications
You must be signed in to change notification settings - Fork 46
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: update content_type_matching logic for binary payloads #429
feat: update content_type_matching logic for binary payloads #429
Conversation
Looks like infer will handle the most common types, but it has all the checks build in in Rust code, not config, so it is not extensible and will not be able to detect new types unless the crate is updated. So having tree_magic as a fallback is probably a good idea. |
compatibility-suite/pact-compatibility-suite/features/V3/matching_rules.feature
Outdated
Show resolved
Hide resolved
- use updated tree_magic with merged fix for apple silicon
… with application/json body
…ted, before we match
👋🏾 Tagged a few of you for review! Always room for improvement on what is proposed but this gives us
The compatibility suite has been updated to test cross platform (windows x86_64 + macos x86_64/arm64 ) and skipped tests for windows have been been re-instated 👍🏾 Happy to make any amendments, as I know this might not be the best solution, especially with respect to my coding style, or the overall (existing) approach to matching in this function, but please be reminded this is a massive improvement over our existing confusing behaviour, and we can always progress forwards. |
@@ -30,7 +30,7 @@ itertools = "0.12.1" | |||
lazy_static = "1.4.0" | |||
maplit = "1.0.2" | |||
pact_matching = { version = "~1.2.2", path = "../pact_matching", default-features = false } | |||
pact_mock_server = { version = "~1.2.6", default-features = false } | |||
pact_mock_server = { version = "=1.2.8", default-features = false, git = "https://github.com/you54f/pact-core-mock-server.git", branch = "main" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update to released pact_mock_server, when pact_matching is released, and pact_mock_server updated to reference released crate
@@ -31,7 +31,8 @@ maplit = "1.0.2" | |||
multipart = { version = "0.18.0", default-features = false, features = ["client", "mock"] } | |||
onig = { version = "6.4.0", default-features = false } | |||
pact_matching = { version = "~1.2.2", path = "../pact_matching" } | |||
pact_mock_server = { version = "~1.2.6" } | |||
pact_mock_server = { version = "=1.2.8", git = "https://github.com/you54f/pact-core-mock-server.git", branch = "main" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update to released pact_mock_server, when pact_matching is released, and pact_mock_server updated to reference released crate
@@ -31,7 +31,8 @@ maplit = "1.0.2" | |||
multipart = { version = "0.18.0", default-features = false, features = ["client", "mock"] } | |||
onig = { version = "6.4.0", default-features = false } | |||
pact_matching = { version = "~1.2.2", path = "../pact_matching" } | |||
pact_mock_server = { version = "~1.2.6" } | |||
pact_mock_server = { version = "=1.2.8", git = "https://github.com/you54f/pact-core-mock-server.git", branch = "main" } | |||
# pact_mock_server = { version = "=1.2.8", path = "../../../pact-core-mock-server/pact_mock_server" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path useful for dev guidelines if users are working across both repos locally.
.
├── pact-core-mock-server
└── pact-reference
Just a note, if you want to override a dependency, the easiest way is to use the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I wonder: since this PR is merged, when can we revert custom changes related to the pact_mock_server
?
1. MagicDB is not shipped with pact_matching, due to GPL restrictions, users can add manually | ||
1. Linux Alpine - `apk add shared-mime-info` | ||
2. MacOS `brew install shared-mime-info` | ||
1. `arm64` MacOS requires `tree_magic_mini` [fork](https://github.com/you54f/tree_magic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a new version has been released v3.1.5
, and this fork is no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has been yes! i need to update that comment to reflect, we are consuming 3.1.5 in here now
Two tests are failing on Windows: https://github.com/pact-foundation/pact-reference/actions/runs/9295821959/job/25583357274 |
All good. Mock server is using the old pact matching. Updated it and ran the tests on Windows, all pass. |
fixes #171
Content Type - Detection Mechanisms for Binary Content
pact_matching
now performs the following for matching Binary content-typesexpected
Content-Type
header requested by user in testinfer
library, and guessContent-Type
based on magic bytestree_magic_mini
library, and guessContent-Type
based on shared-mime-info DBapk add shared-mime-info
brew install shared-mime-info
arm64
MacOS requirestree_magic_mini
forkapt-get install -y shared-mime-info
text/plain
, then manually read bytes usingdetect_content_type_from_bytes
function inpact_models
2
,3
, or4
fails, then throw error, otherwise returnOk
certainly better ways to implement this, but wanted to make sure I had a full round trip in all the consuming languages, and could remove the content-type hacks there.
The plus side is we have consistent behaviour in all of our test examples, on all supported platforms and architectures (win/lin/mac arm64 and amd64) without the use of tree_magic and the existence of shared-mime-info (which is great for container users, and great for avoiding GPL woes)
Rust libraries used:
Questions
Notes to merger
Tested in