I'm new to the server-less world using Amazon AWS and I try to understand the thumb rules of writing integration tests.
Lets give the following simple system we want to test:
We have a supermarket for which we want to save all the receipts. The system contains a DB with single table for the data. A job queue which contains all the transactions that need to be handled and couple of workers which do some pre-process on each job in the queue and then commit the result to the DB.
We want to test the next scenario:
- Initialize new DB and queue
- Initialize couple of workers
- Insert jobs to the queue
- Wait
- Validate the result
- clean the environment
By cleaning the environment, the next time we run the tests, the same result would come. If we won't do it, and for example, data will left in the DB, it will affect the validation of the next time we run the tests.
My experience is working with dockers. With them, I could docker-compose up
a new DB and queues at the set-up and docker-compose down
all the containers at tear-down. This is a simple solution.
Now, the question is what's the good way to do such tests for my server-less AWS application?
The db is dynamo db
. The queues are sqs
and the "workers" are lambda
s which trigger on sqs insertion. Of course it's an "easy" example and it's quite over kill but the question is larger than the specific case.
The solutions I found so far:
- Use local services such as local dynamo DB which is official by Amazon. But also local SQS which is not official nor supported by them. Cons: the results can be different with Amazon services at deployment.
- Use
sam deploy
each time to run the tests on amazon. I can create a new stack but the resources are left in Amazon's servers forever (such as s3 buckets and queues). Cons: the code isn't local and hard to debug + takes time deploy. - Use the same resources for all the tests and clean them at the beginning. Cons: ugly code and option for a lot of code duplication between projects.
From what I searched, there is no common "how to write tests tutorial" and I would like to hear from your experience.