Skip to content

tests(parameters): end to end tests for DynamoDBProvider #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Jan 13, 2023

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 (namely TinyLogger, ResourceAccessGranter, and middleware).

Note
The tests 7 & 8 will be added once #1222 gets resolved as they require the provider to accept a custom sdk client.

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)

id value
my-param foo
my-param-json "{\"foo\": \"bar\"}"
my-param-binary "YmF6"

Table-GetMultiple: a table with a partition key (id) and a sort key (sk) and attribute (value)

id sk value
my-params config bar
my-params key baz
my-encoded-params config.json "{\"foo\": \"bar\"}"
my-encoded-params config.binary "YmF6"

Table-GetCustomKeys: a table with a single partition key (key) and attribute (val)

key val
my-param foo

Table-GetMultipleCustomKeys: a table with a partition key (key) and a sort key (sort) and attribute (val)

key sort val
my-params config bar
my-params key baz

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

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label Jan 13, 2023
@dreamorosi dreamorosi self-assigned this Jan 13, 2023
@dreamorosi dreamorosi linked an issue Jan 13, 2023 that may be closed by this pull request
2 tasks
@dreamorosi dreamorosi added the tests PRs that add or change tests label Jan 17, 2023
@dreamorosi dreamorosi merged commit 897cda6 into main Jan 17, 2023
@dreamorosi dreamorosi deleted the 1039-maintenance-write-end-to-end-tests-for-the-utility branch January 17, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL PRs between 500-999 LOC, often PRs that grown with feedback tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: integration tests for DynamoDBProvider
1 participant