diff --git a/Makefile b/Makefile index 945c2c7..2715c8e 100644 --- a/Makefile +++ b/Makefile @@ -42,10 +42,10 @@ fake_ci_webhook: ## ===================== test: .env - docker compose up pact_verifier --exit-code-from pact_verifier + docker compose up pact_verifier --exit-code-from pact_verifier --build docker compose logs pact_verifier test_native: .env - docker compose up pact_verifier_native --exit-code-from pact_verifier_native + docker compose up pact_verifier_native --exit-code-from pact_verifier_native --build docker compose logs pact_verifier_native ## ===================== diff --git a/app/main.py b/app/main.py index f08e9b4..d9fe1ae 100644 --- a/app/main.py +++ b/app/main.py @@ -19,4 +19,24 @@ async def product(id: str, response: Response): return product response.status_code = 404 - return {} \ No newline at end of file + return {} + +@app.delete("/product/{id}") +async def delete_product(id: str, response: Response): + global catalog + catalog = [product for product in catalog if product["id"] != id] + response.status_code = 204 + return catalog + + +@app.post("/_pact/state") +async def change_state(request: dict, response: Response): + state = request.get("state") + print(state) + if state == "a product with ID 10 exists": + catalog.append({ "id": "10", "type": "CREDIT_CARD", "name": "Buy stuff without actually having money" }) + response.status_code = 200 + return {"result": "Product with ID 10 added"} + else: + response.status_code = 400 + return {"error": "Unknown state"} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 89a3418..c9057ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,12 +24,14 @@ services: - GIT_BRANCH command: > verify - ${PACT_URL} + /pacts/pactflow-example-consumer-python-pactflow-example-provider-python.json --provider-base-url http://api:8000 --provider pactflow-example-provider-python - --provider-app-version ${GIT_COMMIT} - --provider-version-branch ${GIT_BRANCH} + --log-level debug --wait 10 + --provider-states-setup-url http://api:8000/_pact/state + volumes: + - ./pacts_ruby:/pacts pact_verifier_native: image: pactfoundation/pact-ref-verifier:latest @@ -47,7 +49,10 @@ services: command: > --hostname api --port 8000 - --provider-name pactflow-example-provider-python + --provider-name pactflow-example-provider-python-v3 --loglevel info - --provider-version $GIT_COMMIT - --provider-branch $GIT_BRANCH \ No newline at end of file + --dir /pacts + --request-timeout 10000 + --state-change-url http://api:8000/_pact/state + volumes: + - ./pacts_rust:/pacts \ No newline at end of file diff --git a/pacts_ruby/pactflow-example-consumer-python-pactflow-example-provider-python.json b/pacts_ruby/pactflow-example-consumer-python-pactflow-example-provider-python.json new file mode 100644 index 0000000..b94dfdc --- /dev/null +++ b/pacts_ruby/pactflow-example-consumer-python-pactflow-example-provider-python.json @@ -0,0 +1,62 @@ +{ + "consumer": { + "name": "pactflow-example-consumer-python" + }, + "provider": { + "name": "pactflow-example-provider-python" + }, + "interactions": [ + { + "description": "a request to get a product", + "providerState": "a product with ID 10 exists", + "request": { + "method": "GET", + "path": "/product/10" + }, + "response": { + "status": 200, + "headers": { + }, + "body": { + "id": "27", + "name": "Margharita", + "type": "Pizza" + }, + "matchingRules": { + "$.body": { + "match": "type" + } + } + } + }, + { + "description": "a request to delete a product", + "providerState": "a product with ID 10 exists", + "request": { + "method": "DELETE", + "path": "/product/10", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "id": "27" + }, + "matchingRules": { + "$.body": { + "match": "type" + } + } + }, + "response": { + "status": 204, + "headers": { + } + } + } + ], + "metadata": { + "pactSpecification": { + "version": "2.0.0" + } + } +} \ No newline at end of file diff --git a/pacts_rust/pactflow-example-consumer-python-v3-pactflow-example-provider-python-v3.json b/pacts_rust/pactflow-example-consumer-python-v3-pactflow-example-provider-python-v3.json new file mode 100644 index 0000000..6f40c0a --- /dev/null +++ b/pacts_rust/pactflow-example-consumer-python-v3-pactflow-example-provider-python-v3.json @@ -0,0 +1,104 @@ +{ + "consumer": { + "name": "pactflow-example-consumer-python-v3" + }, + "interactions": [ + + { + "description": "a request to get a product", + "pending": false, + "providerStates": [ + { + "name": "a product with ID 10 exists" + } + ], + "request": { + "method": "GET", + "path": "/product/10" + }, + "response": { + "body": { + "content": { + "id": "27", + "name": "Margharita", + "type": "Pizza" + }, + "contentType": "application/json", + "encoded": false + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "matchingRules": { + "body": { + "$": { + "combine": "AND", + "matchers": [ + { + "match": "type" + } + ] + } + } + }, + "status": 200 + }, + "type": "Synchronous/HTTP" + }, + { + "description": "a request to delete a product", + "pending": false, + "providerStates": [ + { + "name": "a product with ID 10 exists" + } + ], + "request": { + "body": { + "content": { + "id": "27" + }, + "contentType": "application/json", + "encoded": false + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "matchingRules": { + "body": { + "$": { + "combine": "AND", + "matchers": [ + { + "match": "type" + } + ] + } + } + }, + "method": "DELETE", + "path": "/product/10" + }, + "response": { + "status": 204 + }, + "type": "Synchronous/HTTP" + } + ], + "metadata": { + "pactRust": { + "ffi": "0.4.22", + "models": "1.2.3" + }, + "pactSpecification": { + "version": "4.0" + } + }, + "provider": { + "name": "pactflow-example-provider-python-v3" + } +} \ No newline at end of file