Skip to content

Commit

Permalink
feat: pending pacts + selectors
Browse files Browse the repository at this point in the history
- Adds support for pending pacts
- Adds support for selectors
- Cleans up build system to use Make and reduces reliance on legacy build scripts

Fixes #124
  • Loading branch information
Matt Fellows authored and mefellows committed Feb 17, 2020
1 parent d457b86 commit 9a0fdf3
Show file tree
Hide file tree
Showing 233 changed files with 72,607 additions and 35,038 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.o
*.a
*.so

# Folders
_obj
_test
Expand Down Expand Up @@ -32,7 +31,6 @@ pact-mock-service
pact-provider-verifier

*.out
*.cov
*.iml
*.idea
*.bak
Expand All @@ -43,9 +41,11 @@ pacts
logs
log
tmp
coverage.txt

# IDE
.vscode

# Dependencies
vendor
pact
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
language: go

go:
- 1.9.x
- 1.10.x

services:
- docker

env:
global:
secure: LN8/2VY4tvHcCzIVlpy+x3KIlkFNGrwQmQadLR3oT0nJWmkZQhE5f+InAPaQNDm3siJcNG0wLCo0iLw6JN1esF/VQPrsHrW3MAkbKyNsdYnSZUZJ6Zs6MmBoigHy4qWuFayGhChgMHqhyXf6q8B5KhJb3vKKn/WW4nsU8tfpk1jdr8mdRcFEfjViQake5vZUb93gy3sXJxz6NlEaYZcrY25c/iOd06oOQZlCCyz5FhkArBKK95jbeMr5LO/5Xlkg1pIHE571Distoc4e3+ZfzW/yQCsgrZNcLElV96mvRHw/x8k2Bb7UgXQbNPX/mxV7bJCHVjhmIkwP8JKOFEs9AD0nWWjXWA1PlG7MdQoZTCoAnZWUCCsMVDDg/sg7/Vlzf+szYCoz0NE2v0Z1+v9h/itljaSHa0H9u2G/mkvZio377ou0AK54OIXDcPP0BmXvA8uJV6U3hCubWOnF0uwSCrysKEThxD/OFm90IIyLY8LKlsgHsFTkSTiApI//xRfm4NBF1sSg4V2FCzAMJx6596ekIcWgfoVUpSiOKiktwXnZha6XtHENDJeGuNpywowPInvYDZHCHYscCnre6MKTMttmb/q4JgSJEnn2vatRwXQbglzXhCDH7dw/a/75LSUT5Exj0f2HWpxDy+pi+nzITxZoFT+syNFwDvSRMT/wKLU=
67 changes: 51 additions & 16 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,37 +1,72 @@
include make/config.mk

TEST?=./...

.DEFAULT_GOAL := ci

ci:: clean bin tools test pact goveralls
ci:: docker deps clean bin test pact goveralls

docker:
@echo "--- 🛠 Starting docker"
docker-compose up -d

bin:
@sh -c "$(CURDIR)/scripts/build.sh"
gox -os="darwin" -arch="amd64" -output="build/pact-go_{{.OS}}_{{.Arch}}"
gox -os="windows" -arch="386" -output="build/pact-go_{{.OS}}_{{.Arch}}"
gox -os="linux" -arch="386" -output="build/pact-go_{{.OS}}_{{.Arch}}"
gox -os="linux" -arch="amd64" -output="build/pact-go_{{.OS}}_{{.Arch}}"
@echo "==> Results:"
ls -hl build/

clean:
@sh -c "$(CURDIR)/scripts/clean.sh"
rm -rf build output dist

deps:
@echo "--- 🐿 Fetching build dependencies "
go get github.com/axw/gocov/gocov
go get github.com/mattn/goveralls
go get golang.org/x/tools/cmd/cover
go get github.com/modocache/gover
go get github.com/mitchellh/gox

goveralls:
goveralls -service="travis-ci" -coverprofile=coverage.txt -repotoken $(COVERALLS_TOKEN)

