Skip to content

Commit

Permalink
test: add ruby/rust impl based DELETE reqs with body
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Nov 18, 2024
1 parent 37d695f commit e35cfba
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

## =====================
Expand Down
22 changes: 21 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ async def product(id: str, response: Response):
return product

response.status_code = 404
return {}
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"}
17 changes: 11 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
--dir /pacts
--request-timeout 10000
--state-change-url http://api:8000/_pact/state
volumes:
- ./pacts_rust:/pacts
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit e35cfba

Please sign in to comment.