In this demo we will showcase two different contract testing approaches, as showed in the Bugbusters contrac testing meetup.
- Node
- Yarn / NPM
- Go
- Your folder is inside $GOPATH
cd pactcd consumer
yarn
yarn jestThis will generate the corresponding pact under the pacts folder, which will then be used to validate our provider.
Ensure you've installed pact's CLI Tools.
cd provider
go test . -vcd swaggerThe API definition is under apidocs/specs/openapi.yaml
To run our consumer, we will be using Prism.
Be sure to have Prism installed: curl https://raw.githubusercontent.com/stoplightio/prism/2.x/install.sh | sh
cd consumer
prism mock -s ../apidocs/specs/openapi.yamlThis will create a Prism mock server based on our specifications. Prism will remain running in the foreground. So, in another terminal...
cd consumer
yarn
yarn jestThis will validate our consumer against our Prism mock server, making sure that what the consumer expects is the same as the specifications in our swagger definition.
First, let's make sure we have Dredd installed:
yarn global add dredd
In order to validate our provider, we will need to run the service first, so it can respond in its endpoints.
cd provider
go run provider.goThis will leave our provider running in the foreground, so in another terminal we can run dredd against the service:
cd provider
dredd ~/dev/go/src/github.com/pboix/contract-demo/swagger/apidocs/specs/openapi.yaml http://localhost:8000