Skip to content

Commit

Permalink
feat(integ-tests): enhancements to integ-tests (#20180)
Browse files Browse the repository at this point in the history
This PR contains various enhancements including

- `integ-tests`
    - removed dependency on other CDK libraries (other than core)
	- API ergonomics improvements
 		- renamed `queryAws` to `awsApiCall`
 		- added some additional methods
	- Now using `Match` from @aws-cdk/assertions for the assertions provider
	- `DeployAssert` now creates its own stack
		- This stack is written to a new IntegManifest property so that it can be treated differently
			(i.e. don't diff this stack)
	- Additional assertion types (OBJECT_LIKE)
	- Refactored assertion results
		- removed separate results handler in favor of just writing results to a stack output
	- utility for invoking lambda functions (separate from `awsApiCall`)
	- `IntegTest` now creates a test case by default.
	- Added `IntegTestCaseStack` class

- `integ-runner`
	- Updated to handle the results of assertions
		- When running with update workflow, the assertion stack is only deployed during the 
			"update" deployment
		- The stack outputs containing the assertion results are are written to a
			file that the runner can read.



I've also converted/added assertions to a couple of existing integration tests
- `aws-lambda/test/integ.bundling.ts`
- `aws-lambda-destinations/test/integ.destinations.ts`
- `aws-stepfunctions-tasks/test/eventbridge/integ.put-events.ts`

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
corymhall committed May 16, 2022
1 parent 861a2bb commit 3ff3fb7
Show file tree
Hide file tree
Showing 64 changed files with 5,275 additions and 577 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/assertions/lib/helpers-internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../match';
export * from '../matcher';
5 changes: 5 additions & 0 deletions packages/@aws-cdk/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"build+extract": "yarn build && yarn rosetta:extract",
"build+test+extract": "yarn build+test && yarn rosetta:extract"
},
"ubergen": {
"exports": {
"./lib/helpers-internal": "./lib/helpers-internal/index.js"
}
},
"jsii": {
"outdir": "dist",
"diagnostics": {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-lambda-destinations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/integ-tests": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
{
"Resources": {
"LambdaInvoked12df417a1b74909abb3ea643735a310": {
"Type": "Custom::DeployAssert@SdkCallLambdainvoke",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F",
"Arn"
]
},
"service": "Lambda",
"api": "invoke",
"parameters": {
"FunctionName": {
"Fn::ImportValue": "aws-cdk-lambda-destinations:ExportsOutputRefSnsSqsC4810B27404A5AFF"
},
"InvocationType": "Event",
"Payload": "{\"status\":\"OK\"}"
},
"flattenResponse": "false",
"salt": "1651691787842"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"LambdaInvoked12df417a1b74909abb3ea643735a310InvokeF590C289": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::ImportValue": "aws-cdk-lambda-destinations:ExportsOutputRefSnsSqsC4810B27404A5AFF"
},
"Principal": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73",
"Arn"
]
}
}
},
"AwsApiCallSQSreceiveMessage": {
"Type": "Custom::DeployAssert@SdkCallSQSreceiveMessage",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F",
"Arn"
]
},
"service": "SQS",
"api": "receiveMessage",
"parameters": {
"QueueUrl": {
"Fn::ImportValue": "aws-cdk-lambda-destinations:ExportsOutputRefQueue4A7E3555425E8BD3"
},
"WaitTimeSeconds": 20
},
"flattenResponse": "true",
"salt": "1651691787842"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"AwsApiCallSQSreceiveMessageAssertEqualsSQSreceiveMessage56120636": {
"Type": "Custom::DeployAssert@AssertEquals",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F",
"Arn"
]
},
"actual": {
"Fn::GetAtt": [
"AwsApiCallSQSreceiveMessage",
"apiCallResponse.Messages.0.Body"
]
},
"expected": "{\"$ObjectLike\":{\"requestContext\":{\"condition\":\"Success\"},\"requestPayload\":{\"status\":\"OK\"},\"responseContext\":{\"statusCode\":200},\"responsePayload\":\"success\"}}",
"salt": "1651691787843"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
],
"Policies": [
{
"PolicyName": "Inline",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:Invoke"
],
"Effect": "Allow",
"Resource": [
"*"
]
},
{
"Action": [
"lambda:InvokeFunction"
],
"Effect": "Allow",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":lambda:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":function:",
{
"Fn::ImportValue": "aws-cdk-lambda-destinations:ExportsOutputRefSnsSqsC4810B27404A5AFF"
}
]
]
}
]
},
{
"Action": [
"sqs:ReceiveMessage"
],
"Effect": "Allow",
"Resource": [
"*"
]
}
]
}
}
]
}
},
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Runtime": "nodejs14.x",
"Code": {
"S3Bucket": {
"Ref": "AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bS3BucketF7210344"
},
"S3Key": {
"Fn::Join": [
"",
[
{
"Fn::Select": [
0,
{
"Fn::Split": [
"||",
{
"Ref": "AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bS3VersionKey1E71961C"
}
]
}
]
},
{
"Fn::Select": [
1,
{
"Fn::Split": [
"||",
{
"Ref": "AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bS3VersionKey1E71961C"
}
]
}
]
}
]
]
}
},
"Timeout": 120,
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73",
"Arn"
]
}
}
}
},
"Outputs": {
"AssertionResultsAssertEqualsSQSreceiveMessage": {
"Value": {
"Fn::GetAtt": [
"AwsApiCallSQSreceiveMessageAssertEqualsSQSreceiveMessage56120636",
"data"
]
}
}
},
"Parameters": {
"AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bS3BucketF7210344": {
"Type": "String",
"Description": "S3 bucket for asset \"1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38b\""
},
"AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bS3VersionKey1E71961C": {
"Type": "String",
"Description": "S3 key for asset version \"1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38b\""
},
"AssetParameters1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38bArtifactHash4F8362F2": {
"Type": "String",
"Description": "Artifact hash for asset \"1bc7cf3a01a7153f942391263b3bac937812996cc28f9abaf83ffebbbe03e38b\""
}
}
}
Loading

0 comments on commit 3ff3fb7

Please sign in to comment.