Password Store – Weekly update

Last Friday, I implemented the last part of the basic testing for the Password File API.

To perform the unit testing for the lambda, I went for a pretty basic solution: no SAM image deployment of any kind, this will come later on.

The pseudo environment:

I’m creating a library to handle both boto3 mock-up and lambda environment. For the moment it’s integrated within the package but I’ll most likely end up splitting this to a new package.

The lambda is created by the lambda_handler.py file in the test folder.

Contains 3 important features:

  • load_event function: this one will load an event from the the lambda_events folder into a dictionary
  • LambdaContext class: this is a mock-up of the lambda context item passed to a lambda handler by AWS.
  • start_lambda function: this one will load the event, then create a lambda_context or use one. Setup the lambda start time, and raise an exceptions if the lambda takes more than the time_out to run.

The idea here, is to get an easy access to any part of the lambda context, have an easy to read lambda event and fail the test is the lambda takes already too long to run in the ideal situation that is the unit test.

Using this I also did a bit of update in the unit test code to use this script.

Note that while writing these lines, I realize that I should add an environment dictionary to start_lambda and implement a mocking of os.getenv() to it so I can also pass environment variables to the lambda.

Next Week:

Initially, I wanted to move to implementing the rest of the boto3 API I need, but on the context and knowledge sharing standpoint it would make more sense to implement the lambda first. Then get back to the unit test and explain the mocking and how this works.

0 Replies to “Password Store – Weekly update”

Leave a Reply

Your email address will not be published. Required fields are marked *