diff --git a/Makefile b/Makefile index 6e07bb141..f16907b45 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ dev: test: "$(CURDIR)/scripts/test.sh" +pact: + "$(CURDIR)/scripts/pact.sh" + testrace: go test -race $(TEST) $(TESTARGS) diff --git a/scripts/lib b/scripts/lib new file mode 100644 index 000000000..3e8588fd2 --- /dev/null +++ b/scripts/lib @@ -0,0 +1,21 @@ +function step { + echo "" + echo " -----> $1" +} + +function log { + echo " $1" +} + +function detect_os { + platform='unknown' + unamestr=`uname` + if [[ "$unamestr" == 'Linux' ]]; then + platform='linux' + elif [[ "$OSTYPE" == "darwin"* ]]; then + platform='darwin' + elif [[ "$unamestr" == 'FreeBSD' ]]; then + platform='freebsd' + fi + echo $platform +} \ No newline at end of file diff --git a/scripts/pact.sh b/scripts/pact.sh new file mode 100755 index 000000000..4f17d5577 --- /dev/null +++ b/scripts/pact.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +############################################################ +## Start and stop the Pact Mock Server daemon ## +############################################################ + +LIBDIR=$(dirname "$0") +. "${LIBDIR}/lib" + +trap shutdown INT +CUR_DIR=$(pwd) +function shutdown() { + step "Shutting down stub server" + log "Finding Pact daemon PID" + PID=$(ps -ef | grep pact-go | awk -F" " '{print $2}' | head -n 1) + if [ "${PID}" != "" ]; then + log "Killing ${PID}" + kill $PID + fi + cd $CUR_DIR +} + +# mkdir -p bin +if [ ! -f "dist/pact-go" ]; then + cd dist + platform=$(detect_os) + archive="${platform}-amd64.tar.gz" + step "Installing Pact Go for ${platform}" + + if [ ! -f "${archive}" ]; then + log "Cannot find distribution package ${archive}, please run 'make package' first" + exit 1 + fi + + log "Expanding archive" + if [[ $platform == 'linux' ]]; then + tar -xf $archive + mv pact-go_linux_amd64 pact-go + elif [[ $platform == 'darwin' ]]; then + tar -xf $archive + mv pact-go_darwin_amd64 pact-go + else + log "Unsupported platform ${platform}" + exit 1 + fi + + cd .. + log "Done" +fi + +step "Starting Daemon" +mkdir -p ./logs +./dist/pact-go daemon -v -l DEBUG > logs/daemon.log 2>&1 & + +step "Running integration tests" +export PACT_INTEGRATED_TESTS=1 +export PACT_BROKER_HOST="https://test.pact.dius.com.au" +export PACT_BROKER_USERNAME="dXfltyFMgNOFZAxr8io9wJ37iUpY42M" +export PACT_BROKER_PASSWORD="JN4kVfO5AIZWxelWbLvqMd8PkAVycBJh2Psyg11wtkubJC4xlOH5GmIfwO9gWe" +cd dsl +go test -run TestPact_Integration +EXIT_CODE=$? +cd .. + +shutdown + +# step "Stopping Metrics API" +# make stop + +if [ "${EXIT_CODE}" = "0" ]; then + step "Integration testing succeeded!" +else + step "Integration testing failed, see stack trace above" +fi + +exit $EXIT_CODE \ No newline at end of file diff --git a/wercker.yml b/wercker.yml index 2975ba258..830e4ea28 100644 --- a/wercker.yml +++ b/wercker.yml @@ -61,6 +61,25 @@ package: ls -larth build ls -larth output +integration: + steps: + - setup-go-workspace + - golint: + exclude: "vendor" + - script: + name: retrieve artifacts + code: | + mkdir -p output + mkdir -p build + if [ -d "$WERCKER_CACHE_DIR/build" ]; then cp -r $WERCKER_CACHE_DIR/build .; fi + if [ -d "$WERCKER_CACHE_DIR/output" ]; then cp -r $WERCKER_CACHE_DIR/output .; fi + ls -larth build + ls -larth output + - script: + name: pact + code: | + make pact + # TODO: Get tokens for Pact foundation deploy: steps: