Skip to content

Commit

Permalink
wip: working examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Dec 9, 2017
1 parent 881085a commit d1e175f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ including [flexible matching](http://docs.pact.io/documentation/matching.html).
- [Matching (Consumer Tests)](#matching-consumer-tests)
- [Provider](#provider)
- [Provider Verification](#provider-verification)
- [Publishing Verification Results to a Pact Broker](#publishing-verification-results-to-a-pact-broker)
- [API with Authorization](#api-with-authorization)
- [Broker](#broker)
- [Publishing Verification Results to a Pact Broker](#publishing-verification-results-to-a-pact-broker)
- [Publishing Pacts to a Broker and Tagging Pacts](#publishing-pacts-to-a-broker-and-tagging-pacts)
- [Publishing from Go code](#publishing-from-go-code)
- [Publishing from the CLI](#publishing-from-the-cli)
- [Using the Pact Broker with Basic authentication](#using-the-pact-broker-with-basic-authentication)
- [Publishing from Go code](#publishing-from-go-code)
- [Publishing from the CLI](#publishing-from-the-cli)
- [Using the Pact Broker with Basic authentication](#using-the-pact-broker-with-basic-authentication)
- [Troubleshooting](#troubleshooting)
- [Splitting tests across multiple files](#splitting-tests-across-multiple-files)
- [Output Logging](#output-logging)
Expand Down Expand Up @@ -361,7 +363,28 @@ for more on this strategy.
For more on provider states, refer to http://docs.pact.io/documentation/provider_states.html.
#### Publishing Verification Results to a Pact Broker
#### API with Authorization
Sometimes you may need to add things to the requests that can't be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. e.g. an OAuth bearer token: `Authorization: Bearer 0b79bab50daca910b000d4f1a2b675d604257e42`.

For this case, we have a facility that should be carefully used during verification - the ability to specificy custom headers to be sent during provider verification. The flag to achieve this is `customProviderHeaders`.

For example, to have two headers sent as part of the verification request, modify the `verifyProvider` options as per below:

```js
let opts = {
provider: 'Animal Profile Service',
...
customProviderHeaders: ['Authorization: Bearer e5e5e5e5e5e5e5', 'SomeSpecialHeader: some specialvalue']
}
return new Verifier().verifyProvider(opts).then(output => { ... })
```

## Broker


### Publishing Verification Results to a Pact Broker

If you're using a Pact Broker (e.g. a hosted one at pact.dius.com.au), you can
publish your verification results so that consumers can query if they are safe
Expand All @@ -385,7 +408,7 @@ See the [Pact Broker](http://docs.pact.io/documentation/sharings_pacts.html)
documentation for more details on the Broker and this [article](http://rea.tech/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices/)
on how to make it work for you.
#### Publishing from Go code
### Publishing from Go code
```go
p := Publisher{}
Expand All @@ -397,7 +420,7 @@ err := p.Publish(types.PublishRequest{
})
```
#### Publishing from the CLI
### Publishing from the CLI
Use a cURL request like the following to PUT the pact to the right location,
specifying your consumer name, provider name and consumer version.
Expand All @@ -410,7 +433,7 @@ curl -v \
http://your-pact-broker/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0
```
#### Using the Pact Broker with Basic authentication
### Using the Pact Broker with Basic authentication
The following flags are required to use basic authentication when
publishing or retrieving Pact files to/from a Pact Broker:
Expand Down
2 changes: 1 addition & 1 deletion examples/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestProvider(t *testing.T) {
ProviderBaseURL: "http://localhost:8000",
PactURLs: []string{filepath.ToSlash(fmt.Sprintf("%s/myconsumer-myprovider.json", pactDir))},
ProviderStatesSetupURL: "http://localhost:8000/setup",
CustomProviderHeaders: []string{"Authorization: blahblah"},
CustomProviderHeaders: []string{"Authorization: basic e5e5e5e5e5e5e5"},
})
}

Expand Down
27 changes: 9 additions & 18 deletions types/verify_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,54 +66,45 @@ func (v *VerifyRequest) Validate() error {

if len(v.CustomProviderHeaders) != 0 {
for _, header := range v.CustomProviderHeaders {
v.Args = append(v.Args, "--custom-provider-header ")
v.Args = append(v.Args, header)
v.Args = append(v.Args, "--custom-provider-header", header)
}
}

v.Args = append(v.Args, "--format", "json")

if v.ProviderBaseURL != "" {
v.Args = append(v.Args, "--provider-base-url")
v.Args = append(v.Args, v.ProviderBaseURL)
v.Args = append(v.Args, "--provider-base-url", v.ProviderBaseURL)
} else {
return fmt.Errorf("Provider base URL is mandatory")
}

if v.ProviderStatesSetupURL != "" {
v.Args = append(v.Args, "--provider-states-setup-url")
v.Args = append(v.Args, v.ProviderStatesSetupURL)
v.Args = append(v.Args, "--provider-states-setup-url", 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)
v.Args = append(v.Args, "--provider-states-url", v.ProviderStatesURL)
}

if v.BrokerUsername != "" {
v.Args = append(v.Args, "--broker-username")
v.Args = append(v.Args, v.BrokerUsername)
v.Args = append(v.Args, "--broker-username", v.BrokerUsername)
}

if v.BrokerPassword != "" {
v.Args = append(v.Args, "--broker-password")
v.Args = append(v.Args, v.BrokerPassword)
v.Args = append(v.Args, "--broker-password", v.BrokerPassword)
}

if v.ProviderVersion != "" {
v.Args = append(v.Args, "--provider_app_version")
v.Args = append(v.Args, v.ProviderVersion)
v.Args = append(v.Args, "--provider_app_version", v.ProviderVersion)
}

if v.PublishVerificationResults {
v.Args = append(v.Args, "--publish_verification_results")
v.Args = append(v.Args, "true")
v.Args = append(v.Args, "--publish_verification_results", "true")
}

if v.Verbose {
v.Args = append(v.Args, "--verbose")
v.Args = append(v.Args, fmt.Sprintf("%v", v.Verbose))
v.Args = append(v.Args, "--verbose", fmt.Sprintf("%v", v.Verbose))
}
return nil
}

0 comments on commit d1e175f

Please sign in to comment.