Skip to content

Commit

Permalink
test: make tests validate local and files from a pact broker
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jul 27, 2021
1 parent 53838a5 commit a2fee63
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 575 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
echo "LD_LIBRARY_PATH=/tmp" >> $GITHUB_ENV
echo "PACT_GO_LIB_DOWNLOAD_PATH=/tmp" >> $GITHUB_ENV
echo "LOG_LEVEL=trace" >> $GITHUB_ENV
echo "APP_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "APP_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v2
with:
Expand Down
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
include make/config.mk

TEST?=./...

.DEFAULT_GOAL := ci

ci:: docker deps clean bin test pact #goveralls
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD -e PACT_BROKER_TOKEN pactfoundation/pact-cli:latest"

ci:: deps clean bin test pact #goveralls

# Run the ci target from a developer machine with the environment variables
# set as if it was on Travis CI.
# Use this for quick feedback when playing around with your workflows.
fake_ci:
@CI=true \
APP_SHA=`git rev-parse --short HEAD`+`date +%s` \
APP_BRANCH=`git rev-parse --abbrev-ref HEAD` \
make ci

# same as above, but just for pact
fake_pact:
@CI=true \
APP_SHA=`git rev-parse --short HEAD`+`date +%s` \
APP_BRANCH=`git rev-parse --abbrev-ref HEAD` \
make pact

docker:
@echo "--- 🛠 Starting docker"
Expand Down Expand Up @@ -43,8 +59,13 @@ install: bin
pact: clean install #docker
@echo "--- 🔨 Running Pact examples"
go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
make publish
go test -v -timeout=10s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...

publish:
@echo "-- 📃 Publishing pacts"
@"${PACT_CLI}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH}

release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestProductAPIClient(t *testing.T) {
// Specify the two applications in the integration we are testing
// NOTE: this can usually be extracted out of the individual test for re-use)
mockProvider, err := NewV2Pact(MockHTTPProviderConfig{
Consumer: "ProductAPIConsumer",
Provider: "ProductAPI",
Consumer: "PactGoProductAPIConsumer",
Provider: "PactGoProductAPI",
})
assert.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions examples/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestConsumerV2(t *testing.T) {
SetLogLevel("TRACE")

mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
Consumer: "V2Consumer",
Consumer: "PactGoV2Consumer",
Provider: "V2Provider",
Host: "127.0.0.1",
TLS: true,
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestConsumerV2_Match(t *testing.T) {
SetLogLevel("TRACE")

mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
Consumer: "V2ConsumerMatch",
Consumer: "PactGoV2ConsumerMatch",
Provider: "V2ProviderMatch",
Host: "127.0.0.1",
TLS: true,
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestConsumerV3(t *testing.T) {
SetLogLevel("TRACE")

mockProvider, err := NewV3Pact(MockHTTPProviderConfig{
Consumer: "V3Consumer",
Consumer: "PactGoV3Consumer",
Provider: "V3Provider",
Host: "127.0.0.1",
TLS: true,
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestConsumerV2AllInOne(t *testing.T) {
SetLogLevel("TRACE")

mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
Consumer: "V2ConsumerAllInOne",
Consumer: "PactGoV2ConsumerAllInOne",
Provider: "V2Provider",
Host: "127.0.0.1",
TLS: true,
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestMessagePact(t *testing.T) {
SetLogLevel("TRACE")

provider, err := NewMessagePactV3(MessageConfig{
Consumer: "V3MessageConsumer",
Consumer: "PactGoV3MessageConsumer",
Provider: "V3MessageProvider", // must be different to the HTTP one, can't mix both interaction styles
})
assert.NoError(t, err)
Expand Down
100 changes: 0 additions & 100 deletions examples/pacts/V2Consumer-V2Provider.json

This file was deleted.

100 changes: 0 additions & 100 deletions examples/pacts/V2ConsumerMatch-V2ProviderMatch.json

This file was deleted.

Loading

0 comments on commit a2fee63

Please sign in to comment.