diff --git a/dsl/broker.go b/dsl/broker.go index b6fe0a981..dfd07c2b9 100644 --- a/dsl/broker.go +++ b/dsl/broker.go @@ -31,7 +31,8 @@ type PactLink struct { // HalLinks represents the _links key in a HAL document. type HalLinks struct { - Pacts []PactLink `json:"pb:pacts"` + Pacts []PactLink `json:"pb:pacts"` + OldPacts []PactLink `json:"pacts"` } // HalDoc is a simple representation of the HAL response from a Pact Broker. @@ -101,9 +102,15 @@ func findConsumers(provider string, request *types.VerifyRequest) error { return err } + for _, p := range doc.Links.OldPacts { + pactURLs[p.Title] = p.Href + } + for _, p := range doc.Links.Pacts { pactURLs[p.Title] = p.Href } + + fmt.Println(pactURLs) } // Scrub out duplicate pacts across tags (e.g. 'latest' may equal 'prod' pact) diff --git a/dsl/broker_test.go b/dsl/broker_test.go index 48f1e2f1b..459108d7e 100644 --- a/dsl/broker_test.go +++ b/dsl/broker_test.go @@ -11,7 +11,7 @@ import ( "github.com/pact-foundation/pact-go/utils" ) -func TestPact_findConsumersNoTags(t *testing.T) { +func TestBroker_findConsumersNoTags(t *testing.T) { s := setupMockBroker(false) defer s.Close() request := types.VerifyRequest{ @@ -22,8 +22,8 @@ func TestPact_findConsumersNoTags(t *testing.T) { t.Fatalf("Error: %s", err.Error()) } - if len(request.PactURLs) != 2 { - t.Fatalf("Expected 2 PactURLs but got: %d", len(request.PactURLs)) + 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) @@ -32,7 +32,7 @@ func TestPact_findConsumersNoTags(t *testing.T) { } } -func TestPact_findConsumersWithTags(t *testing.T) { +func TestBroker_findConsumersWithTags(t *testing.T) { s := setupMockBroker(false) defer s.Close() request := types.VerifyRequest{ @@ -44,8 +44,8 @@ func TestPact_findConsumersWithTags(t *testing.T) { t.Fatalf("Error: %s", err.Error()) } - if len(request.PactURLs) != 2 { - t.Fatalf("Expected 2 PactURLs but got: %d", len(request.PactURLs)) + 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) @@ -54,7 +54,7 @@ func TestPact_findConsumersWithTags(t *testing.T) { } } -func TestPact_findConsumersBrokerDown(t *testing.T) { +func TestBroker_findConsumersBrokerDown(t *testing.T) { port, _ := utils.GetFreePort() request := types.VerifyRequest{ Tags: []string{"dev", "prod"}, @@ -67,7 +67,7 @@ func TestPact_findConsumersBrokerDown(t *testing.T) { } } -func TestPact_findConsumersInvalidResponse(t *testing.T) { +func TestBroker_findConsumersInvalidResponse(t *testing.T) { s := setupMockBroker(false) defer s.Close() request := types.VerifyRequest{ @@ -81,7 +81,7 @@ func TestPact_findConsumersInvalidResponse(t *testing.T) { } } -func TestPact_findConsumersInvalidURL(t *testing.T) { +func TestBroker_findConsumersInvalidURL(t *testing.T) { request := types.VerifyRequest{ BrokerURL: "%%%", } @@ -92,7 +92,7 @@ func TestPact_findConsumersInvalidURL(t *testing.T) { } } -func TestPact_findConsumersErrorResponse(t *testing.T) { +func TestBroker_findConsumersErrorResponse(t *testing.T) { s := setupMockBroker(false) defer s.Close() request := types.VerifyRequest{ @@ -106,7 +106,7 @@ func TestPact_findConsumersErrorResponse(t *testing.T) { } } -func TestPact_findConsumersNoConsumers(t *testing.T) { +func TestBroker_findConsumersNoConsumers(t *testing.T) { s := setupMockBroker(false) defer s.Close() request := types.VerifyRequest{ @@ -119,7 +119,7 @@ func TestPact_findConsumersNoConsumers(t *testing.T) { } } -func TestPact_findConsumersAuthenticated(t *testing.T) { +func TestBroker_findConsumersAuthenticated(t *testing.T) { s := setupMockBroker(true) defer s.Close() request := types.VerifyRequest{ @@ -134,7 +134,7 @@ func TestPact_findConsumersAuthenticated(t *testing.T) { } } -func TestPact_findConsumersAuthenticatedFail(t *testing.T) { +func TestBroker_findConsumersAuthenticatedFail(t *testing.T) { s := setupMockBroker(true) defer s.Close() request := types.VerifyRequest{ @@ -186,7 +186,7 @@ func setupMockBroker(auth bool) *httptest.Server { // curl --user pactuser:pact -H "accept: application/hal+json" "http://pact.onegeek.com.au/pacts/provider/bobby/latest" mux.HandleFunc("/pacts/provider/bobby/latest", authFunc(func(w http.ResponseWriter, req *http.Request) { log.Println("[DEBUG] get pacts for provider 'bobby'") - fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest","title":"Latest pact versions for the provider bobby"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/jessica/version/2.0.0","title":"Pact between jessica (v2.0.0) and bobby","name":"jessica"},{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"Pact between billy (v1.0.0) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL, server.URL) + fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest","title":"Latest pact versions for the provider bobby"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/jessica/version/2.0.0","title":"Pact between jessica (v2.0.0) and bobby","name":"jessica"},{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"Pact between billy (v1.0.0) and bobby","name":"billy"}],"pacts":[{"href":"%s/pacts/provider/bobby/consumer/jessica/version/2.0.0","title":"OLD Pact between jessica (v2.0.0) and bobby","name":"jessica"},{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"OLD Pact between billy (v1.0.0) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL, server.URL, server.URL, server.URL) w.Header().Add("Content-Type", "application/hal+json") })) @@ -194,7 +194,7 @@ func setupMockBroker(auth bool) *httptest.Server { // curl --user pactuser:pact -H "accept: application/hal+json" "http://pact.onegeek.com.au/pacts/provider/bobby/latest/sit4" mux.Handle("/pacts/provider/bobby/latest/prod", authFunc(func(w http.ResponseWriter, req *http.Request) { log.Println("[DEBUG] get all pacts for provider 'bobby' where the tag 'prod' exists") - fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest/dev","title":"Latest pact versions for the provider bobby with tag 'dev'"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"Pact between billy (v1.0.0) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL) + fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest/dev","title":"Latest pact versions for the provider bobby with tag 'dev'"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"Pact between billy (v1.0.0) and bobby","name":"billy"}],"pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.0","title":"OLD Pact between billy (v1.0.0) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL, server.URL) w.Header().Add("Content-Type", "application/hal+json") })) @@ -217,7 +217,7 @@ func setupMockBroker(auth bool) *httptest.Server { // curl --user pactuser:pact -H "accept: application/hal+json" "http://pact.onegeek.com.au/pacts/provider/bobby/latest/sit4" mux.Handle("/pacts/provider/bobby/latest/dev", authFunc(func(w http.ResponseWriter, req *http.Request) { log.Println("[DEBUG] get all pacts for provider 'bobby' where the tag 'dev' exists") - fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest/dev","title":"Latest pact versions for the provider bobby with tag 'dev'"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.1","title":"Pact between billy (v1.0.1) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL) + fmt.Fprintf(w, `{"_links":{"self":{"href":"%s/pacts/provider/bobby/latest/dev","title":"Latest pact versions for the provider bobby with tag 'dev'"},"provider":{"href":"%s/pacticipants/bobby","title":"bobby"},"pb:pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.1","title":"Pact between billy (v1.0.1) and bobby","name":"billy"}],"pacts":[{"href":"%s/pacts/provider/bobby/consumer/billy/version/1.0.1","title":"OLD Pact between billy (v1.0.1) and bobby","name":"billy"}]}}`, server.URL, server.URL, server.URL, server.URL) w.Header().Add("Content-Type", "application/hal+json") }))