Home > Mobile >  Pact contract testing between aws services
Pact contract testing between aws services

Time:09-29

I'm trying to understand how Pact can be used to test message-based communication between two services.

Say I have two lambdas A and B where A communicate using DynamoDB streams, so if I insert an item

{"hello":"world"}

then this would trigger a message to B which would be marshaled in the following format

{"hello":{"S":"world"} 

which would be accessible in the field event.Record.dynamodb.NewImage. How would Pact help me in this situation to ensure that B actually receives what is expected when the two objects differ so heavily?

In this case, I already know that the message gets marshaled, but it is something that is so easy to miss and ideally is the type of thing I'd like to cover with a tool that markets itself as a contract-testing tool.

CodePudding user response:

I've not tried testing a DynamoDB stream. Whilst in theory it should be possible, in practice it might be hard to run the provider side of the test in a reliable and isolated way because you don't control the provider - i.e. you'll probably need to do some funkiness to trigger DynamoDB to emit to the stream and pass it to Pact to verify.

The key trick is to remove any "protocol" specific elements from the test, trusting in this case, that AWS will always comply with its stated interface. So it's aligned with what you're wanting to do (just check the payload).

I don't have any better answers, but you might find inspiration in https://docs.pact.io/getting_started/how_pact_works#how-to-write-message-pact-tests for more on the general approach, and https://docs.pactflow.io/docs/examples/kafka/java/consumer for an example with Kafka.

  • Related