- Ruby shared core has been replaced by the Rust shared core
- In general, the interface has been reduced in favour of encouraging use of the Pact [CLI tools]
Publisher
interface has been removed- Ability to create and verify both [v2] and [v3] [specification] pacts
- A bunch of new features, including the new v3 specification matchers and generators, injected provider states and more.
- Each test is given a dedicated server and port, simplifying lifecycle events and improving isolation between tests.
- You must clear out any pact directory prior to the tests running. Any pact files will be appended to during test execution or may result in conflicts.
The new package is migratable, with the the /v2
major version bump
i.e. github.com/pact-foundation/pact-go/v2
By default, all logging is to stdout.
You can configure logging with the following environment variables:
PACT_LOG_LEVEL
(it also respectsLOG_LEVEL
) - the level to log at. Must be one of "trace", "debug", "info", "warn", "error" or "off".PACT_LOG_PATH
- a path to a file to redirect logs
dsl.Pact
was the primary interface. This is now replaced withNewV2Pact
and theNewV3Pact
methods, which will return you a builder for the corresponding specification.Verify
is nowExecuteTest
to avoid ambiguity with provider side verification. It also accepts a*testing.T
argument, to improve error reporting and resolution.
These are available in consumer package: "github.com/pact-foundation/pact-go/v2/consumer"
The interface now also exposes an improved builder interface that aids discoverability, better types and readability. The previous "all-in-one" request/response style has been preserved (WithCompleteRequest
and WithCompleteResponse
), to aid in migration. See the TestConsumerV2AllInOne
test in the examples to see this in action.
The test function provided to Verify
now accepts a func(MockServerConfig) error
(previously a func() error
).
The test function will receive the details of the mock server configuration, such as the host and port, which may be useful in configuring the test HTTP client, for example. This prevents the need to maintain global state between tests as was previously the case.
You can now use proper POSIX compliant regexes :)
the NewV2Pact
and NewV3Pact
interfaces are not thread safe (i.e. you shouldn't run parallel tests with them), but you don't need to. Here is one of the examples run on a loop 1000 times, writing to a different file on each run:
➜ examples ✗ time go test -count=1 -tags=consumer -run TestConsumerV2 .
ok github.com/pact-foundation/pact-go/examples 4.269s
go test -count=1 -tags=consumer -run TestConsumerV2 . 4.34s user 1.93s system 113% cpu 5.542 total
➜ examples ✗ ls -la pacts/*.json | wc -l
1001
➜ examples ✗
There is no real need, when in < 5 seconds you can run 1000 consumer pact tests!
The content-type
is now a mandatory field, to improve matching for bodies of various types.
Two new builder methods exist for binary/file payloads:
WithBinaryBody
accepts a[]byte
for matching on binary payloads (e.g. images)WithMultipartFile
accepts a path to file from the file system, and the multipart boundary
Query strings are now accepted (and encoded) as nested data structures, instead of flat strings and may have an array of values.
dsl.Pact
was the primary interface. This is now replaced withHTTPVerifier
struct andVerifyProvider
method.
These are available in provider package: "github.com/pact-foundation/pact-go/v2/provider"
Consumers may now specify multiple provider states. When the provider verifies them, it will invoke the StateHandler
for each of the states in the interaction.
The StateHandler
type has also changed in 3 important ways:
- Provider states may contain [parameters], which may be useful for the state setup (e.g. data for creation of a state)
- There is now a
setup
bool, indicating if the state is being setup or torn down. This is helpful for cleaning up state specific items (separate toAfterEach
andBeforeEach
which do not have access to the current state information) - If the consumer code uses provider state injected values (citation needed), the provider may return a JSON payload that will be substituted into the incoming request. See this example for more
dsl.Pact
was the primary interface. This is now replaced withNewMessagePactV3
builder. TheVerifyMessageConsumer
method is now replaced by the methodVerify
on the builder.
dsl.Pact
was the primary interface. This is now replaced by theMessageVerifier
struct and theVerify
method. The main difference is the state handlers, as discussed above.
These are available in message package: "github.com/pact-foundation/pact-go/v2/message"