CDK Integration Testing Constructs
Project description
integ-tests
---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, *, 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
)
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")
different_archs_case = IntegTestCase(stack, "DifferentArchitectures",
stacks=[
StackUnderTest(app, "Stack1",
architecture=lambda_.Architecture.ARM_64
),
StackUnderTest(app, "Stack2",
architecture=lambda_.Architecture.X86_64
)
]
)
# There must be exactly one instance of TestCase per file
IntegTest(app, "integ-test",
# Register as many test cases as you want here
test_cases=[different_archs_case]
)
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")
test_case = 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
)
)
)
)
IntegTest(app, "integ-test",
test_cases=[test_case]
)
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
Built Distribution
Hashes for aws-cdk.integ-tests-1.156.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25edda00e9ef45d5ad517402690cac369d5e6688ba599ca69d49efed370739a4 |
|
MD5 | 802901c40f59efb8093e42a07759d17c |
|
BLAKE2b-256 | d2fe41021a8ad7dcccb6646afdbbe6a995d73aedfa07dd8f82da65019125eda2 |
Hashes for aws_cdk.integ_tests-1.156.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11b6022a83edd6feff1a6af20becc707d9c5edae1fbfda56c7aed2f1457febc7 |
|
MD5 | 3523a7e3fa0e971404d109fa333f4d1c |
|
BLAKE2b-256 | f569cae396aded360221e30713afe2c00ed800caccc52c8b6f5bfc178a57f702 |