-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathexample.sh
executable file
·57 lines (46 loc) · 2.01 KB
/
example.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# BEFORE SUITE start mock service
# invoked by the pact framework
bundle exec bin/pact-mock-service service \
--port 1234 \
--consumer Foo \
--provider Bar \
--pact-specification-version 2 \
--pact-dir ./tmp/pacts \
--log ./tmp/bar_mock_service.log \
--log-level DEBUG &
pid=$!
# BEFORE SUITE wait for mock service to start up
# invoked by the pact framework
while [ "200" -ne "$(curl -H "X-Pact-Mock-Service: true" -s -o /dev/null -w "%{http_code}" localhost:1234)" ]; do sleep 0.5; done
# uncomment this line to see the curl commands interleaved with the responses
# set -x
# BEFORE EACH TEST clear interactions from previous test
# invoked by the pact framework
curl -X DELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions
# BEFORE A TEST set up interaction(s) just for that test
# The contents of this would be written by the developer in the provided pact DSL for
# your language eg. mockService.given(...).uponReceiving(...). ...
# This can be called mulitple times. Alternatively PUT could be used
# with a body of `{interactions: [...]}` which would negate the need to call DELETE.
curl -X POST -H "X-Pact-Mock-Service: true" -d@script/consumer-interaction.json localhost:1234/interactions
# IN A TEST execute interaction(s)
# this would be done by the consumer code under test
curl localhost:1234/foo
echo ''
# AFTER EACH TEST verify interaction(s) took place
# This would be done explicitly by the developer or automatically by the framework,
# depending on the language
curl -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification
# AFTER SUITE
# write pact
# this would be invoked explictly by the developer or automatically framework,
# depending on the language
curl -X POST -H "X-Pact-Mock-Service: true" -H "Content-Length: 0" localhost:1234/pact
# AFTER SUITE stop mock service
# this would be invoked by the test framework
kill -2 $pid
while [ kill -0 $pid 2> /dev/null ]; do sleep 0.5; done
echo ''
echo 'FYI the mock service logs are:'
cat ./tmp/bar_mock_service.log