Closed mikemadisonweb closed 3 years ago
I'll take a look a little later, but at first glance it looks ok. You might need to specify the content type for the request though also
Thanks for the answer! Very strange indeed, I have created a minimal app with this pact and it worked fine: https://bitbucket.org/mikemadweb/pact-go-minimal/src/master/
I will dig deeper for an issue in the original app.
Awesome, thanks @mikemadisonweb. It is documented in the readme, but only in the example consumer test with a comment. I'll make this for documentation enhancement because it's not immediately obvious.
Thanks for the report and taking the time to create a repro.
Ok, so I guess I got the whole picture now. So as I mentioned previously setting Content-Type explicitly solved the case. Still why I received an empty request in the code was a mystery. I'm using Echo framework by the way and it has Bind() method, which populates the request struct depending on the request content type. If the Content-Type header was missing there would be a meaningful message that media type is not supported, seems like Pact uses application/x-www-form-urlencoded as a default. In the case of application/x-www-form-urlencoded Echo does not throw an error if the request body is JSON, but just ignores the body. That is why the request was empty.
I have updated the minimal repo with these details, just in case.
Thanks! Yes, that all makes sense to me. Pact will do what you tell it, basically, and omitting content-type
it will default to something sensible - in this case application/x-www-form-urlencoded
(I believe this is standard in many frameworks as there is a body).
As mentioned, I'll make a note that if using JSON the correct header should be sent.
Docs updated.
More like a question, maybe I misunderstood the concept. I'm trying to verify the provider with a local pact file I generated from the client test. All the tests are running in Docker. I have a POST request with a body, but upon verification the API handler receives an empty request, so validation fails and tests fail. I need some help here.
Software versions
go 1.14
Tests executing in the docker containers.
Expected behaviour
Empty request body received by API.
Actual behaviour
Request body from pact file received by API.
Steps to reproduce
This is a simplified version of the tests and the pact file: