Skip to content

Commit 3c8b82e

Browse files
lvthillovishaalmehrishi
authored andcommitted
feat: add extra tests for backward compatibility + add assertion
1 parent 36e5c5f commit 3c8b82e

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-synthetics/test/integ.canary-resources-to-replicate-tags.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'node:path';
22
import { App, Duration, Size, Stack, StackProps, Tags } from 'aws-cdk-lib/core';
3-
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
3+
import { IntegTest, ExpectedResult } from '@aws-cdk/integ-tests-alpha';
44
import { Construct } from 'constructs';
55
import * as synthetics from 'aws-cdk-lib/aws-synthetics';
66

@@ -31,6 +31,25 @@ class TestStack extends Stack {
3131
const app = new App();
3232
const testStack = new TestStack(app, 'SyntheticsCanaryResourcesToReplicateTagsStack');
3333

34-
new IntegTest(app, 'SyntheticsCanaryResourcesToReplicateTags', {
34+
const integ = new IntegTest(app, 'SyntheticsCanaryResourcesToReplicateTags', {
3535
testCases: [testStack],
3636
});
37+
38+
const getCanary = integ.assertions.awsApiCall('Synthetics', 'getCanary', {
39+
Name: 'tag-replication',
40+
});
41+
42+
const getLambdaTags = integ.assertions.awsApiCall('Lambda', 'listTags', {
43+
Resource: getCanary.getAttString('Canary.EngineArn'),
44+
});
45+
46+
getLambdaTags.expect(ExpectedResult.objectLike({
47+
Tags: {
48+
Environment: 'test',
49+
Owner: 'cdk-team',
50+
Project: 'synthetics-tag-replication',
51+
},
52+
})).waitForAssertions({
53+
totalTimeout: Duration.minutes(5),
54+
interval: Duration.seconds(30),
55+
});

packages/aws-cdk-lib/aws-synthetics/test/canary.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,3 +1213,50 @@ test('can configure resourcesToReplicateTags', () => {
12131213
ResourcesToReplicateTags: ['lambda-function'],
12141214
});
12151215
});
1216+
1217+
test('resourcesToReplicateTags is not included when not specified', () => {
1218+
// GIVEN
1219+
const stack = new Stack();
1220+
1221+
// WHEN
1222+
new synthetics.Canary(stack, 'Canary', {
1223+
canaryName: 'mycanary',
1224+
test: synthetics.Test.custom({
1225+
handler: 'index.handler',
1226+
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
1227+
}),
1228+
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
1229+
});
1230+
1231+
// THEN
1232+
const template = Template.fromStack(stack);
1233+
template.hasResourceProperties('AWS::Synthetics::Canary', {
1234+
Name: 'mycanary',
1235+
});
1236+
1237+
const canaryResource = template.findResources('AWS::Synthetics::Canary');
1238+
const canaryProps = canaryResource[Object.keys(canaryResource)[0]].Properties;
1239+
expect(canaryProps.ResourcesToReplicateTags).toBeUndefined();
1240+
});
1241+
1242+
test('resourcesToReplicateTags can be empty array', () => {
1243+
// GIVEN
1244+
const stack = new Stack();
1245+
1246+
// WHEN
1247+
new synthetics.Canary(stack, 'Canary', {
1248+
canaryName: 'mycanary',
1249+
test: synthetics.Test.custom({
1250+
handler: 'index.handler',
1251+
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
1252+
}),
1253+
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0,
1254+
resourcesToReplicateTags: [],
1255+
});
1256+
1257+
// THEN
1258+
Template.fromStack(stack).hasResourceProperties('AWS::Synthetics::Canary', {
1259+
Name: 'mycanary',
1260+
ResourcesToReplicateTags: [],
1261+
});
1262+
});

0 commit comments

Comments
 (0)