Skip to content

Commit 49b4aa1

Browse files
authored
fix(integ-tests): httpApiCall.expect with resolved URL (#29705)
### Issue # (if applicable) Closes #29700 I've also opened #29701 to catch similar issues at synth time in the future ### Reason for this change When running `httpApiCall('url').expect`, the `AssertionResults` output logical ID would be overridden with an invalid name, containing the URL slashes. This issue was not noticed earlier because, as far as I can tell, assertions were only made with `Token`/`Ref` URLs, e.g. `apigw.DomainName` ### Description of changes * Remove non-alphanumeric characters from the overridden `AssertionResults` output logical ID * I've also added a bit of documentation to `ExpectedResult`, I noticed it was slightly lacking while creating the integration test ### Description of how you validated changes I've added unit and integration tests. The integration tests include both tests with API Gateway, to cover unresolved URLs, and to https://httpbin.org/ to test this fix ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4eb02a4 commit 49b4aa1

12 files changed

+2483
-1
lines changed

packages/@aws-cdk/integ-tests-alpha/lib/assertions/common.ts

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export abstract class ExpectedResult {
5555
* ExpectedResult.exact({
5656
* stringParam: 'hello',
5757
* });
58+
*
59+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-exactpattern
5860
*/
5961
public static exact(expected: any): ExpectedResult {
6062
return {
@@ -74,11 +76,15 @@ export abstract class ExpectedResult {
7476
* stringParam: 'hello',
7577
* numberParam: 3,
7678
* booleanParam: true,
79+
* objectParam: { prop1: 'value', prop2: 'value' },
7780
* };
7881
* // pass
7982
* ExpectedResult.objectLike({
8083
* stringParam: 'hello',
84+
* objectParam: { prop1: 'value' },
8185
* });
86+
*
87+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-objectwbrlikepattern
8288
*/
8389
public static objectLike(expected: { [key: string]: any }): ExpectedResult {
8490
return {
@@ -108,6 +114,8 @@ export abstract class ExpectedResult {
108114
* stringParam: 'hello',
109115
* },
110116
* ]);
117+
*
118+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-arraywbrwithpattern
111119
*/
112120
public static arrayWith(expected: any[]): ExpectedResult {
113121
return {
@@ -126,6 +134,8 @@ export abstract class ExpectedResult {
126134
*
127135
* // pass
128136
* ExpectedResult.stringLikeRegexp('value');
137+
*
138+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Match.html#static-stringwbrlikewbrregexppattern
129139
*/
130140
public static stringLikeRegexp(expected: string): ExpectedResult {
131141
return {

packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class HttpApiCall extends ApiCallBase {
4747

4848
new CfnOutput(node, 'AssertionResults', {
4949
value: result,
50-
}).overrideLogicalId(`AssertionResults${id}`);
50+
}).overrideLogicalId(`AssertionResults${id.replace(/[\W_]+/g, '')}`);
5151
}
5252
}
5353
},

packages/@aws-cdk/integ-tests-alpha/test/assertions/deploy-assert.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ describe('DeployAssert', () => {
268268
}));
269269
});
270270

271+
test('expect creates a valid CfnOutput', () => {
272+
// GIVEN
273+
const app = new App();
274+
const deplossert = new DeployAssert(app);
275+
276+
// WHEN
277+
const query = deplossert.httpApiCall('https://example.com/test/123?param=value&param2#hash');
278+
query.expect(ExpectedResult.objectLike({ status: 200 }));
279+
280+
// THEN
281+
Template.fromStack(deplossert.scope).hasOutput(
282+
// Output name should only contain alphanumeric characters
283+
'AssertionResultsHttpApiCallexamplecomtest1237c0018be9f253e38cad30092c2fa2a91',
284+
{
285+
Value: {
286+
'Fn::GetAtt': ['HttpApiCallexamplecomtest1237c0018be9f253e38cad30092c2fa2a91', 'assertion'],
287+
},
288+
},
289+
);
290+
});
291+
271292
test('multiple calls can be configured', () => {
272293
// GIVEN
273294
const app = new App();

packages/@aws-cdk/integ-tests-alpha/test/assertions/providers/integ.http-api-call-assertions.js.snapshot/AssertionsTestDefaultTestDeployAssertDC0672BB.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)