Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions javascript/packages/tv-shows-api/pact/provider_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ startMockServer().then(() => {
pactBrokerUrl: 'http://localhost',
publishVerificationResult: true,
providerVersion: packageJson.version,
stateHandlers: {
['a tv show exists']: () => {},
['provider allows tv show creation']: () => {},
},
}

new Verifier(opts).verifyProvider().then(function () {
Expand Down
28 changes: 14 additions & 14 deletions pact-broker/ssl/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ server {
}
}

server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/cert/pact_cert.pem;
ssl_certificate_key /etc/nginx/cert/pact_cert.key;

location / {
proxy_pass http://app:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate /etc/nginx/cert/pact_cert.pem;
# ssl_certificate_key /etc/nginx/cert/pact_cert.key;
#
# location / {
# proxy_pass http://app:80;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
# }
14 changes: 10 additions & 4 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/usr/bin/make -f

MOVIES_API_VERSION=4.0.0
DURATION_PROVIDER_VERSION=3.0.0

args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}`

%:
@:

pactman-duration-provider-verify:
pactman-verifier -b http://localhost duration-provider http://localhost:9000 http://localhost:9000/_pact/provider_states
pactman-verifier -b http://localhost/ duration-provider http://localhost:9000 http://localhost:9000/_pact/provider_states -a $(DURATION_PROVIDER_VERSION) -r

pactman-movies-api-verify:
pactman-verifier -b http://localhost movies-api http://localhost:9001 http://localhost:9001/_pact/provider_states
pactman-verifier -b http://localhost/ movies-api http://localhost:9001 http://localhost:9001/_pact/provider_states -a $(MOVIES_API_VERSION) -r

pactman-movies-api-verify-prg:
python ./movies_api/launch.py

pactman-movies-api-publish:
$ curl -v --silent --output /dev/null --show-error --fail -XPUT \-H "Content-Type: application/json" -d@pacts/pactman/movies-api-duration-provider-pact.json http://localhost/pacts/provider/duration-provider/consumer/movies-api/version/$(call args, "1.0.0")
$ curl -v --silent --output /dev/null --show-error --fail -XPUT \-H "Content-Type: application/json" -d@pacts/pactman/movies-api-duration-provider-pact.json http://localhost/pacts/provider/duration-provider/consumer/movies-api/version/$(call args, $(MOVIES_API_VERSION))

.PHONY: pactman-movies-api-publish pactman-duration-provider-verify
.PHONY: pactman-movies-api-publish pactman-duration-provider-verify pactman-movies-api-verify pactman-movies-api-verify-prg
26 changes: 26 additions & 0 deletions python/duration_provider/launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import subprocess

VERSION = '1.0.0'
PORT = 9000


def main():
p_app = subprocess.Popen(['python', './main.py'])

try:
p_verifier = subprocess.Popen(
[
'pactman-verifier',
'-b', 'http://localhost/', 'duration-provider',
f'http://localhost:{PORT}', f'http://localhost:{PORT}/_pact/provider_states', '-a',
VERSION, '-r'
]
)
p_verifier.communicate()
except Exception:
p_app.kill()
p_app.kill()


if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions python/duration_provider/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import uvicorn
from typing import Dict, Any

from fastapi import FastAPI

PORT = 9000

app = FastAPI()


Expand All @@ -13,3 +16,7 @@ async def duration(media_id: int):
@app.post('/_pact/provider_states')
def provider_states(item: Dict[Any, Any] = None):
return {'result': item['state']}


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=PORT)
27 changes: 27 additions & 0 deletions python/movies_api/launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess

VERSION = '1.0.0'
PORT = 9001


def main():
p_app = subprocess.Popen(['python', './main.py'])

try:
p_verifier = subprocess.Popen(
[
'pactman-verifier',
'-b', 'http://localhost/', 'movies-api',
f'http://localhost:{PORT}', f'http://localhost:{PORT}/_pact/provider_states', '-a',
VERSION, '-r'
]
)

p_verifier.communicate()
except Exception:
p_app.kill()
p_app.kill()


if __name__ == '__main__':
main()
12 changes: 11 additions & 1 deletion python/movies_api/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import uvicorn
from typing import Dict, Any, Optional
from fastapi import FastAPI, Response
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel
import requests

PORT = 9001
JSON_RESULT = {
"id": 42,
"name": "The Silence of the Lambs",
Expand All @@ -15,6 +17,7 @@
DURATION_PROVIDER_ENDPOINT = 'http://localhost:9000/duration'
HEADERS = {"Content-Type": "application/json; charset=utf-8"}


class Movie(BaseModel):
name: str
genre: str
Expand All @@ -23,6 +26,7 @@ class Movie(BaseModel):

app = FastAPI()


def get_duration(movie_id):
response = requests.get(f"{DURATION_PROVIDER_ENDPOINT}/{movie_id}")
return response.json()
Expand All @@ -37,12 +41,18 @@ async def movie(movie_id: int):

return JSONResponse(content=JSON_RESULT, headers=HEADERS)


@app.post("/movies")
async def create_movie(movie: Movie):
content = dict(movie)
content['id'] = 42
return JSONResponse(content=content, headers=HEADERS, status_code=201)


@app.post('/_pact/provider_states')
def provider_states(item: Dict[Any, Any] = None):
return {'result': item['state']}


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=PORT)