Skip to content

Commit c6ed80e

Browse files
committed
chore: refactor integ test
1 parent 7eef0d6 commit c6ed80e

7 files changed

+78
-59
lines changed

test/integ.resources.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ const integ = new IntegTest(app, 'OpenSearchRestResourcesIntegTest', {
1111
diffAssets: true,
1212
});
1313

14-
const assertion = integ.assertions.awsApiCall('Lambda', 'Invoke', {
15-
FunctionName: stack.testHandler.functionName,
14+
const assertion = integ.assertions.invokeFunction({
15+
functionName: stack.testHandler.functionName,
1616
});
1717
// https://docs.aws.amazon.com/lambda/latest/api/API_Invoke.html#API_Invoke_ResponseElements
1818
assertion.expect(ExpectedResult.objectLike({ StatusCode: 200 }));
19-
assertion.provider.addToRolePolicy({
20-
Effect: 'Allow',
21-
Action: ['lambda:InvokeFunction'],
22-
Resource: [stack.testHandler.functionArn],
23-
});

test/integ.resources.ts.snapshot/OpenSearchRestResourcesIntegTestDefaultTestDeployAssertAA436F18.assets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
}
1515
}
1616
},
17-
"ebcf36631f84f9f3b16bef2edfdef56d5076309dcc18587a1d5a60cf73f7952c": {
17+
"ade37aa7b85446d0c19cd1fcb277da5d1da671c72b6625ff4b5a468e5c4a3e01": {
1818
"source": {
1919
"path": "OpenSearchRestResourcesIntegTestDefaultTestDeployAssertAA436F18.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "ebcf36631f84f9f3b16bef2edfdef56d5076309dcc18587a1d5a60cf73f7952c.json",
25+
"objectKey": "ade37aa7b85446d0c19cd1fcb277da5d1da671c72b6625ff4b5a468e5c4a3e01.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

test/integ.resources.ts.snapshot/OpenSearchRestResourcesIntegTestDefaultTestDeployAssertAA436F18.template.json

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Resources": {
3-
"AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680": {
4-
"Type": "Custom::DeployAssert@SdkCallLambdaInvoke",
3+
"LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1": {
4+
"Type": "Custom::DeployAssert@SdkCallLambdainvoke",
55
"Properties": {
66
"ServiceToken": {
77
"Fn::GetAtt": [
@@ -10,7 +10,7 @@
1010
]
1111
},
1212
"service": "Lambda",
13-
"api": "Invoke",
13+
"api": "invoke",
1414
"expected": "{\"$ObjectLike\":{\"StatusCode\":200}}",
1515
"parameters": {
1616
"FunctionName": {
@@ -27,11 +27,26 @@
2727
}
2828
},
2929
"flattenResponse": "false",
30-
"salt": "1719035849476"
30+
"salt": "1719080822231"
3131
},
3232
"UpdateReplacePolicy": "Delete",
3333
"DeletionPolicy": "Delete"
3434
},
35+
"LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1InvokeC5D4A4D4": {
36+
"Type": "AWS::Lambda::Permission",
37+
"Properties": {
38+
"Action": "lambda:InvokeFunction",
39+
"FunctionName": {
40+
"Fn::ImportValue": "OpenSearchRestResourcesStack:ExportsOutputRefTestHandler3EEC63921B5ED14E"
41+
},
42+
"Principal": {
43+
"Fn::GetAtt": [
44+
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73",
45+
"Arn"
46+
]
47+
}
48+
}
49+
},
3550
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73": {
3651
"Type": "AWS::IAM::Role",
3752
"Properties": {
@@ -68,13 +83,33 @@
6883
]
6984
},
7085
{
71-
"Effect": "Allow",
7286
"Action": [
7387
"lambda:InvokeFunction"
7488
],
89+
"Effect": "Allow",
7590
"Resource": [
7691
{
77-
"Fn::ImportValue": "OpenSearchRestResourcesStack:ExportsOutputFnGetAttTestHandler3EEC6392Arn42B9A49B"
92+
"Fn::Join": [
93+
"",
94+
[
95+
"arn:",
96+
{
97+
"Ref": "AWS::Partition"
98+
},
99+
":lambda:",
100+
{
101+
"Ref": "AWS::Region"
102+
},
103+
":",
104+
{
105+
"Ref": "AWS::AccountId"
106+
},
107+
":function:",
108+
{
109+
"Fn::ImportValue": "OpenSearchRestResourcesStack:ExportsOutputRefTestHandler3EEC63921B5ED14E"
110+
}
111+
]
112+
]
78113
}
79114
]
80115
}
@@ -106,10 +141,10 @@
106141
}
107142
},
108143
"Outputs": {
109-
"AssertionResultsAwsApiCallLambdaInvokee049850589ce011a8daad895dd924680": {
144+
"AssertionResultsLambdaInvokea77f64222a12d5eb00fd5fdb480e60b1": {
110145
"Value": {
111146
"Fn::GetAtt": [
112-
"AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680",
147+
"LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1",
113148
"assertion"
114149
]
115150
}

test/integ.resources.ts.snapshot/OpenSearchRestResourcesStack.assets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
}
4141
}
4242
},
43-
"d6154d8a81f32ef58ed8ac4ed54e9456c874408d79687de8f44abfb06fe8d6fc": {
43+
"969b787468ef89cee264ab83fa4a310c03fb29a03361f48a326732bc339a6c01": {
4444
"source": {
4545
"path": "OpenSearchRestResourcesStack.template.json",
4646
"packaging": "file"
4747
},
4848
"destinations": {
4949
"current_account-current_region": {
5050
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
51-
"objectKey": "d6154d8a81f32ef58ed8ac4ed54e9456c874408d79687de8f44abfb06fe8d6fc.json",
51+
"objectKey": "969b787468ef89cee264ab83fa4a310c03fb29a03361f48a326732bc339a6c01.json",
5252
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
5353
}
5454
}

test/integ.resources.ts.snapshot/OpenSearchRestResourcesStack.template.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,17 +1335,6 @@
13351335
"Export": {
13361336
"Name": "OpenSearchRestResourcesStack:ExportsOutputRefTestHandler3EEC63921B5ED14E"
13371337
}
1338-
},
1339-
"ExportsOutputFnGetAttTestHandler3EEC6392Arn42B9A49B": {
1340-
"Value": {
1341-
"Fn::GetAtt": [
1342-
"TestHandler3EEC6392",
1343-
"Arn"
1344-
]
1345-
},
1346-
"Export": {
1347-
"Name": "OpenSearchRestResourcesStack:ExportsOutputFnGetAttTestHandler3EEC6392Arn42B9A49B"
1348-
}
13491338
}
13501339
},
13511340
"Parameters": {

test/integ.resources.ts.snapshot/manifest.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"validateOnSynth": false,
1919
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2020
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
21-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d6154d8a81f32ef58ed8ac4ed54e9456c874408d79687de8f44abfb06fe8d6fc.json",
21+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/969b787468ef89cee264ab83fa4a310c03fb29a03361f48a326732bc339a6c01.json",
2222
"requiresBootstrapStackVersion": 6,
2323
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2424
"additionalDependencies": [
@@ -340,12 +340,6 @@
340340
"data": "ExportsOutputRefTestHandler3EEC63921B5ED14E"
341341
}
342342
],
343-
"/OpenSearchRestResourcesStack/Exports/Output{\"Fn::GetAtt\":[\"TestHandler3EEC6392\",\"Arn\"]}": [
344-
{
345-
"type": "aws:cdk:logicalId",
346-
"data": "ExportsOutputFnGetAttTestHandler3EEC6392Arn42B9A49B"
347-
}
348-
],
349343
"/OpenSearchRestResourcesStack/BootstrapVersion": [
350344
{
351345
"type": "aws:cdk:logicalId",
@@ -378,7 +372,7 @@
378372
"validateOnSynth": false,
379373
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
380374
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
381-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ebcf36631f84f9f3b16bef2edfdef56d5076309dcc18587a1d5a60cf73f7952c.json",
375+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ade37aa7b85446d0c19cd1fcb277da5d1da671c72b6625ff4b5a468e5c4a3e01.json",
382376
"requiresBootstrapStackVersion": 6,
383377
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
384378
"additionalDependencies": [
@@ -395,16 +389,22 @@
395389
"OpenSearchRestResourcesIntegTestDefaultTestDeployAssertAA436F18.assets"
396390
],
397391
"metadata": {
398-
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/Default/Default": [
392+
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/Default/Default": [
393+
{
394+
"type": "aws:cdk:logicalId",
395+
"data": "LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1"
396+
}
397+
],
398+
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/Invoke": [
399399
{
400400
"type": "aws:cdk:logicalId",
401-
"data": "AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680"
401+
"data": "LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1InvokeC5D4A4D4"
402402
}
403403
],
404-
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/AssertionResults": [
404+
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/AssertionResults": [
405405
{
406406
"type": "aws:cdk:logicalId",
407-
"data": "AssertionResultsAwsApiCallLambdaInvokee049850589ce011a8daad895dd924680"
407+
"data": "AssertionResultsLambdaInvokea77f64222a12d5eb00fd5fdb480e60b1"
408408
}
409409
],
410410
"/OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/SingletonFunction1488541a7b23466481b69b4408076b81/Role": [

test/integ.resources.ts.snapshot/tree.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,14 +1815,6 @@
18151815
"fqn": "aws-cdk-lib.CfnOutput",
18161816
"version": "2.133.0"
18171817
}
1818-
},
1819-
"Output{\"Fn::GetAtt\":[\"TestHandler3EEC6392\",\"Arn\"]}": {
1820-
"id": "Output{\"Fn::GetAtt\":[\"TestHandler3EEC6392\",\"Arn\"]}",
1821-
"path": "OpenSearchRestResourcesStack/Exports/Output{\"Fn::GetAtt\":[\"TestHandler3EEC6392\",\"Arn\"]}",
1822-
"constructInfo": {
1823-
"fqn": "aws-cdk-lib.CfnOutput",
1824-
"version": "2.133.0"
1825-
}
18261818
}
18271819
},
18281820
"constructInfo": {
@@ -1872,17 +1864,17 @@
18721864
"id": "DeployAssert",
18731865
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert",
18741866
"children": {
1875-
"AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680": {
1876-
"id": "AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680",
1877-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680",
1867+
"LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1": {
1868+
"id": "LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1",
1869+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1",
18781870
"children": {
18791871
"SdkProvider": {
18801872
"id": "SdkProvider",
1881-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/SdkProvider",
1873+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/SdkProvider",
18821874
"children": {
18831875
"AssertionsProvider": {
18841876
"id": "AssertionsProvider",
1885-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/SdkProvider/AssertionsProvider",
1877+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/SdkProvider/AssertionsProvider",
18861878
"constructInfo": {
18871879
"fqn": "constructs.Construct",
18881880
"version": "10.3.0"
@@ -1896,11 +1888,11 @@
18961888
},
18971889
"Default": {
18981890
"id": "Default",
1899-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/Default",
1891+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/Default",
19001892
"children": {
19011893
"Default": {
19021894
"id": "Default",
1903-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/Default/Default",
1895+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/Default/Default",
19041896
"constructInfo": {
19051897
"fqn": "aws-cdk-lib.CfnResource",
19061898
"version": "2.133.0"
@@ -1912,17 +1904,25 @@
19121904
"version": "2.133.0"
19131905
}
19141906
},
1907+
"Invoke": {
1908+
"id": "Invoke",
1909+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/Invoke",
1910+
"constructInfo": {
1911+
"fqn": "aws-cdk-lib.CfnResource",
1912+
"version": "2.133.0"
1913+
}
1914+
},
19151915
"AssertionResults": {
19161916
"id": "AssertionResults",
1917-
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/AwsApiCallLambdaInvokee049850589ce011a8daad895dd924680/AssertionResults",
1917+
"path": "OpenSearchRestResourcesIntegTest/DefaultTest/DeployAssert/LambdaInvokea77f64222a12d5eb00fd5fdb480e60b1/AssertionResults",
19181918
"constructInfo": {
19191919
"fqn": "aws-cdk-lib.CfnOutput",
19201920
"version": "2.133.0"
19211921
}
19221922
}
19231923
},
19241924
"constructInfo": {
1925-
"fqn": "@aws-cdk/integ-tests-alpha.AwsApiCall",
1925+
"fqn": "@aws-cdk/integ-tests-alpha.LambdaInvokeFunction",
19261926
"version": "2.133.0-alpha.0"
19271927
}
19281928
},

0 commit comments

Comments
 (0)