Hi, I’m trying to play with `StateHandlers` but I ...
# pact-go
g
Hi, I’m trying to play with
StateHandlers
but I don’t see how I can change the response status code. Do you have an example?
👀 1
m
StateHandlers don’t exist to change the response directly from the verification, they exist to setup the internal state of the provider, such that they can return as needed
e.g. if you want a
404
you make sure a resource isn’t in the database vs a
200
where you ensure the resource does exist
g
@Matt (pactflow.io / pact-js / pact-go) mmh, Are you sure ? I’m using the pact-go V2 and the StateHandler must return a
ProviderStateV3Response
https://github.com/pact-foundation/pact-go/blob/2.x.x/examples/provider_test.go#L74-L88 My Pb is that ProviderStateV3Response is a map of fields used to generate the response body. But I cannot interact with other parts of the response. And If I return
nil
instead of the ProviderStateV3Response, that doesn’t call my ms. Do you have an example to interact with the database and
ProviderStateV3Response
?
m
StateHandlers
don’t have access to the request/response at all
They are like a hook for a specific test (interaction). They give you the opportunity to modify the internal state of the provider - but don’t give you access to the request/response
(
RequestFilters
can do that, but it’s not really used for this purpose)
My Pb is that ProviderStateV3Response is a map of fields used to generate the response body
no, the
ProviderStateV3Response
is not a response body for the provider test. It’s parameters to configure the current state setup
g
ok thank, I understand the point
👍 1