Skip to content

Commit e35cfba

Browse files
committed
test: add ruby/rust impl based DELETE reqs with body
1 parent 37d695f commit e35cfba

5 files changed

+200
-9
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ fake_ci_webhook:
4242
## =====================
4343

4444
test: .env
45-
docker compose up pact_verifier --exit-code-from pact_verifier
45+
docker compose up pact_verifier --exit-code-from pact_verifier --build
4646
docker compose logs pact_verifier
4747
test_native: .env
48-
docker compose up pact_verifier_native --exit-code-from pact_verifier_native
48+
docker compose up pact_verifier_native --exit-code-from pact_verifier_native --build
4949
docker compose logs pact_verifier_native
5050

5151
## =====================

app/main.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,24 @@ async def product(id: str, response: Response):
1919
return product
2020

2121
response.status_code = 404
22-
return {}
22+
return {}
23+
24+
@app.delete("/product/{id}")
25+
async def delete_product(id: str, response: Response):
26+
global catalog
27+
catalog = [product for product in catalog if product["id"] != id]
28+
response.status_code = 204
29+
return catalog
30+
31+
32+
@app.post("/_pact/state")
33+
async def change_state(request: dict, response: Response):
34+
state = request.get("state")
35+
print(state)
36+
if state == "a product with ID 10 exists":
37+
catalog.append({ "id": "10", "type": "CREDIT_CARD", "name": "Buy stuff without actually having money" })
38+
response.status_code = 200
39+
return {"result": "Product with ID 10 added"}
40+
else:
41+
response.status_code = 400
42+
return {"error": "Unknown state"}

docker-compose.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ services:
2424
- GIT_BRANCH
2525
command: >
2626
verify
27-
${PACT_URL}
27+
/pacts/pactflow-example-consumer-python-pactflow-example-provider-python.json
2828
--provider-base-url http://api:8000
2929
--provider pactflow-example-provider-python
30-
--provider-app-version ${GIT_COMMIT}
31-
--provider-version-branch ${GIT_BRANCH}
30+
--log-level debug
3231
--wait 10
32+
--provider-states-setup-url http://api:8000/_pact/state
33+
volumes:
34+
- ./pacts_ruby:/pacts
3335

3436
pact_verifier_native:
3537
image: pactfoundation/pact-ref-verifier:latest
@@ -47,7 +49,10 @@ services:
4749
command: >
4850
--hostname api
4951
--port 8000
50-
--provider-name pactflow-example-provider-python
52+
--provider-name pactflow-example-provider-python-v3
5153
--loglevel info
52-
--provider-version $GIT_COMMIT
53-
--provider-branch $GIT_BRANCH
54+
--dir /pacts
55+
--request-timeout 10000
56+
--state-change-url http://api:8000/_pact/state
57+
volumes:
58+
- ./pacts_rust:/pacts
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"consumer": {
3+
"name": "pactflow-example-consumer-python"
4+
},
5+
"provider": {
6+
"name": "pactflow-example-provider-python"
7+
},
8+
"interactions": [
9+
{
10+
"description": "a request to get a product",
11+
"providerState": "a product with ID 10 exists",
12+
"request": {
13+
"method": "GET",
14+
"path": "/product/10"
15+
},
16+
"response": {
17+
"status": 200,
18+
"headers": {
19+
},
20+
"body": {
21+
"id": "27",
22+
"name": "Margharita",
23+
"type": "Pizza"
24+
},
25+
"matchingRules": {
26+
"$.body": {
27+
"match": "type"
28+
}
29+
}
30+
}
31+
},
32+
{
33+
"description": "a request to delete a product",
34+
"providerState": "a product with ID 10 exists",
35+
"request": {
36+
"method": "DELETE",
37+
"path": "/product/10",
38+
"headers": {
39+
"Content-Type": "application/json"
40+
},
41+
"body": {
42+
"id": "27"
43+
},
44+
"matchingRules": {
45+
"$.body": {
46+
"match": "type"
47+
}
48+
}
49+
},
50+
"response": {
51+
"status": 204,
52+
"headers": {
53+
}
54+
}
55+
}
56+
],
57+
"metadata": {
58+
"pactSpecification": {
59+
"version": "2.0.0"
60+
}
61+
}
62+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"consumer": {
3+
"name": "pactflow-example-consumer-python-v3"
4+
},
5+
"interactions": [
6+
7+
{
8+
"description": "a request to get a product",
9+
"pending": false,
10+
"providerStates": [
11+
{
12+
"name": "a product with ID 10 exists"
13+
}
14+
],
15+
"request": {
16+
"method": "GET",
17+
"path": "/product/10"
18+
},
19+
"response": {
20+
"body": {
21+
"content": {
22+
"id": "27",
23+
"name": "Margharita",
24+
"type": "Pizza"
25+
},
26+
"contentType": "application/json",
27+
"encoded": false
28+
},
29+
"headers": {
30+
"Content-Type": [
31+
"application/json"
32+
]
33+
},
34+
"matchingRules": {
35+
"body": {
36+
"$": {
37+
"combine": "AND",
38+
"matchers": [
39+
{
40+
"match": "type"
41+
}
42+
]
43+
}
44+
}
45+
},
46+
"status": 200
47+
},
48+
"type": "Synchronous/HTTP"
49+
},
50+
{
51+
"description": "a request to delete a product",
52+
"pending": false,
53+
"providerStates": [
54+
{
55+
"name": "a product with ID 10 exists"
56+
}
57+
],
58+
"request": {
59+
"body": {
60+
"content": {
61+
"id": "27"
62+
},
63+
"contentType": "application/json",
64+
"encoded": false
65+
},
66+
"headers": {
67+
"Content-Type": [
68+
"application/json"
69+
]
70+
},
71+
"matchingRules": {
72+
"body": {
73+
"$": {
74+
"combine": "AND",
75+
"matchers": [
76+
{
77+
"match": "type"
78+
}
79+
]
80+
}
81+
}
82+
},
83+
"method": "DELETE",
84+
"path": "/product/10"
85+
},
86+
"response": {
87+
"status": 204
88+
},
89+
"type": "Synchronous/HTTP"
90+
}
91+
],
92+
"metadata": {
93+
"pactRust": {
94+
"ffi": "0.4.22",
95+
"models": "1.2.3"
96+
},
97+
"pactSpecification": {
98+
"version": "4.0"
99+
}
100+
},
101+
"provider": {
102+
"name": "pactflow-example-provider-python-v3"
103+
}
104+
}

0 commit comments

Comments
 (0)