From f11563cf57e07a933f981a3b078bf56059dace3a Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sat, 29 Apr 2017 13:06:03 +1000 Subject: [PATCH 1/6] chore(build): no need to fetch dependencies - we vendor them --- scripts/build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 6dbff2224..2df7ed46f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,11 +7,9 @@ VERSION=$(go version) echo "==> Go version ${VERSION}" echo "==> Getting dependencies..." -export GO15VENDOREXPERIMENT=1 - go get github.com/mitchellh/gox -go get github.com/inconshreveable/mousetrap # windows dep -go get -d ./... + +echo "==> Creating binaries..." 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}}" From 2f0032db06ee4e9ce70c573d133d6eb8bdbc6c55 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sat, 29 Apr 2017 18:29:12 +1000 Subject: [PATCH 2/6] chore(build): improved process killing in integration tests --- scripts/pact.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/pact.sh b/scripts/pact.sh index 710f05708..a913facbb 100755 --- a/scripts/pact.sh +++ b/scripts/pact.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash +e ############################################################ ## Start and stop the Pact Mock Server daemon ## @@ -12,7 +12,7 @@ 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) + PID=$(ps -ef | grep "pact-go daemon"| grep -v grep | awk -F" " '{print $2}' | head -n 1) if [ "${PID}" != "" ]; then log "Killing ${PID}" kill $PID @@ -20,7 +20,6 @@ function shutdown() { cd $CUR_DIR } -# mkdir -p bin if [ ! -f "dist/pact-go" ]; then cd dist platform=$(detect_os) @@ -64,9 +63,6 @@ cd .. shutdown -# step "Stopping Metrics API" -# make stop - if [ "${SCRIPT_STATUS}" = "0" ]; then step "Integration testing succeeded!" else From 20ccaed3de3886756faf9c484b8f3d1e47880a6a Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sun, 30 Apr 2017 14:24:53 +1000 Subject: [PATCH 3/6] chore(quality): cleanup extraneous comment --- daemon/service_manager.go | 1 - 1 file changed, 1 deletion(-) diff --git a/daemon/service_manager.go b/daemon/service_manager.go index b456d9d4b..e6f436610 100644 --- a/daemon/service_manager.go +++ b/daemon/service_manager.go @@ -59,7 +59,6 @@ func (s *ServiceManager) removeServiceMonitor() { } } -// Stop a Service and returns the exit status. // Stop a Service and returns the exit status. func (s *ServiceManager) Stop(pid int) (bool, error) { log.Println("[DEBUG] stopping service with pid", pid) From 8819608ceb188d0b07c6dc7e3924128293face21 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sun, 30 Apr 2017 14:25:55 +1000 Subject: [PATCH 4/6] feat(ruby): clean ruby stack trace in pact provider verification failures #19 --- dsl/client.go | 18 +++++++++++++++++- dsl/client_test.go | 16 ++++++++++++++++ dsl/pact_integration_test.go | 4 ++-- scripts/pact.sh | 6 +++--- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/dsl/client.go b/dsl/client.go index d14fb31bb..9655729eb 100644 --- a/dsl/client.go +++ b/dsl/client.go @@ -6,6 +6,7 @@ import ( "net" "net/rpc" "net/url" + "regexp" "strconv" "strings" "time" @@ -127,12 +128,27 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) (string, error) } if res.ExitCode > 0 { - return "", fmt.Errorf("provider verification failed: %s", res.Message) + return "", fmt.Errorf("provider verification failed: %s", sanitiseRubyResponse(res.Message)) } return res.Message, err } +// sanitiseRubyResponse removes Ruby-isms from the response content +// making the output much more human readable +func sanitiseRubyResponse(response string) string { + r := regexp.MustCompile("(?m)^\\s*#.*$") + s := r.ReplaceAllString(response, "") + + r = regexp.MustCompile("(?m).*bundle exec rake pact:verify.*$") + s = r.ReplaceAllString(s, "") + + r = regexp.MustCompile("\\n+") + s = r.ReplaceAllString(s, "\n") + + return s +} + // ListServers lists all running Pact Mock Servers. func (p *PactClient) ListServers() *types.PactListResponse { log.Println("[DEBUG] client: listing servers") diff --git a/dsl/client_test.go b/dsl/client_test.go index 8b7c1a760..3e63d960c 100644 --- a/dsl/client_test.go +++ b/dsl/client_test.go @@ -387,3 +387,19 @@ func TestHelperProcess(t *testing.T) { fmt.Fprintf(os.Stdout, "COMMAND: oh yays!\n") os.Exit(0) } + +func Test_sanitiseRubyResponse(t *testing.T) { + var tests = map[string]string{ + "this is a sentence with a hash # so it should be in tact": "this is a sentence with a hash # so it should be in tact", + "this is a sentence with a hash and newline\n#so it should not be in tact": "this is a sentence with a hash and newline", + "this is a sentence with a ruby statement bundle exec rake pact:verify so it should not be in tact": "", + "this is a sentence with a ruby statement\nbundle exec rake pact:verify so it should not be in tact": "this is a sentence with a ruby statement", + "this is a sentence with multiple new lines \n\n\n\n\nit should not be in tact": "this is a sentence with multiple new lines \nit should not be in tact", + } + for k, v := range tests { + test := sanitiseRubyResponse(k) + if !strings.EqualFold(strings.TrimSpace(test), strings.TrimSpace(v)) { + log.Fatalf("Got `%s', Expected `%s`", strings.TrimSpace(test), strings.TrimSpace(v)) + } + } +} diff --git a/dsl/pact_integration_test.go b/dsl/pact_integration_test.go index 21c77fa16..287bd91de 100644 --- a/dsl/pact_integration_test.go +++ b/dsl/pact_integration_test.go @@ -13,7 +13,7 @@ import ( var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../pacts", dir) -var logDir = fmt.Sprintf("%s/../logs", dir) +var logDir = fmt.Sprintf("%s/../log", dir) func TestPact_Integration(t *testing.T) { // Enable when running E2E/integration tests before a release @@ -202,7 +202,7 @@ func setupProviderAPI() int { [ [ { - "size": 10, + "size": 10, "colour": "red", "tag": [ [ diff --git a/scripts/pact.sh b/scripts/pact.sh index a913facbb..dc1eb3c0d 100755 --- a/scripts/pact.sh +++ b/scripts/pact.sh @@ -48,8 +48,8 @@ if [ ! -f "dist/pact-go" ]; then fi step "Starting Daemon" -mkdir -p ./logs -./dist/pact-go daemon -v -l DEBUG > logs/daemon.log 2>&1 & +mkdir -p ./log +./dist/pact-go daemon -v -l DEBUG > log/daemon.log 2>&1 & step "Running integration tests" export PACT_INTEGRATED_TESTS=1 @@ -57,7 +57,7 @@ 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 +go test -v -run TestPact_Integration SCRIPT_STATUS=$? cd .. From ea09f087d1cb3a2f144204a64ccc4838809c1545 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sun, 30 Apr 2017 14:36:00 +1000 Subject: [PATCH 5/6] chore(test): speed up unit tests by reducing timeouts waiting for daemon --- daemon/daemon_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index ed8b715d2..2c67c5930 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -87,7 +87,7 @@ func TestShutdownDaemon(t *testing.T) { func connectToDaemon(port int, t *testing.T) { for { select { - case <-time.After(1 * time.Second): + case <-time.After(250 * time.Millisecond): t.Fatalf("Expected server to start < 1s.") case <-time.After(50 * time.Millisecond): _, err := net.Dial("tcp", fmt.Sprintf(":%d", port)) @@ -104,7 +104,7 @@ func waitForDaemonToShutdown(port int, daemon *Daemon, t *testing.T) { daemon.signalChan <- os.Interrupt } t.Logf("Waiting for deamon to shutdown before next test") - timeout := time.After(1 * time.Second) + timeout := time.After(250 * time.Millisecond) for { select { case <-timeout: @@ -474,7 +474,7 @@ func TestHelperProcess(t *testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { return } - <-time.After(1 * time.Second) + <-time.After(250 * time.Millisecond) // some code here to check arguments perhaps? // Fail :( From d8931dcf4d7907c1c89d7993634055c20d810520 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sun, 30 Apr 2017 14:38:52 +1000 Subject: [PATCH 6/6] chore(test): tidy up spacing in pact integration test --- dsl/pact_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsl/pact_integration_test.go b/dsl/pact_integration_test.go index 287bd91de..c7e850fd5 100644 --- a/dsl/pact_integration_test.go +++ b/dsl/pact_integration_test.go @@ -202,7 +202,7 @@ func setupProviderAPI() int { [ [ { - "size": 10, + "size": 10, "colour": "red", "tag": [ [