DEV Community

Mike Stemle
Mike Stemle Subscriber

Posted on

That awkward moment when you need to generate test data...

The Problem

I have a system which uses SNS to send mail messages to a Lambda for additional processing. The Lambda is written in JavaScript, and it has really good test coverage, but there are message shapes that aren't included.

All of the messages which go through the system get persisted into S3 in SMTP format, but the Lambda receives a JavaScript object in a known SNS shape as its input, not an SMTP message.

The Solution

Write a quick-and-dirty script to generate JSON from the SMTP message which is close enough to what the Lambda's input would be, so that I can add additional messages to the Lambda's unit tests as needed.

The Gist

Here's a gist of the script.

Conclusion

As I'm sure you noticed, that data isn't super clean. It's missing some key fields, so it's not 100%. However, my additional processing only needs the Message content, the Subject and a few fields from the receipt.

Thanks for looking at my quick-and-dirty, I had fun writing it. May your quick-and-dirties bring you joy as well.

(Update: Made a couple code fixes to the Gist)

Top comments (0)