Skip to content

Commit f1ee33c

Browse files
committed
feat(e2e): run e2e tests in wercker builds. Fixes #20
1 parent 33a0434 commit f1ee33c

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ dev:
1414
test:
1515
"$(CURDIR)/scripts/test.sh"
1616

17+
pact:
18+
"$(CURDIR)/scripts/pact.sh"
19+
1720
testrace:
1821
go test -race $(TEST) $(TESTARGS)
1922

scripts/lib

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function step {
2+
echo ""
3+
echo " -----> $1"
4+
}
5+
6+
function log {
7+
echo " $1"
8+
}
9+
10+
function detect_os {
11+
platform='unknown'
12+
unamestr=`uname`
13+
if [[ "$unamestr" == 'Linux' ]]; then
14+
platform='linux'
15+
elif [[ "$OSTYPE" == "darwin"* ]]; then
16+
platform='darwin'
17+
elif [[ "$unamestr" == 'FreeBSD' ]]; then
18+
platform='freebsd'
19+
fi
20+
echo $platform
21+
}

scripts/pact.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
############################################################
4+
## Start and stop the Pact Mock Server daemon ##
5+
############################################################
6+
7+
LIBDIR=$(dirname "$0")
8+
. "${LIBDIR}/lib"
9+
10+
trap shutdown INT
11+
CUR_DIR=$(pwd)
12+
function shutdown() {
13+
step "Shutting down stub server"
14+
log "Finding Pact daemon PID"
15+
PID=$(ps -ef | grep pact-go | awk -F" " '{print $2}' | head -n 1)
16+
if [ "${PID}" != "" ]; then
17+
log "Killing ${PID}"
18+
kill $PID
19+
fi
20+
cd $CUR_DIR
21+
}
22+
23+
# mkdir -p bin
24+
if [ ! -f "dist/pact-go" ]; then
25+
cd dist
26+
platform=$(detect_os)
27+
archive="${platform}-amd64.tar.gz"
28+
step "Installing Pact Go for ${platform}"
29+
30+
if [ ! -f "${archive}" ]; then
31+
log "Cannot find distribution package ${archive}, please run 'make package' first"
32+
exit 1
33+
fi
34+
35+
log "Expanding archive"
36+
if [[ $platform == 'linux' ]]; then
37+
tar -xf $archive
38+
mv pact-go_linux_amd64 pact-go
39+
elif [[ $platform == 'darwin' ]]; then
40+
tar -xf $archive
41+
mv pact-go_darwin_amd64 pact-go
42+
else
43+
log "Unsupported platform ${platform}"
44+
exit 1
45+
fi
46+
47+
cd ..
48+
log "Done"
49+
fi
50+
51+
step "Starting Daemon"
52+
mkdir -p ./logs
53+
./dist/pact-go daemon -v -l DEBUG > logs/daemon.log 2>&1 &
54+
55+
step "Running integration tests"
56+
export PACT_INTEGRATED_TESTS=1
57+
export PACT_BROKER_HOST="https://test.pact.dius.com.au"
58+
export PACT_BROKER_USERNAME="dXfltyFMgNOFZAxr8io9wJ37iUpY42M"
59+
export PACT_BROKER_PASSWORD="JN4kVfO5AIZWxelWbLvqMd8PkAVycBJh2Psyg11wtkubJC4xlOH5GmIfwO9gWe"
60+
cd dsl
61+
go test -run TestPact_Integration
62+
EXIT_CODE=$?
63+
cd ..
64+
65+
shutdown
66+
67+
# step "Stopping Metrics API"
68+
# make stop
69+
70+
if [ "${EXIT_CODE}" = "0" ]; then
71+
step "Integration testing succeeded!"
72+
else
73+
step "Integration testing failed, see stack trace above"
74+
fi
75+
76+
exit $EXIT_CODE

wercker.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ package:
6161
ls -larth build
6262
ls -larth output
6363
64+
integration:
65+
steps:
66+
- setup-go-workspace
67+
- golint:
68+
exclude: "vendor"
69+
- script:
70+
name: retrieve artifacts
71+
code: |
72+
mkdir -p output
73+
mkdir -p build
74+
if [ -d "$WERCKER_CACHE_DIR/build" ]; then cp -r $WERCKER_CACHE_DIR/build .; fi
75+
if [ -d "$WERCKER_CACHE_DIR/output" ]; then cp -r $WERCKER_CACHE_DIR/output .; fi
76+
ls -larth build
77+
ls -larth output
78+
- script:
79+
name: pact
80+
code: |
81+
make pact
82+
6483
# TODO: Get tokens for Pact foundation
6584
deploy:
6685
steps:

0 commit comments

Comments
 (0)