Skip to content

Commit

Permalink
feat(ruby): clean ruby stack trace in pact provider verification fail…
Browse files Browse the repository at this point in the history
…ures #19
  • Loading branch information
mefellows committed Apr 30, 2017
1 parent 20ccaed commit 8819608
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
18 changes: 17 additions & 1 deletion dsl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/rpc"
"net/url"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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")
Expand Down
16 changes: 16 additions & 0 deletions dsl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
4 changes: 2 additions & 2 deletions dsl/pact_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -202,7 +202,7 @@ func setupProviderAPI() int {
[
[
{
"size": 10,
"size": 10,
"colour": "red",
"tag": [
[
Expand Down
6 changes: 3 additions & 3 deletions scripts/pact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ 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
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 ..

Expand Down

0 comments on commit 8819608

Please sign in to comment.