I have a nodejs App based on expressjs that I am testing using gruntjs as task runner and mochajs as test framework. Thus I have written component, integration and unit tests that are executed via grunt test or directly via mocha test/component/v1/apiX locally when I develop and on a test VM during deployment as part of a CI process.
Now when thinking about moving this app to an AWS Lambda aka going serverless the following questions come to mind regarding my testing and CI process (note that I am going to use aws-serverless-express and thus will not have to write lambda functions explicitely):
1) How to implement the component / e2e tests that are done via HTTP api requests?
2) How to implement the integration & unit tests that only load & test a part of the app?
3) How to integrate both with a new CI flow that rejects deployment if any of the tests fail?
I consider question 1) mostly solved: there are many approaches to test AWS Lambdas from the outside. You can do lamba-to-lambda testing calling your lambda-to-test from a test-lambda directly or you can call the lambda-to-test via AWS API Gateway using HTTP from test-lambda as described here. You can also use the serverless-mocha-plugin for local lambda testing (if using serverless).
It is 2) where it gets interesting: once your lambda is deployed it is a black box. You cannot execute anything that is not declared as lambda interface explicitely. How do I save or re-implement my mocha unit & integration tests?
Same for 3): how do you make your CI run all the tests on deployment and reject deployment if they fail?
Here my own approach: I would make my node app serverless only if in TEST environment. Simply let it work as classical node HTTP service by making all changes conditional depending on environment. Since few changes are required this should be possible and maintainable. Now I can run the tests as usual locally and on deployment with grunt and mocha. Then I can still have final lambda-to-lambda testing if I want to be sure the serverless version works as well.
Aucun commentaire:
Enregistrer un commentaire