-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #437 from YOU54F/fix/issue_389
fix: merge pact duplicates with diff desc/same prov state
- Loading branch information
Showing
11 changed files
with
1,063 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from cffi import FFI | ||
from register_ffi import get_ffi_lib | ||
import json | ||
import requests | ||
|
||
ffi = FFI() | ||
lib = get_ffi_lib(ffi) # loads the entire C namespace | ||
lib.pactffi_logger_init() | ||
lib.pactffi_log_to_stdout(3) | ||
|
||
pact = lib.pactffi_new_pact(b'merge-test-consumer', b'merge-test-provider-http') | ||
lib.pactffi_with_specification(pact, 5) | ||
interaction = lib.pactffi_new_interaction(pact, b'a request for an order with an unknown ID') | ||
lib.pactffi_with_request(interaction, b'GET', b'/api/orders/404') | ||
lib.pactffi_with_header_v2(interaction, 0,b'Accept', 0, b'application/json') | ||
lib.pactffi_response_status(interaction, 404) | ||
|
||
# Start mock server | ||
mock_server_port = lib.pactffi_create_mock_server_for_transport(pact , b'0.0.0.0',0, b'http', b'{}') | ||
print(f"Mock server started: {mock_server_port}") | ||
|
||
try: | ||
response = requests.get(f"http://127.0.0.1:{mock_server_port}/api/orders/404", | ||
headers={'Content-Type': 'application/json'}) | ||
response.raise_for_status() | ||
except requests.HTTPError as http_err: | ||
print(f'Client request - HTTP error occurred: {http_err}') # Python 3.6 | ||
except Exception as err: | ||
print(f'Client request - Other error occurred: {err}') # Python 3.6 | ||
|
||
result = lib.pactffi_mock_server_matched(mock_server_port) | ||
res_write_pact = lib.pactffi_write_pact_file(mock_server_port, './pacts'.encode('ascii'), False) | ||
|
||
## Cleanup | ||
lib.pactffi_cleanup_mock_server(mock_server_port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from cffi import FFI | ||
from register_ffi import get_ffi_lib | ||
import json | ||
import requests | ||
|
||
ffi = FFI() | ||
lib = get_ffi_lib(ffi) # loads the entire C namespace | ||
lib.pactffi_logger_init() | ||
lib.pactffi_log_to_stdout(3) | ||
message_pact = lib.pactffi_new_pact(b'merge-test-consumer', b'merge-test-provider-message') | ||
lib.pactffi_with_specification(message_pact, 5) | ||
message = lib.pactffi_new_message(message_pact, b'an event indicating that an order has been created') | ||
# lib.pactffi_message_expects_to_receive(message,b'Book (id fb5a885f-f7e8-4a50-950f-c1a64a94d500) created message') | ||
# lib.pactffi_message_given(message, b'A book with id fb5a885f-f7e8-4a50-950f-c1a64a94d500 is required') | ||
contents = { | ||
"id": { | ||
"pact:matcher:type": 'integer', | ||
"value": '1' | ||
} | ||
} | ||
length = len(json.dumps(contents)) | ||
size = length + 1 | ||
lib.pactffi_message_with_contents(message, b'application/json', ffi.new("char[]", json.dumps(contents).encode('ascii')), size) | ||
reified = lib.pactffi_message_reify(message) | ||
res_write_message_pact = lib.pactffi_write_message_pact_file(message_pact, './pacts'.encode('ascii'), False) | ||
print(res_write_message_pact) |
106 changes: 106 additions & 0 deletions
106
python/pacts/merge-test-consumer-merge-test-provider-http.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"consumer": { | ||
"name": "merge-test-consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a request for an order by ID", | ||
"pending": false, | ||
"providerStates": [ | ||
{ | ||
"name": "an order with ID {id} exists", | ||
"params": { | ||
"id": 1 | ||
} | ||
} | ||
], | ||
"request": { | ||
"headers": { | ||
"Accept": [ | ||
"application/json" | ||
] | ||
}, | ||
"method": "GET", | ||
"path": "/api/orders/1" | ||
}, | ||
"response": { | ||
"body": { | ||
"content": { | ||
"date": "2023-06-28T12:13:14.0000000+01:00", | ||
"id": 1, | ||
"status": "Pending" | ||
}, | ||
"contentType": "application/json", | ||
"encoded": false | ||
}, | ||
"headers": { | ||
"Content-Type": [ | ||
"application/json" | ||
] | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.date": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"$.id": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "integer" | ||
} | ||
] | ||
}, | ||
"$.status": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "Pending|Fulfilling|Shipped" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"status": 200 | ||
}, | ||
"type": "Synchronous/HTTP" | ||
}, | ||
{ | ||
"description": "a request for an order with an unknown ID", | ||
"pending": false, | ||
"request": { | ||
"headers": { | ||
"Accept": [ | ||
"application/json" | ||
] | ||
}, | ||
"method": "GET", | ||
"path": "/api/orders/404" | ||
}, | ||
"response": { | ||
"status": 404 | ||
}, | ||
"transport": "http", | ||
"type": "Synchronous/HTTP" | ||
} | ||
], | ||
"metadata": { | ||
"pactRust": { | ||
"ffi": "0.4.21", | ||
"mockserver": "1.2.8", | ||
"models": "1.2.1" | ||
}, | ||
"pactSpecification": { | ||
"version": "4.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "merge-test-provider-http" | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
python/pacts/merge-test-consumer-merge-test-provider-message.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"consumer": { | ||
"name": "merge-test-consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a request to update the status of an order", | ||
"pending": false, | ||
"providerStates": [ | ||
{ | ||
"name": "an order with ID {id} exists", | ||
"params": { | ||
"id": 1 | ||
} | ||
} | ||
], | ||
"request": { | ||
"body": { | ||
"content": "Fulfilling", | ||
"contentType": "application/json", | ||
"encoded": false | ||
}, | ||
"headers": { | ||
"Content-Type": [ | ||
"application/json" | ||
] | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "Pending|Fulfilling|Shipped" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"method": "PUT", | ||
"path": "/api/orders/1/status" | ||
}, | ||
"response": { | ||
"status": 204 | ||
}, | ||
"type": "Synchronous/HTTP" | ||
}, | ||
{ | ||
"contents": { | ||
"content": { | ||
"id": "1" | ||
}, | ||
"contentType": "application/json", | ||
"encoded": false | ||
}, | ||
"description": "an event indicating that an order has been created", | ||
"matchingRules": { | ||
"body": { | ||
"$.id": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "integer" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"pending": false, | ||
"type": "Asynchronous/Messages" | ||
} | ||
], | ||
"metadata": { | ||
"pactRust": { | ||
"ffi": "0.4.21", | ||
"models": "1.2.1" | ||
}, | ||
"pactSpecification": { | ||
"version": "4.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "merge-test-provider-message" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.