Skip to content

Commit

Permalink
feat(verification): remove ProviderStatesURL during verification
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 1, 2017
1 parent e793898 commit 05b3e65
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 124 deletions.
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})

Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -348,35 +344,17 @@ 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)
```

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")
Expand Down
28 changes: 2 additions & 26 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion dsl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions dsl/pact_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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")
Expand Down
17 changes: 0 additions & 17 deletions examples/gin/provider/user_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package provider

import (
"fmt"
"net/http"
"os"
"testing"

Expand All @@ -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),
})

Expand All @@ -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))
Expand All @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions examples/go-kit/provider/user_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions examples/mux/provider/user_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand All @@ -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 {
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
2 changes: 2 additions & 0 deletions types/verify_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 05b3e65

Please sign in to comment.