Skip to content

Commit

Permalink
fix(broker): fix pact retrieval from broker
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 20, 2018
1 parent 9a60d4f commit c45d3cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
13 changes: 8 additions & 5 deletions dsl/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ func findConsumers(provider string, request *types.VerifyRequest) error {
return err
}

for _, p := range doc.Links.OldPacts {
pactURLs[p.Title] = p.Href
// Collapse results on the URL the pact links to
for _, p := range doc.Links.Pacts {
pactURLs[p.Href] = p.Href
}

for _, p := range doc.Links.Pacts {
pactURLs[p.Title] = p.Href
// Ensure backwards compatability with old pacts
// See https://github.com/pact-foundation/pact_broker/issues/209#issuecomment-390437990
for _, p := range doc.Links.OldPacts {
pactURLs[p.Href] = p.Href
}

fmt.Println(pactURLs)
fmt.Println("[DEBUG] pacts to verify: ", pactURLs)
}

// Scrub out duplicate pacts across tags (e.g. 'latest' may equal 'prod' pact)
Expand Down
20 changes: 6 additions & 14 deletions dsl/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ func TestBroker_findConsumersNoTags(t *testing.T) {
t.Fatalf("Error: %s", err.Error())
}

if len(request.PactURLs) != 4 {
t.Fatalf("Expected 4 PactURLs but got: %d", len(request.PactURLs))
}

pactURL := fmt.Sprintf("%s/pacts/provider/bobby/consumer/jessica/version/2.0.0", s.URL)
if request.PactURLs[0] != pactURL && request.PactURLs[1] != pactURL {
t.Fatalf("Expected '%s', but got '%s'", pactURL, request.PactURLs[0])
// Because we have both old and new format here, we will not benefit from
// the condensing of pacts, even though the contents are the same
if len(request.PactURLs) != 2 {
t.Fatalf("Expected 2 PactURLs but got: %d, %s", len(request.PactURLs), request.PactURLs)
}
}

Expand All @@ -44,13 +41,8 @@ func TestBroker_findConsumersWithTags(t *testing.T) {
t.Fatalf("Error: %s", err.Error())
}

if len(request.PactURLs) != 4 {
t.Fatalf("Expected 4 PactURLs but got: %d", len(request.PactURLs))
}

pactURL := fmt.Sprintf("%s/pacts/provider/bobby/consumer/billy/version/1.0.1", s.URL)
if request.PactURLs[0] != pactURL && request.PactURLs[1] != pactURL {
t.Fatalf("Expected '%s', but got '%s'", pactURL, request.PactURLs[0])
if len(request.PactURLs) != 2 {
t.Fatalf("Expected 2 PactURLs but got: %d", len(request.PactURLs))
}
}

Expand Down

0 comments on commit c45d3cc

Please sign in to comment.