pact-foundation / pact-go

Golang version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
http://pact.io
MIT License
842 stars 107 forks source link

Allow `.WithMetadata` function to use pact DSL rather than static values #217

Open nsfrias opened 2 years ago

nsfrias commented 2 years ago

Software versions

Expected behaviour

WithMetadata method of github.com/pact-foundation/pact-go/v2/message should accept Pact DSL as argument (something like map[string]Matcher similarly to WithJSONContent) to allow us to set an expectation for metadata properties that are not static -- for example a timestamp.

Actual behaviour

WithMetadata method of github.com/pact-foundation/pact-go/v2/message only accepts a map[string]string thus allowing us to define only static metadata properties.

nsfrias commented 2 years ago

Working on this.

nsfrias commented 2 years ago

Hi,

After some investigation I found that the pact_ffi rust library needs to be changed to allow metadata to include matchers, the changes that need to happen in my view are:

In addition to this a very minor change is required in WithMetadata function in pact-go/internal/native/message_server.go to build the matching rule (using stringFromInterface()).

The rust changes will take me a bit as I am yet not very familiar with it. :(