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 :( 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) 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..c7e850fd5 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/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}}" diff --git a/scripts/pact.sh b/scripts/pact.sh index 710f05708..dc1eb3c0d 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) @@ -49,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 @@ -58,15 +57,12 @@ 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 .. shutdown -# step "Stopping Metrics API" -# make stop - if [ "${SCRIPT_STATUS}" = "0" ]; then step "Integration testing succeeded!" else