dev:
@TF_DEV=1 sh -c "$(CURDIR)/scripts/dev.sh"
install:
@if [ ! -d pact/bin ]; then\
echo "--- 🐿 Installing Pact CLI dependencies";\
curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | bash;\
fi

test:
"$(CURDIR)/scripts/test.sh"
pact: install docker
@echo "--- 🔨 Running Pact examples"
go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample
go test -tags=provider -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample

release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"

pact:
"$(CURDIR)/scripts/pact.sh"
test: deps
@echo "--- ✅ Running tests"
@if [ -f coverage.txt ]; then rm coverage.txt; fi;
@echo "mode: count" > coverage.txt
@for d in $$(go list ./... | grep -v vendor | grep -v examples); \
do \
go test -race -coverprofile=profile.out -covermode=atomic $$d; \
if [ -f profile.out ]; then \
cat profile.out | tail -n +2 >> coverage.txt; \
rm profile.out; \
fi; \
done; \

testrace:
go test -race $(TEST) $(TESTARGS)
go tool cover -func coverage.txt

tools:
"$(CURDIR)/scripts/install-cli-tools.sh"

goveralls:
"$(CURDIR)/scripts/goveralls.sh"
testrace:
go test -race $(TEST) $(TESTARGS)

updatedeps:
go get -d -v -p 2 ./...

