Skip to content

Tools to convert Pact (https://pact.io) contracts into executable stubs & test cases

Notifications You must be signed in to change notification settings

monch1962/pact-to-karate

Repository files navigation

Build Status

Quality Gate Status Technical Debt Code Smells Coverage Lines of Code Security Rating Vulnerabilities

pact-to-karate

Code to take Pact contracts as input and convert them to executable (consumer-side) test cases & (provider-side) stubs.

Assumptions

Either you have a Go build environment to compile the executable, or a Docker environment which you can use to build a Docker image containing the Go executable

Templates

Test case & stub generation is delivered via Handlebars templates; the various template files are stored under ./templates. The intention is that this collection of templates will grow and evolve over time to cover a broader range of tools (e.g. Mountebank stubs, Hoverfly stubs, Node/mocha/chai test cases, ...) and you'll be able to pick and choose which languages/tools/frameworks you want to use

To use one of these templates, you need to specify it via the environment variable TEMPLATE when you run either the Go code or the Docker container

To generate e.g. a set of Karate tests, you could run e.g. $ cat sample-pacts/sample-pact-extended2.v2.json | TEMPLATE=karate-tests go run main.go

To generate a Karate stub, you could run e.g. $ cat sample-pacts/sample-pact-extended2.v2.json | TEMPLATE=karate-stub go run main.go

To use

To run interpreted version locally

$ cat sample-pacts/sample-pact-extended2.v2.json | TEMPLATE=karate-stub go run main.go

To run compiled version locally

$ go build main.go

$ cat sample-pacts/sample-pact-extended2.v2.json | TEMPLATE=karate-stub ./main

To run inside Docker container

$ docker build -t pact-karate .

$ cat sample-pacts/sample-pact-extended2.v2.json | docker run -e TEMPLATE=karate-stub -i pact-karate:latest

About

Tools to convert Pact (https://pact.io) contracts into executable stubs & test cases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published