Skip to content

Commit e10391b

Browse files
authored
chore: migrate comcalvi's modules to assertions (#18202)
Migrates all of comcalvi's modules to assertions. PR is complete when these modules are migrated: - [x] autoscaling - [x] application autoscaling - [x] autoscaling common - [x] autoscaling hooktargets - [x] cloudtrail - [x] cloudformation-include - [x] logs ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent cb86e30 commit e10391b

File tree

11 files changed

+226
-356
lines changed

11 files changed

+226
-356
lines changed

packages/@aws-cdk/aws-autoscaling-hooktargets/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"license": "Apache-2.0",
6666
"devDependencies": {
67-
"@aws-cdk/assert-internal": "0.0.0",
67+
"@aws-cdk/assertions": "0.0.0",
6868
"@aws-cdk/aws-ec2": "0.0.0",
6969
"@aws-cdk/cdk-build-tools": "0.0.0",
7070
"@aws-cdk/cdk-integ-tools": "0.0.0",

packages/@aws-cdk/aws-autoscaling-hooktargets/test/hooks.test.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import '@aws-cdk/assert-internal/jest';
2-
import { arrayWith } from '@aws-cdk/assert-internal';
1+
import { Match, Template } from '@aws-cdk/assertions';
32
import * as autoscaling from '@aws-cdk/aws-autoscaling';
43
import * as ec2 from '@aws-cdk/aws-ec2';
54
import * as iam from '@aws-cdk/aws-iam';
@@ -27,7 +26,7 @@ describe('given an AutoScalingGroup and no role', () => {
2726
});
2827

2928
afterEach(() => {
30-
expect(stack).toHaveResource('AWS::IAM::Role', {
29+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
3130
AssumeRolePolicyDocument: {
3231
Version: '2012-10-17',
3332
Statement: [
@@ -54,8 +53,8 @@ describe('given an AutoScalingGroup and no role', () => {
5453
});
5554

5655
// THEN
57-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { 'Fn::GetAtt': ['Queue4A7E3555', 'Arn'] } });
58-
expect(stack).toHaveResource('AWS::IAM::Policy', {
56+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { 'Fn::GetAtt': ['Queue4A7E3555', 'Arn'] } });
57+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
5958
PolicyDocument: {
6059
Statement: [
6160
{
@@ -95,8 +94,8 @@ describe('given an AutoScalingGroup and no role', () => {
9594
});
9695

9796
// THEN
98-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'TopicBFC7AF6E' } });
99-
expect(stack).toHaveResource('AWS::IAM::Policy', {
97+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'TopicBFC7AF6E' } });
98+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
10099
PolicyDocument: {
101100
Statement: [
102101
{
@@ -133,13 +132,13 @@ describe('given an AutoScalingGroup and no role', () => {
133132
});
134133

135134
// THEN
136-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' } });
137-
expect(stack).toHaveResource('AWS::SNS::Subscription', {
135+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' } });
136+
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Subscription', {
138137
Protocol: 'lambda',
139138
TopicArn: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' },
140139
Endpoint: { 'Fn::GetAtt': ['Fn9270CBC0', 'Arn'] },
141140
});
142-
expect(stack).toHaveResource('AWS::IAM::Policy', {
141+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
143142
PolicyDocument: {
144143
Statement: [
145144
{
@@ -177,17 +176,17 @@ describe('given an AutoScalingGroup and no role', () => {
177176
});
178177

179178
// THEN
180-
expect(stack).toHaveResourceLike('AWS::SNS::Topic', {
179+
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', {
181180
KmsMasterKeyId: {
182181
'Fn::GetAtt': [
183182
'keyFEDD6EC0',
184183
'Arn',
185184
],
186185
},
187186
});
188-
expect(stack).toHaveResourceLike('AWS::IAM::Policy', {
187+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
189188
PolicyDocument: {
190-
Statement: arrayWith(
189+
Statement: Match.arrayWith([
191190
{
192191
Effect: 'Allow',
193192
Action: [
@@ -201,7 +200,7 @@ describe('given an AutoScalingGroup and no role', () => {
201200
],
202201
},
203202
},
204-
),
203+
]),
205204
},
206205
});
207206
});
@@ -223,7 +222,7 @@ describe('given an AutoScalingGroup and a role', () => {
223222
});
224223

225224
afterEach(() => {
226-
expect(stack).toHaveResource('AWS::IAM::Role', {
225+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
227226
AssumeRolePolicyDocument: {
228227
Version: '2012-10-17',
229228
Statement: [
@@ -253,7 +252,7 @@ describe('given an AutoScalingGroup and a role', () => {
253252
});
254253

255254
// THEN
256-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { 'Fn::GetAtt': ['Queue4A7E3555', 'Arn'] } });
255+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { 'Fn::GetAtt': ['Queue4A7E3555', 'Arn'] } });
257256
});
258257

259258
test('can use topic as hook target with a role', () => {
@@ -271,8 +270,8 @@ describe('given an AutoScalingGroup and a role', () => {
271270
});
272271

273272
// THEN
274-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'TopicBFC7AF6E' } });
275-
expect(stack).toHaveResource('AWS::IAM::Policy', {
273+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'TopicBFC7AF6E' } });
274+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
276275
PolicyDocument: {
277276
Statement: [
278277
{
@@ -313,13 +312,13 @@ describe('given an AutoScalingGroup and a role', () => {
313312
});
314313

315314
// THEN
316-
expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' } });
317-
expect(stack).toHaveResource('AWS::SNS::Subscription', {
315+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LifecycleHook', { NotificationTargetARN: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' } });
316+
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Subscription', {
318317
Protocol: 'lambda',
319318
TopicArn: { Ref: 'ASGLifecycleHookTransTopic9B0D4842' },
320319
Endpoint: { 'Fn::GetAtt': ['Fn9270CBC0', 'Arn'] },
321320
});
322-
expect(stack).toHaveResource('AWS::IAM::Policy', {
321+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
323322
PolicyDocument: {
324323
Statement: [
325324
{

packages/@aws-cdk/aws-autoscaling/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
},
8080
"license": "Apache-2.0",
8181
"devDependencies": {
82-
"@aws-cdk/assert-internal": "0.0.0",
82+
"@aws-cdk/assertions": "0.0.0",
8383
"@aws-cdk/cdk-build-tools": "0.0.0",
8484
"@aws-cdk/cdk-integ-tools": "0.0.0",
8585
"@aws-cdk/cfn2ts": "0.0.0",

packages/@aws-cdk/aws-autoscaling/test/aspects/require-imdsv2-aspect.test.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
expect as expectCDK,
3-
haveResourceLike,
4-
} from '@aws-cdk/assert-internal';
5-
import '@aws-cdk/assert-internal/jest';
1+
import { Match, Template } from '@aws-cdk/assertions';
62
import * as ec2 from '@aws-cdk/aws-ec2';
73
import * as cdk from '@aws-cdk/core';
84
import {
@@ -37,11 +33,12 @@ describe('AutoScalingGroupRequireImdsv2Aspect', () => {
3733
cdk.Aspects.of(stack).add(aspect);
3834

3935
// THEN
40-
expectCDK(stack).notTo(haveResourceLike('AWS::AutoScaling::LaunchConfiguration', {
36+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', Match.not({
4137
MetadataOptions: {
4238
HttpTokens: 'required',
4339
},
4440
}));
41+
4542
expect(asg.node.metadataEntry).toContainEqual({
4643
data: expect.stringContaining('CfnLaunchConfiguration.MetadataOptions field is a CDK token.'),
4744
type: 'aws:cdk:warning',
@@ -62,11 +59,11 @@ describe('AutoScalingGroupRequireImdsv2Aspect', () => {
6259
cdk.Aspects.of(stack).add(aspect);
6360

6461
// THEN
65-
expectCDK(stack).to(haveResourceLike('AWS::AutoScaling::LaunchConfiguration', {
62+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', {
6663
MetadataOptions: {
6764
HttpTokens: 'required',
6865
},
69-
}));
66+
});
7067
});
7168
});
7269

0 commit comments

Comments
 (0)