.PHONY: bin default dev test pact updatedeps clean release
.PHONY: install bin default dev test pact updatedeps clean release
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ pact.VerifyProvider(t, types.VerifyRequest{
return nil
},
"User jmarie does not exist": func() error {
fmt.Println("state handler")
userRepository = jmarieDoesNotExist
return nil
},
Expand Down Expand Up @@ -769,11 +768,7 @@ Learn everything in Pact Go in 60 minutes: https://github.com/pact-foundation/pa
There are number of examples we use as end-to-end integration test prior to releasing a new binary, including publishing to a Pact Broker. To enable them, set the following environment variables

```sh
cd $GOPATH/src/github.com/pact-foundation/pact-go/examples
export PACT_INTEGRATED_TESTS=1
export PACT_BROKER_USERNAME="dXfltyFMgNOFZAxr8io9wJ37iUpY42M"
export PACT_BROKER_PASSWORD="O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"
export PACT_BROKER_HOST="https://test.pact.dius.com.au"
make pact
```

Once these variables have been exported, cd into one of the directories containing a test and run `go test -v .`:
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ clone_folder: c:\gopath\src\github.com\pact-foundation\pact-go
environment:
GOPATH: c:\gopath
GOVERSION: 1.10
PACT_BROKER_HOST: "https://test.pact.dius.com.au"
PACT_BROKER_PROTO: "https"
PACT_BROKER_URL: "test.pact.dius.com.au"
PACT_BROKER_USERNAME: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M"
PACT_BROKER_PASSWORD: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"

Expand Down
2 changes: 1 addition & 1 deletion client/publish_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type PublishService struct {
// --provider-app-version
// --custom-provider-headers
func (v *PublishService) NewService(args []string) Service {
log.Printf("[DEBUG] starting verification service with args: %v\n", args)
log.Printf("[DEBUG] starting publish service with args: %v\n", args)

v.Args = []string{
"publish",
Expand Down
36 changes: 30 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
version: '3.6'
version: "3"

services:
pact:
build: ./
command: bash
volumes:
- .:/go/src/github.com/pact-foundation/pact-go
httpbin:
image: kennethreitz/httpbin
ports:
- "8000:80"

postgres:
image: postgres
healthcheck:
test: psql postgres --command "select 1" -U postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres

broker_app:
image: dius/pact-broker
links:
- postgres
ports:
- 80:80
environment:
PACT_BROKER_BASIC_AUTH_USERNAME: pact_workshop
PACT_BROKER_BASIC_AUTH_PASSWORD: pact_workshop
PACT_BROKER_DATABASE_USERNAME: postgres
PACT_BROKER_DATABASE_PASSWORD: password
PACT_BROKER_DATABASE_HOST: postgres
PACT_BROKER_DATABASE_NAME: postgres
10 changes: 5 additions & 5 deletions dsl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Client interface {
RemoveAllServers(server *types.MockServer) []*types.MockServer

// VerifyProvider runs the verification process against a running Provider.
VerifyProvider(request types.VerifyRequest) (types.ProviderVerifierResponse, error)
VerifyProvider(request types.VerifyRequest) ([]types.ProviderVerifierResponse, error)

// UpdateMessagePact adds a pact message to a contract file
UpdateMessagePact(request types.PactMessageRequest) error
Expand Down Expand Up @@ -143,9 +143,9 @@ func (p *PactClient) RemoveAllServers(server *types.MockServer) []*types.MockSer

// VerifyProvider runs the verification process against a running Provider.
// TODO: extract/refactor the stdout/error streaems from these functions
func (p *PactClient) VerifyProvider(request types.VerifyRequest) (types.ProviderVerifierResponse, error) {
func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.ProviderVerifierResponse, error) {
log.Println("[DEBUG] client: verifying a provider")
var response types.ProviderVerifierResponse
response := make([]types.ProviderVerifierResponse, 0)

// Convert request into flags, and validate request
err := request.Validate()
Expand Down Expand Up @@ -194,7 +194,7 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) (types.Provider

err = cmd.Wait()

// Split by lines, as the content is now JSONL
// Split by lines, as the content is JSONL formatted
// See https://github.com/pact-foundation/pact-go/issues/88#issuecomment-404686337
verifications := strings.Split(string(stdOut), "\n")

Expand All @@ -209,7 +209,7 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) (types.Provider
if v != "" && strings.Index(v, "INFO") != 0 {
dErr := json.Unmarshal([]byte(v), &verification)

response.Examples = append(response.Examples, verification.Examples...)
response = append(response, verification)

if dErr != nil {
err = dErr
Expand Down
2 changes: 1 addition & 1 deletion dsl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func waitForPortInTest(port int, t *testing.T) {
// mock service but execute our code in isolation.
//
// Use this when you want too exercise the client code, but not shell out to Ruby.
// Where possible, you should consider creating a mockClient{} object and
// Where possible, outside of these tess, you should consider creating a mockClient{} object and
// stubbing out the required behaviour.
//
// Stubbing the exec.Cmd interface is hard, see fakeExec* functions for
Expand Down
4 changes: 2 additions & 2 deletions dsl/message.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dsl

import (
"fmt"
"log"
"reflect"
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func (p *Message) WithContent(content interface{}) *Message {
// AsType specifies that the content sent through to the
// consumer handler should be sent as the given type
func (p *Message) AsType(t interface{}) *Message {
fmt.Println("[DEBUG] setting Message decoding to type:", reflect.TypeOf(t))
log.Println("[DEBUG] setting Message decoding to type:", reflect.TypeOf(t))
p.Type = t

return p
Expand Down
7 changes: 2 additions & 5 deletions dsl/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import (
"github.com/pact-foundation/pact-go/types"
)

// TODO: Migrate tests from createMockClient to this package
// where possible

// Mock Client for testing the DSL package
type mockClient struct {
VerifyProviderResponse types.ProviderVerifierResponse
VerifyProviderResponse []types.ProviderVerifierResponse
VerifyProviderError error
Servers []*types.MockServer
StopServerResponse *types.MockServer
Expand Down Expand Up @@ -57,7 +54,7 @@ func (p *mockClient) RemoveAllServers(server *types.MockServer) []*types.MockSer
}

// VerifyProvider runs the verification process against a running Provider.
func (p *mockClient) VerifyProvider(request types.VerifyRequest) (types.ProviderVerifierResponse, error) {
func (p *mockClient) VerifyProvider(request types.VerifyRequest) ([]types.ProviderVerifierResponse, error) {
return p.VerifyProviderResponse, p.VerifyProviderError
}

Expand Down
2 changes: 1 addition & 1 deletion dsl/mock_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type MockService struct {
func (m *MockService) call(method string, url string, content interface{}) error {
body, err := json.Marshal(content)
if err != nil {
fmt.Println(err)
log.Println("[ERROR]", err)
return err
}

Expand Down
Loading

0 comments on commit 9a0fdf3

Please sign in to comment.