tests(parameters): end to end tests for DynamoDBProvider
#1244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR introduces the test suite that runs integration tests on the
DynamoDBProvider
which is part of the upcoming Parameters utility. The PR also introduces a few helper/utility functions that might be used by other test suites that also belong to the Parameters utility (namelyTinyLogger
,ResourceAccessGranter
, andmiddleware
).Test suite
The test suite deploys a CDK stack with a Lambda function and a number of DynamoDB tables. The function code uses the Parameters utility to retrieve values from the DynamoDB tables. It then logs the values to CloudWatch Logs as JSON.
Once the stack is deployed, the Lambda function is invoked and the CloudWatch Logs are retrieved. The logs are then parsed and the values are compared to the expected values in each test case.
The tables are populated with data before the Lambda function is invoked. These tables and values allow to test the different use cases of the
DynamoDBProvider
class.The tables are:
Table-Get
: a table with a single partition key (id) and attribute (value)"{\"foo\": \"bar\"}"
"YmF6"
Table-GetMultiple
: a table with a partition key (id) and a sort key (sk) and attribute (value)"{\"foo\": \"bar\"}"
"YmF6"
Table-GetCustomKeys
: a table with a single partition key (key) and attribute (val)Table-GetMultipleCustomKeys
: a table with a partition key (key) and a sort key (sort) and attribute (val)The tests are:
Test 1
Get a single parameter with default options (keyAttr: 'id', valueAttr: 'value') from table
Table-Get
.Test 2
Get multiple parameters with default options (keyAttr: 'id', sortAttr: 'sk', valueAttr: 'value') from table
Table-GetMultiple
.Test 3
Get a single parameter with custom options (keyAttr: 'key', valueAttr: 'val') from table
Table-GetCustomKeys
.Test 4
Get multiple parameters with custom options (keyAttr: 'key', sortAttr: 'sort', valueAttr: 'val') from table
Table-GetMultipleCustomKeys
.Test 5
Get a single JSON parameter with default options (keyAttr: 'id', valueAttr: 'value') and transform from table
Table-Get
.Test 6
Get a single binrary parameter with default options (keyAttr: 'id', valueAttr: 'value') and transform it from table
Table-Get
.Test 7
Get multiple JSON and binary parameters with default options (keyAttr: 'id', sortAttr: 'sk', valueAttr: 'value') and transform them automatically from table
Table-GetMultiple
.Test 8
Get a parameter twice and check that the value is cached. This uses a custom SDK client that counts the number of calls to DynamoDB. This reads from
Table-Get
.Test 9
Get a cached parameter and force retrieval. This also uses the same custom SDK client that counts the number of calls to DynamoDB. This reads from
Table-Get
.How to verify this change
Given that the integration tests are not yet hooked up to the GitHub workflow that runs them on GitHub, at the moment the only way to test this is to checkout the repo locally and then run:
npm run test:e2e:nodejs18x -w packages/parameters
.The command above will run the tests on your currently logged in AWS account and use the Node.js 18 runtime.
Related issues, RFCs
Issue number: #1243
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.