Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle verification response correctly #170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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