From 05b3e6539d3a42c214df8fd21a8997c0e94449e9 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Thu, 1 Jun 2017 13:43:36 +1000 Subject: [PATCH] feat(verification): remove ProviderStatesURL during verification --- README.md | 34 ++++--------------- doc.go | 28 ++------------- dsl/client_test.go | 1 - dsl/pact_integration_test.go | 11 +----- examples/gin/provider/user_service_test.go | 17 ---------- examples/go-kit/provider/user_service_test.go | 20 ----------- examples/mux/provider/user_service_test.go | 21 ------------ scripts/package.sh | 2 +- types/verify_request.go | 2 ++ 9 files changed, 12 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index 276c89a53..f195b45d9 100644 --- a/README.md +++ b/README.md @@ -265,8 +265,7 @@ Read more about [flexible matching](https://github.com/realestate-com-au/pact/wi ```go response := pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://localhost:8000", - PactURLs: []string{"./pacts/my_consumer-my_provider.json"}, - ProviderStatesURL: "http://localhost:8000/states", + PactURLs: []string{"./pacts/my_consumer-my_provider.json"}, ProviderStatesSetupURL: "http://localhost:8000/setup", }) @@ -292,8 +291,7 @@ When validating a Provider, you have 3 options to provide the Pact files: ```go response = pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://myproviderhost", - PactURLs: []string{"http://broker/pacts/provider/them/consumer/me/latest/dev"}, - ProviderStatesURL: "http://myproviderhost/states", + PactURLs: []string{"http://broker/pacts/provider/them/consumer/me/latest/dev"}, ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -304,8 +302,7 @@ When validating a Provider, you have 3 options to provide the Pact files: ```go response = pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://myproviderhost", - BrokerURL: "http://brokerHost", - ProviderStatesURL: "http://myproviderhost/states", + BrokerURL: "http://brokerHost", ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -317,8 +314,7 @@ When validating a Provider, you have 3 options to provide the Pact files: response = pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://myproviderhost", BrokerURL: "http://brokerHost", - Tags: []string{"latest", "sit4"}, - ProviderStatesURL: "http://myproviderhost/states", + Tags: []string{"latest", "sit4"}, ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -348,11 +344,10 @@ with a corresponding request/response pair. Configuring the provider is a little more involved, and (currently) requires 2 running API endpoints to retrieve and configure available states during the -verification process. The two options you must provide to the dsl.VerifyRequest -are: +verification process. The option you must provide to the dsl.VerifyRequest +is: ```go -ProviderStatesURL: GET URL to fetch all available states (see types.ProviderStates) ProviderStatesSetupURL: POST URL to set the provider state (see types.ProviderState) ``` @@ -360,23 +355,6 @@ Example routes using the standard Go http package might look like this, note the `/states` endpoint returns a list of available states for each known consumer: ```go -// Return known provider states to the verifier (ProviderStatesURL): -mux.HandleFunc("/states", func(w http.ResponseWriter, req *http.Request) { - states := - `{ - "My Front end consumer": [ - "User A exists", - "User A does not exist" - ], - "My api friend": [ - "User A exists", - "User A does not exist" - ] - }` - fmt.Fprintf(w, states) - w.Header().Add("Content-Type", "application/json") -}) - // Handle a request from the verifier to configure a provider state (ProviderStatesSetupURL) mux.HandleFunc("/setup", func(w http.ResponseWriter, req *http.Request) { w.Header().Add("Content-Type", "application/json") diff --git a/doc.go b/doc.go index cd4ad1a3a..7fb70145b 100644 --- a/doc.go +++ b/doc.go @@ -138,7 +138,6 @@ A typical Provider side test would like something like: err := pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://localhost:8000", PactURLs: []string{"./pacts/my_consumer-my_provider.json"}, - ProviderStatesURL: "http://localhost:8000/states", ProviderStatesSetupURL: "http://localhost:8000/setup", }) @@ -164,7 +163,6 @@ When validating a Provider, you have 3 options to provide the Pact files: response = pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://myproviderhost", PactURLs: []string{"http://broker/pacts/provider/them/consumer/me/latest/dev"}, - ProviderStatesURL: "http://myproviderhost/states", ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -175,7 +173,6 @@ When validating a Provider, you have 3 options to provide the Pact files: response = pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: "http://myproviderhost", BrokerURL: brokerHost, - ProviderStatesURL: "http://myproviderhost/states", ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -187,7 +184,6 @@ When validating a Provider, you have 3 options to provide the Pact files: ProviderBaseURL: "http://myproviderhost", BrokerURL: brokerHost, Tags: []string{"latest", "sit4"}, - ProviderStatesURL: "http://myproviderhost/states", ProviderStatesSetupURL: "http://myproviderhost/setup", BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -216,32 +212,12 @@ with a corresponding request/response pair. Configuring the provider is a little more involved, and (currently) requires 2 running API endpoints to retrieve and configure available states during the -verification process. The two options you must provide to the dsl.VerifyRequest +verification process. The option you must provide to the dsl.VerifyRequest are: - ProviderStatesURL: GET URL to fetch all available states (see types.ProviderStates) ProviderStatesSetupURL: POST URL to set the provider state (see types.ProviderState) -Example routes using the standard Go http package might look like this, note -the `/states` endpoint returns a list of available states for each known consumer: - - // Return known provider states to the verifier (ProviderStatesURL): - mux.HandleFunc("/states", func(w http.ResponseWriter, req *http.Request) { - var states types.ProviderStates - states = - `{ - "My Front end consumer": [ - "User A exists", - "User A does not exist" - ], - "My api friend": [ - "User A exists", - "User A does not exist" - ] - }` - fmt.Fprintf(w, states) - w.Header().Add("Content-Type", "application/json") - }) +Example routes using the standard Go http package might look like this: // Handle a request from the verifier to configure a provider state (ProviderStatesSetupURL) mux.HandleFunc("/setup", func(w http.ResponseWriter, req *http.Request) { diff --git a/dsl/client_test.go b/dsl/client_test.go index 3e63d960c..2cafdb19a 100644 --- a/dsl/client_test.go +++ b/dsl/client_test.go @@ -238,7 +238,6 @@ func TestClient_VerifyProvider(t *testing.T) { PactURLs: []string{"foo.json", "bar.json"}, BrokerUsername: "foo", BrokerPassword: "foo", - ProviderStatesURL: "http://foo/states", ProviderStatesSetupURL: "http://foo/states/setup", } _, err := client.VerifyProvider(req) diff --git a/dsl/pact_integration_test.go b/dsl/pact_integration_test.go index 40b0bf3d6..2672d7639 100644 --- a/dsl/pact_integration_test.go +++ b/dsl/pact_integration_test.go @@ -133,7 +133,6 @@ func TestPact_Integration(t *testing.T) { err = providerPact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort), PactURLs: []string{fmt.Sprintf("%s/billy-bobby.json", pactDir)}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", providerPort), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort), PublishVerificationResults: false, // No HAL links in local pacts }) @@ -146,7 +145,6 @@ func TestPact_Integration(t *testing.T) { err = providerPact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort), PactURLs: []string{fmt.Sprintf("%s/pacts/provider/bobby/consumer/billy/latest/sit4", brokerHost)}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", providerPort), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort), BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -162,7 +160,6 @@ func TestPact_Integration(t *testing.T) { err = providerPact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort), BrokerURL: brokerHost, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", providerPort), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort), BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), @@ -177,10 +174,9 @@ func TestPact_Integration(t *testing.T) { // Verify the Provider - Tag-based Published Pacts for any known consumers err = providerPact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort), + ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort), BrokerURL: brokerHost, Tags: []string{"latest", "sit4"}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", providerPort), - ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort), BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"), BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"), PublishVerificationResults: true, @@ -201,11 +197,6 @@ func setupProviderAPI() int { log.Println("[DEBUG] provider API: states setup") w.Header().Add("Content-Type", "application/json") }) - mux.HandleFunc("/states", func(w http.ResponseWriter, req *http.Request) { - log.Println("[DEBUG] provider API: states") - fmt.Fprintf(w, `{"billy": ["Some state", "Some state2"]}`) - w.Header().Add("Content-Type", "application/json") - }) mux.HandleFunc("/foobar", func(w http.ResponseWriter, req *http.Request) { log.Println("[DEBUG] provider API: /foobar") w.Header().Add("Content-Type", "application/json") diff --git a/examples/gin/provider/user_service_test.go b/examples/gin/provider/user_service_test.go index 6b6dad647..0818b003d 100644 --- a/examples/gin/provider/user_service_test.go +++ b/examples/gin/provider/user_service_test.go @@ -2,7 +2,6 @@ package provider import ( "fmt" - "net/http" "os" "testing" @@ -23,7 +22,6 @@ func TestPact_Provider(t *testing.T) { err := pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port), PactURLs: []string{fmt.Sprintf("%s/billy-bobby.json", pactDir)}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", port), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port), }) @@ -37,7 +35,6 @@ func TestPact_Provider(t *testing.T) { func startInstrumentedProvider() { router := gin.Default() router.POST("/users/login", UserLogin) - router.GET("/states", providerStates) router.POST("/setup", providerStateSetup) router.Run(fmt.Sprintf(":%d", port)) @@ -58,20 +55,6 @@ func providerStateSetup(c *gin.Context) { } } -// This path returns all states available for the consumer 'billy' -// Note that the key for the array is the consumer name (in this case, 'billy') -// The values should match a Given("...") block in the Interaction. Essentially, -// this broadcasts the allowed states of the provider for verification, it is not -// necessary for all consumers to use all states. -func providerStates(c *gin.Context) { - c.JSON(http.StatusOK, map[string][]string{ - "billy": []string{ - "User billy exists", - "User billy does not exist", - "User billy is unauthorized"}, - }) -} - // Configuration / Test Data var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../../pacts", dir) diff --git a/examples/go-kit/provider/user_service_test.go b/examples/go-kit/provider/user_service_test.go index f9bd43910..589c72d6a 100644 --- a/examples/go-kit/provider/user_service_test.go +++ b/examples/go-kit/provider/user_service_test.go @@ -58,7 +58,6 @@ func TestPact_Provider(t *testing.T) { err := pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port), PactURLs: []string{fmt.Sprintf("%s/billy-bobby.json", pactDir)}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", port), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port), }) @@ -130,25 +129,6 @@ func startInstrumentedProvider() { logger.Log("[DEBUG] configured provider state: ", state.State) }) - // This path returns all states available for the onsumer 'billy' - // Note that the key for the array is the onsumer name (in this case, 'billy') - // The values should match a Given("...") block in the Interaction. Essentially, - // this broadcasts the allowed states of the provider for verification, it is not - // necessary for all consumers to use all states. - router.Methods("GET").Path("/states").HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - logger.Log("[DEBUG] returning available provider states") - w.Header().Add("Content-Type", "application/json") - var states types.ProviderStates - states = map[string][]string{ - "billy": []string{ - "User billy exists", - "User billy does not exist", - "User billy is unauthorized"}, - } - data, _ := json.Marshal(states) - fmt.Fprintf(w, string(data)) - }) - errs := make(chan error) go func() { c := make(chan os.Signal) diff --git a/examples/mux/provider/user_service_test.go b/examples/mux/provider/user_service_test.go index ec2c94d4e..88df9b48c 100644 --- a/examples/mux/provider/user_service_test.go +++ b/examples/mux/provider/user_service_test.go @@ -26,7 +26,6 @@ func TestPact_Provider(t *testing.T) { err := pact.VerifyProvider(types.VerifyRequest{ ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port), PactURLs: []string{fmt.Sprintf("%s/billy-bobby.json", pactDir)}, - ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", port), ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port), }) @@ -41,7 +40,6 @@ func startInstrumentedProvider() { mux := http.NewServeMux() mux.HandleFunc("/users/login", UserLogin) mux.HandleFunc("/setup", providerStateSetupFunc) - mux.HandleFunc("/states", providerStatesFunc) ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { @@ -54,13 +52,6 @@ func startInstrumentedProvider() { } -// Get all states route. -var providerStatesFunc = func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - body, _ := json.Marshal(providerStates) - w.Write(body) -} - // Set current provider state route. var providerStateSetupFunc = func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") @@ -90,18 +81,6 @@ var providerStateSetupFunc = func(w http.ResponseWriter, r *http.Request) { } } -// This path returns all states available for the consumer 'billy' -// Note that the key for the array is the consumer name (in this case, 'billy') -// The values should match a Given("...") block in the Interaction. Essentially, -// this broadcasts the allowed states of the provider for verification, it is not -// necessary for all consumers to use all states. -var providerStates = map[string][]string{ - "billy": []string{ - "User billy exists", - "User billy does not exist", - "User billy is unauthorized"}, -} - // Configuration / Test Data var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../../pacts", dir) diff --git a/scripts/package.sh b/scripts/package.sh index d0ed46594..9d4106e9c 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -3,7 +3,7 @@ set -e export PACT_MOCK_SERVICE_VERSION=2.1.0 # Seg faults... -export PACT_PROVIDER_VERIFIER_VERSION=1.0.1 +export PACT_PROVIDER_VERIFIER_VERSION=1.1.0 # Create the OS specific versions of the mock service and verifier echo "==> Building Ruby Binaries..." diff --git a/types/verify_request.go b/types/verify_request.go index 3a1a82246..32be19818 100644 --- a/types/verify_request.go +++ b/types/verify_request.go @@ -20,6 +20,7 @@ type VerifyRequest struct { Tags []string // URL to retrieve valid Provider States. + // Deprecation notice: no longer valid/required ProviderStatesURL string // URL to post currentp provider state to on the Provider API. @@ -69,6 +70,7 @@ func (v *VerifyRequest) Validate() error { v.Args = append(v.Args, v.ProviderStatesSetupURL) } + // Field is deprecated, leave here to see deprecation notice if v.ProviderStatesURL != "" { v.Args = append(v.Args, "--provider-states-url") v.Args = append(v.Args, v.ProviderStatesURL)