1
1
import * as path from 'path' ;
2
- import '@aws-cdk/assert-internal/jest' ;
3
- import { ABSENT , ResourcePart } from '@aws-cdk/assert-internal' ;
2
+ import { Match , Template } from '@aws-cdk/assertions' ;
4
3
import * as iam from '@aws-cdk/aws-iam' ;
5
4
import * as cdk from '@aws-cdk/core' ;
6
5
import * as cxapi from '@aws-cdk/cx-api' ;
@@ -20,7 +19,7 @@ describe('log retention', () => {
20
19
} ) ;
21
20
22
21
// THEN
23
- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
22
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
24
23
'PolicyDocument' : {
25
24
'Statement' : [
26
25
{
@@ -42,12 +41,12 @@ describe('log retention', () => {
42
41
] ,
43
42
} ) ;
44
43
45
- expect ( stack ) . toHaveResource ( 'AWS::Lambda::Function' , {
44
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Lambda::Function' , {
46
45
Handler : 'index.handler' ,
47
46
Runtime : 'nodejs14.x' ,
48
47
} ) ;
49
48
50
- expect ( stack ) . toHaveResource ( 'Custom::LogRetention' , {
49
+ Template . fromStack ( stack ) . hasResourceProperties ( 'Custom::LogRetention' , {
51
50
'ServiceToken' : {
52
51
'Fn::GetAtt' : [
53
52
'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A' ,
@@ -57,8 +56,6 @@ describe('log retention', () => {
57
56
'LogGroupName' : 'group' ,
58
57
'RetentionInDays' : 30 ,
59
58
} ) ;
60
-
61
-
62
59
} ) ;
63
60
64
61
test ( 'with imported role' , ( ) => {
@@ -74,7 +71,7 @@ describe('log retention', () => {
74
71
} ) ;
75
72
76
73
// THEN
77
- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
74
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
78
75
'PolicyDocument' : {
79
76
'Statement' : [
80
77
{
@@ -94,9 +91,7 @@ describe('log retention', () => {
94
91
] ,
95
92
} ) ;
96
93
97
- expect ( stack ) . toCountResources ( 'AWS::IAM::Role' , 0 ) ;
98
-
99
-
94
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::IAM::Role' , 0 ) ;
100
95
} ) ;
101
96
102
97
test ( 'with RetentionPeriod set to Infinity' , ( ) => {
@@ -107,11 +102,9 @@ describe('log retention', () => {
107
102
retention : RetentionDays . INFINITE ,
108
103
} ) ;
109
104
110
- expect ( stack ) . toHaveResource ( 'Custom::LogRetention' , {
111
- RetentionInDays : ABSENT ,
105
+ Template . fromStack ( stack ) . hasResourceProperties ( 'Custom::LogRetention' , {
106
+ RetentionInDays : Match . absent ( ) ,
112
107
} ) ;
113
-
114
-
115
108
} ) ;
116
109
117
110
test ( 'with LogGroupRegion specified' , ( ) => {
@@ -122,11 +115,9 @@ describe('log retention', () => {
122
115
retention : RetentionDays . INFINITE ,
123
116
} ) ;
124
117
125
- expect ( stack ) . toHaveResource ( 'Custom::LogRetention' , {
118
+ Template . fromStack ( stack ) . hasResourceProperties ( 'Custom::LogRetention' , {
126
119
LogGroupRegion : 'us-east-1' ,
127
120
} ) ;
128
-
129
-
130
121
} ) ;
131
122
132
123
test ( 'log group ARN is well formed and conforms' , ( ) => {
@@ -140,7 +131,6 @@ describe('log retention', () => {
140
131
expect ( logGroupArn . indexOf ( 'logs' ) ) . toBeGreaterThan ( - 1 ) ;
141
132
expect ( logGroupArn . indexOf ( 'log-group' ) ) . toBeGreaterThan ( - 1 ) ;
142
133
expect ( logGroupArn . endsWith ( ':*' ) ) . toEqual ( true ) ;
143
-
144
134
} ) ;
145
135
146
136
test ( 'log group ARN is well formed and conforms when region is specified' , ( ) => {
@@ -156,7 +146,6 @@ describe('log retention', () => {
156
146
expect ( logGroupArn . indexOf ( 'logs' ) ) . toBeGreaterThan ( - 1 ) ;
157
147
expect ( logGroupArn . indexOf ( 'log-group' ) ) . toBeGreaterThan ( - 1 ) ;
158
148
expect ( logGroupArn . endsWith ( ':*' ) ) . toEqual ( true ) ;
159
-
160
149
} ) ;
161
150
162
151
test ( 'retention Lambda CfnResource receives propagated tags' , ( ) => {
@@ -167,15 +156,14 @@ describe('log retention', () => {
167
156
retention : RetentionDays . ONE_MONTH ,
168
157
} ) ;
169
158
170
- expect ( stack ) . toHaveResourceLike ( 'AWS::Lambda::Function' , {
159
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Lambda::Function' , {
171
160
Tags : [
172
161
{
173
162
Key : 'test-key' ,
174
163
Value : 'test-value' ,
175
164
} ,
176
165
] ,
177
166
} ) ;
178
-
179
167
} ) ;
180
168
181
169
test ( 'asset metadata added to log retention construct lambda function' , ( ) => {
@@ -193,13 +181,12 @@ describe('log retention', () => {
193
181
} ) ;
194
182
195
183
// Then
196
- expect ( stack ) . toHaveResource ( 'AWS::Lambda::Function' , {
184
+ Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
197
185
Metadata : {
198
186
'aws:asset:path' : assetLocation ,
199
187
'aws:asset:is-bundled' : false ,
200
188
'aws:asset:property' : 'Code' ,
201
189
} ,
202
- } , ResourcePart . CompleteDefinition ) ;
203
-
190
+ } ) ;
204
191
} ) ;
205
192
} ) ;
0 commit comments