Skip to content

Commit

Permalink
docs: clarify what a provider state is
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 15, 2021
1 parent e74840a commit 25f0562
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ Two builder methods exist for binary/file payloads:

### Managing Test Data (using Provider States)

Each interaction in a pact should be verified in isolation, with no context maintained from the previous interactions. Tests that depend on the outcome of previous tests are brittle and hard to manage.
Provider states is the feature that allows you to test a request that requires data to exist on the provider.

Read more about [provider states](https://docs.pact.io/getting_started/provider_states/)

There are several ways to define a provider state:

1. Using the `Given` builder method passing in a plain string.
Expand Down
9 changes: 7 additions & 2 deletions docs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ func TestV3HTTPProvider(t *testing.T) {
}
```

### Managing Data (Provider States)
### Managing Test Data (Provider States)

If you have defined any states (as denoted by a `Given()`) in your consumer tests, the `Verifier` can put the provider into the correct state prior to sending the actual request for validation. For example, the provider can use the state to mock away certain database queries. To support this, set up a `StateHandler` for each state using hooks on the `StateHandlers` property. Here is an example:
Each interaction in a pact should be verified in isolation, with no context maintained from the previous interactions. Tests that depend on the outcome of previous tests are brittle and hard to manage.
Provider states is the feature that allows you to test a request that requires data to exist on the provider.

Read more about [provider states](https://docs.pact.io/getting_started/provider_states/).

If you have defined any states (as denoted by a `Given()`) in your consumer tests, the `Verifier` can put the provider into the correct state prior to sending the actual request for validation. For example, the provider can use the state to mock away certain API endpoints or seed data into a database. To support this, you registar a `StateHandler` func for each state using hooks on the `StateHandlers` property. Here is an example:

```go
pact.VerifyProvider(t, types.VerifyRequest{
Expand Down

0 comments on commit 25f0562

Please sign in to comment.