Nuno Frias
04/21/2022, 9:54 AMYousaf Nabi (pactflow.io)
I can’t force the provider to send a message that is syntactically wrong (as the server code enforces the syntax), that leaves me with trying to send a message with wrong data.Are you trying to cover a case on your consumer side, where it handles the errors returned from your provider, in the case of bad data? If you can't force your provider to send a message that in syntactically wrong because the code enforces it, would you expect that scenario to happen in production, and therefore worthy of testing? What is the particular use case here, is your client posting a message to a queue and expecting to do something at some point later with the provider response. Where is the providers response being posted too? There is always a little overlap and I wouldn't be concerned but you wouldn't want to cover all the edge cases. If the shape of the error message is always the same, then you can just test that one case. If in specific error cases, you do some different work in your client, based on a specific response, then I would want a contract to cover that.
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Nuno Frias
04/21/2022, 10:32 AMAre you trying to cover a case on your consumer side, where it handles the errors returned from your provider, in the case of bad data?Correct. In this particular case the provider communicates with the consumer via kafka. Essentially when an upstream event occurs the provider writes an event to a kafka topic, which the consumer reads, does additional processing and then responds to another consumer further downstream. This interaction is started by the provider. I take it from your answer that I should handle the majority of unhappy paths (messages with wrong data) on the component tests, and pick a few relevant cases for Pact -- even that makes the tests overlap a bit. That makes sense to me.
Yousaf Nabi (pactflow.io)
Nuno Frias
04/21/2022, 10:48 AMBoris
04/21/2022, 10:53 AMBoris
04/21/2022, 10:53 AMBoris
04/21/2022, 10:54 AMBoris
04/21/2022, 10:56 AMNuno Frias
04/21/2022, 10:57 AMNuno Frias
04/21/2022, 10:58 AMNuno Frias
04/21/2022, 11:00 AMBoris
04/21/2022, 11:01 AMBoris
04/21/2022, 11:01 AMNuno Frias
04/21/2022, 11:02 AMBoris
04/21/2022, 11:02 AMBoris
04/21/2022, 11:02 AMBoris
04/21/2022, 11:03 AMThere is always a little overlap and I wouldn't be concerned but you wouldn't want to cover all the edge cases. If the shape of the error message is always the same, then you can just test that one case.
If in specific error cases, you do some different work in your client, based on a specific response, then I would want a contract to cover that.That pretty much covers the general advice 👌
Boris
04/21/2022, 11:04 AMBoris
04/21/2022, 11:04 AMBoris
04/21/2022, 11:06 AMBoris
04/21/2022, 11:07 AMNuno Frias
04/21/2022, 11:07 AMNuno Frias
04/21/2022, 11:08 AMBoris
04/21/2022, 11:10 AMNuno Frias
04/21/2022, 11:19 AMNuno Frias
04/21/2022, 11:20 AMNuno Frias
04/21/2022, 11:20 AMNuno Frias
04/21/2022, 11:26 AMI have centralised error handling at the gate where messages are marshalled through the data layer into domain-meaningful models, so I tend to only need one sad path in contracts, for each category of error. The branching for how the errors are handled can be done internally, outside of the contract.Essentially I only need a Pact test to exercise the bit of the client code that rejects the message and I can test the various error cases on the component tests / other unit tests.
Boris
04/21/2022, 11:33 AM