Skip to main content

CDK Integration Testing Constructs

Project description

integ-tests

---

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


Usage

Suppose you have a simple stack, that only encapsulates a Lambda function with a certain handler:

class StackUnderTest(Stack):
    def __init__(self, scope, id, *, functionProps=None, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):
        super().__init__(scope, id, functionProps=functionProps, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)

        lambda_.Function(self, "Handler",
            runtime=lambda_.Runtime.NODEJS_12_X,
            handler="index.handler",
            code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler")),
            (SpreadAssignment ...props.functionProps
              function_props)
        )

You may want to test this stack under different conditions. For example, we want this stack to be deployed correctly, regardless of the architecture we choose for the Lambda function. In particular, it should work for both ARM_64 and X86_64. So you can create an IntegTestCase that exercises both scenarios:

class StackUnderTest(Stack):
    def __init__(self, scope, id, *, architecture=None, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):
        super().__init__(scope, id, architecture=architecture, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)

        lambda_.Function(self, "Handler",
            runtime=lambda_.Runtime.NODEJS_12_X,
            handler="index.handler",
            code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler")),
            architecture=architecture
        )

# Beginning of the test suite
app = App()

stack = Stack(app, "stack")
IntegTestCase(stack, "DifferentArchitectures",
    stacks=[
        StackUnderTest(app, "Stack1",
            architecture=lambda_.Architecture.ARM_64
        ),
        StackUnderTest(app, "Stack2",
            architecture=lambda_.Architecture.X86_64
        )
    ]
)

This is all the instruction you need for the integration test runner to know which stacks to synthesize, deploy and destroy. But you may also need to customize the behavior of the runner by changing its parameters. For example:

app = App()

stack_under_test = Stack(app, "StackUnderTest")

stack = Stack(app, "stack")

IntegTestCase(stack, "CustomizedDeploymentWorkflow",
    stacks=[stack_under_test],
    diff_assets=True,
    stack_update_workflow=True,
    cdk_command_options=CdkCommands(
        deploy=DeployCommand(
            args=DeployOptions(
                require_approval=RequireApproval.NEVER,
                json=True
            )
        ),
        destroy=DestroyCommand(
            args=DestroyOptions(
                force=True
            )
        )
    )
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.integ-tests-alpha-2.21.1a0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file aws-cdk.integ-tests-alpha-2.21.1a0.tar.gz.

File metadata

  • Download URL: aws-cdk.integ-tests-alpha-2.21.1a0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.5

File hashes

Hashes for aws-cdk.integ-tests-alpha-2.21.1a0.tar.gz
Algorithm Hash digest
SHA256 ae544317e174e88761ad3e26a055fb242259c40b831a6a4bae8d7a3933af8a91
MD5 bbf95e50829cdab4e1394d01ae8a71c5
BLAKE2b-256 c6b5cd62e3fc5586bd7ae4411b3d9dcc18d6c2e0c9bcad314674ef8cd534c464

See more details on using hashes here.

File details

Details for the file aws_cdk.integ_tests_alpha-2.21.1a0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.integ_tests_alpha-2.21.1a0-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.5

File hashes

Hashes for aws_cdk.integ_tests_alpha-2.21.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f3a11d2f4c6c62ba021ebdbe335f68dab395fd1b5fabc187ba0ac516c48adaa
MD5 fcc134d5175142916466441d704653e1
BLAKE2b-256 baa474ba70cb14daf106b4abe09ed8bb60255856f8b9981d81f4e6aa063b636a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page