Comments (7)
Yes sure. There might be a caveat though where v2 is full on concurrency focused. Changes the set up and structure of pact tests.
Make sure that v2 fits your needs first.
from pactswift.
Just noticed that arrayContaining method is implemented in v3, are there any chances that we could easily add that matcher without v4 ?
from pactswift.
I was able to implement some sort of arrayContains
matcher in my fork. Response generation is ok, and also i tried to add matching rule by doing this:
processedMatcherValue.rules[${node_with_array_contains}] = AnyEncodable([
"matchers": [
"match": AnyEncodable("arrayContains"),
"variants": AnyEncodable(${all_processed_variants})
]
])
but arrayContains
matching rules wont appear in output pact contact in case of the tests with mock server. (Encoding logic looks fine in PactBuilderTests)
PactBuilderTests:
let testBody: Any = [
"data": [
"foo": Matcher.ContainsLike([
[
"bar": Matcher.SomethingLike("string1")
],
[
"baz": Matcher.SomethingLike("string2")
]
], useAllValues: true)
]
]
Generated JSON: (Do we really need to duplicate internal array $.data.foo
matchers if they are already located in the variants
value? Or real expected values should be used instead of matcher rules in the variants
key?)
matchingRules = {
body = {
"$.data.foo" = {
matchers = {
match = arrayContains;
variants = {
"$.data.foo[0].bar" = {
matchers = (
{
match = type;
}
);
};
"$.data.foo[1].baz" = {
matchers = (
{
match = type;
}
);
};
};
};
};
"$.data.foo[0].bar" = {
matchers = (
{
match = type;
}
);
};
"$.data.foo[1].baz" = {
matchers = (
{
match = type;
}
);
};
};
};
But the final pact contacts doesn't include $.data.foo
matching rules (Problem is in json format i guess, but I could not find any pact example with arrayContains
matcher).
{
"description": "Request for a an object with simpler contains like matcher",
"providerStates": [
{
"name": "dynamic json"
}
],
"request": {
"method": "GET",
"path": "/articles/simpler/containsLikeMatcher"
},
"response": {
"body": {
"foo": [
{
"bar": {
"key1": "value1",
"key2": 123
}
},
{
"baz": {
"key3": "value2",
"key4": 456
}
}
]
},
"matchingRules": {
"body": {
"$.foo[0].bar.key1": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.foo[0].bar.key2": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.foo[1].baz.key3": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.foo[1].baz.key4": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
},
"status": 200
}
Data that passed into mock server also looks ok
from pactswift.
Finally, got the example of arrayContains
rule using pact_mock_server_cli
. Will refactor matcher processing to match the appropriate format
"$.baz": {
"combine": "AND",
"matchers": [
{
"match": "arrayContains",
"variants": [
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
},
{
"index": 0,
"rules": {
"": {
"combine": "AND",
"matchers": [
{
"match": "equality"
}
]
}
}
}
]
}
]
}
from pactswift.
Final results.
One of the tests:
![Screenshot 2023-07-25 at 17 55 05](https://private-user-images.githubusercontent.com/39913650/255959768-e15f4423-401f-4666-b465-aa1a2923fd41.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyOTg2MjQsIm5iZiI6MTcxOTI5ODMyNCwicGF0aCI6Ii8zOTkxMzY1MC8yNTU5NTk3NjgtZTE1ZjQ0MjMtNDAxZi00NjY2LWI0NjUtYWExYTI5MjNmZDQxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI1VDA2NTIwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg3YTI4NTA3OTg0N2UxZDc3YmVjZGU1MjY0NTU0NTA4MTI3ZjFhMDM5NDRjYjhlMWQ1ODA1MGZlZmU3M2NjODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.eWRHUKPlrqh8BT6Zfj8ejNtNH6P6lQsPKy_ZlTY9-IU)
Generated JSON
{
"description": "Request for a an object with contains like matcher",
"providerStates": [
{
"name": "dynamic json"
}
],
"request": {
"method": "GET",
"path": "/articles/simpler/containsLikeMatcher"
},
"response": {
"body": {
"foo": {
"bar": {
"key1": "value1",
"key2": 123
}
}
},
"matchingRules": {
"body": {
"$.foo": {
"combine": "AND",
"matchers": [
{
"match": "arrayContains",
"variants": [
{
"index": 0,
"rules": {
"bar.key1": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"bar.key2": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
},
{
"index": 1,
"rules": {
"baz.key3": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"baz.key4": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
}
]
}
]
}
}
},
"status": 200
}
from pactswift.
Hey @StasMarynych
Sorry for late reply. I'm unfortunately quite far away from GitHub lately. I saw your closed PR, what happened there?
I've pulled the fork that refactored and massively rebased PactSwift code to take advantage of libpact_ffi
more.
Changes are on this branch https://github.com/surpher/PactSwift/tree/feat/v2.0.0 and it has full on support for modern swift concurrency.
from pactswift.
Hey @surpher , thats totally fine) np
That mr was opened by the accident actually. Firstly, I wanted to be sure that current version of libpact_ffi that is in PactSwiftMockServer package supports that new type of matcher at all. Now, I see that everything is ok. So, if there is no arrayContains
matcher in https://github.com/surpher/PactSwift/tree/feat/v2.0.0 would it be better to create the MR based on this branch?
from pactswift.
Related Issues (20)
- Support Cocoapods along side Carthage and SPM HOT 1
- Question: Is it possible to use generators in requests? HOT 4
- Question: Rest vs GraphQL services HOT 3
- Reporting a vulnerability
- Question: What about Pact Specification v4? HOT 2
- Surface interaction mismatches to the test running the validation
- Support matchers and example generators in requests
- Task: Clean up tests and Linux specific code HOT 1
- Task: Unit tests for swift concurrency refactor HOT 4
- Task: Proof of concept using Pact plugins
- Task: Find a way to reduce PactSwiftMockServer repo size HOT 1
- Create new release with concurrency support HOT 3
- Allow to merge with existing pact file HOT 2
- Question: Create PACT for JSON body that contains only a string HOT 4
- Unable to run real device -- Pactconsumer HOT 1
- Unable to run real device — Pactswift HOT 2
- PactSwift how to build on CI HOT 3
- Rules defined on the mock services aren't all written to the generated pact contract. HOT 6
- Feature Request: Add Ability to Pass Custom Header for Verification HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pactswift.