Hi all, Is it possible to inject a value from pro...
# pact-go
n
Hi all, Is it possible to inject a value from provider state into the URL of the request? If so is there any example for Pact-go ? (I am using v2.x.x)
w
What’s the context around what you want to do exactly? There are examples here of modifying the request before the test runs to add in authorization headers. It’s possible you could use that same function to modify the URL as well, but I’m not 100% clear on whether that’s necessarily a good idea or not
n
I have some ID's on the URL that need to match the ID's of objects created on the provider test.
The
RequestFilter
is a good shout. I was looking at the Pact-go equivalent of https://pactflow.io/blog/injecting-values-from-provider-states/ for URL, but
RequestFilter
should do it.
m
n
Thanks @Matt (pactflow.io / pact-js / pact-go) So on the consumer side I would have to put a placeholder on the URL. Something like this:
Copy code
...
WithRequest(http.MethodPost, "/ns/${uuid}/search, func(req *consumer.V4RequestBuilder) {
			req.Header("Content-Type", matchers.S("application/json"))
...
Assuming I returned provider state like in your example:
Copy code
return models.ProviderStateResponse{"uuid": "1234"}, nil
m
Yes, except on the consumer side imyou need to use a matcher and not a string:
FromProviderState(expr, example)
See the consumer docs for all matchers
n
Brilliant. Thank you very much @Matt (pactflow.io / pact-js / pact-go)