Skip to content

Commit

Permalink
Merge pull request #170 from bbmokus/fix/verify-provider-response
Browse files Browse the repository at this point in the history
fix: handle verification response correctly
  • Loading branch information
mefellows authored Jul 3, 2021
2 parents 5996808 + 5903b70 commit 79a461c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dsl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid
err = cmd.Wait()
wg.Wait()

var verification types.ProviderVerifierResponse
for _, v := range verifications {
v = strings.TrimSpace(v)

Expand All @@ -235,6 +234,7 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid
// logging to stdout breaks the JSON response
// https://github.com/pact-foundation/pact-ruby/commit/06fa61581512ba5570c315d089f2c0fc23c8cb11
if v != "" && strings.Index(v, "INFO") != 0 {
var verification types.ProviderVerifierResponse
dErr := json.Unmarshal([]byte(v), &verification)

response = append(response, verification)
Expand Down
24 changes: 22 additions & 2 deletions dsl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,31 @@ func TestClient_VerifyProvider(t *testing.T) {
BrokerPassword: "foo",
ProviderStatesSetupURL: "http://foo/states/setup",
}
_, err := client.VerifyProvider(req)
responses, err := client.VerifyProvider(req)

if err != nil {
t.Fatal("Error: ", err)
}

if len(responses) != 2 {
t.Fatalf("Expected 2 ProviderVerifierResponse objects but got %d", len(responses))
}

if len(responses[0].Examples) != 1 {
t.Fatalf("Expected responses[0] to have 1 example but got %d", len(responses[0].Examples))
}

if responses[0].Examples[0].ID != "1" {
t.Fatalf("Expected responses[0].Examples[0] to have id 1 but got %s", responses[0].Examples[0].ID)
}

if len(responses[1].Examples) != 1 {
t.Fatalf("Expected responses[1] to have 1 example but got %d", len(responses[1].Examples))
}

if responses[1].Examples[0].ID != "2" {
t.Fatalf("Expected responses[1].Examples[0] to have id 2 but got %s", responses[1].Examples[0].ID)
}
}

func TestClient_VerifyProviderFailValidation(t *testing.T) {
Expand Down Expand Up @@ -241,7 +261,7 @@ func TestHelperProcess(t *testing.T) {
}

// Success :)
fmt.Fprintf(os.Stdout, "{\"summary_line\":\"1 examples, 0 failures\"}\n{\"summary_line\":\"1 examples, 0 failures\"}")
fmt.Fprintf(os.Stdout, "{\"examples\":[{\"id\":\"1\"}],\"summary_line\":\"1 examples, 0 failures\"}\n{\"examples\":[{\"id\":\"2\"}],\"summary_line\":\"1 examples, 0 failures\"}")
os.Exit(0)
}

Expand Down

0 comments on commit 79a461c

Please sign in to comment.