1
- import { ResourcePart , SynthUtils } from '@aws-cdk/assert' ;
1
+ import { ABSENT , ResourcePart , SynthUtils } from '@aws-cdk/assert' ;
2
2
import '@aws-cdk/assert/jest' ;
3
3
import * as appscaling from '@aws-cdk/aws-applicationautoscaling' ;
4
4
import * as iam from '@aws-cdk/aws-iam' ;
5
5
import * as kms from '@aws-cdk/aws-kms' ;
6
- import { App , CfnDeletionPolicy , ConstructNode , Duration , RemovalPolicy , Stack , Tag } from '@aws-cdk/core' ;
6
+ import { App , CfnDeletionPolicy , ConstructNode , Duration , PhysicalName , RemovalPolicy , Stack , Tag } from '@aws-cdk/core' ;
7
7
import {
8
8
Attribute ,
9
9
AttributeType ,
@@ -67,8 +67,12 @@ function* LSI_GENERATOR(): Generator<LocalSecondaryIndexProps, never> {
67
67
}
68
68
69
69
describe ( 'default properties' , ( ) => {
70
+ let stack : Stack ;
71
+ beforeEach ( ( ) => {
72
+ stack = new Stack ( ) ;
73
+ } ) ;
74
+
70
75
test ( 'hash key only' , ( ) => {
71
- const stack = new Stack ( ) ;
72
76
new Table ( stack , CONSTRUCT_NAME , { partitionKey : TABLE_PARTITION_KEY } ) ;
73
77
74
78
expect ( stack ) . toHaveResource ( 'AWS::DynamoDB::Table' , {
@@ -82,15 +86,13 @@ describe('default properties', () => {
82
86
} ) ;
83
87
84
88
test ( 'removalPolicy is DESTROY' , ( ) => {
85
- const stack = new Stack ( ) ;
86
89
new Table ( stack , CONSTRUCT_NAME , { partitionKey : TABLE_PARTITION_KEY , removalPolicy : RemovalPolicy . DESTROY } ) ;
87
90
88
91
expect ( stack ) . toHaveResource ( 'AWS::DynamoDB::Table' , { DeletionPolicy : CfnDeletionPolicy . DELETE } , ResourcePart . CompleteDefinition ) ;
89
92
90
93
} ) ;
91
94
92
95
test ( 'hash + range key' , ( ) => {
93
- const stack = new Stack ( ) ;
94
96
new Table ( stack , CONSTRUCT_NAME , {
95
97
partitionKey : TABLE_PARTITION_KEY ,
96
98
sortKey : TABLE_SORT_KEY ,
@@ -110,8 +112,6 @@ describe('default properties', () => {
110
112
} ) ;
111
113
112
114
test ( 'hash + range key can also be specified in props' , ( ) => {
113
- const stack = new Stack ( ) ;
114
-
115
115
new Table ( stack , CONSTRUCT_NAME , {
116
116
partitionKey : TABLE_PARTITION_KEY ,
117
117
sortKey : TABLE_SORT_KEY ,
@@ -132,7 +132,6 @@ describe('default properties', () => {
132
132
} ) ;
133
133
134
134
test ( 'point-in-time recovery is not enabled' , ( ) => {
135
- const stack = new Stack ( ) ;
136
135
new Table ( stack , CONSTRUCT_NAME , {
137
136
partitionKey : TABLE_PARTITION_KEY ,
138
137
sortKey : TABLE_SORT_KEY ,
@@ -154,7 +153,6 @@ describe('default properties', () => {
154
153
} ) ;
155
154
156
155
test ( 'server-side encryption is not enabled' , ( ) => {
157
- const stack = new Stack ( ) ;
158
156
new Table ( stack , CONSTRUCT_NAME , {
159
157
partitionKey : TABLE_PARTITION_KEY ,
160
158
sortKey : TABLE_SORT_KEY ,
@@ -176,7 +174,6 @@ describe('default properties', () => {
176
174
} ) ;
177
175
178
176
test ( 'stream is not enabled' , ( ) => {
179
- const stack = new Stack ( ) ;
180
177
new Table ( stack , CONSTRUCT_NAME , {
181
178
partitionKey : TABLE_PARTITION_KEY ,
182
179
sortKey : TABLE_SORT_KEY ,
@@ -198,7 +195,6 @@ describe('default properties', () => {
198
195
} ) ;
199
196
200
197
test ( 'ttl is not enabled' , ( ) => {
201
- const stack = new Stack ( ) ;
202
198
new Table ( stack , CONSTRUCT_NAME , {
203
199
partitionKey : TABLE_PARTITION_KEY ,
204
200
sortKey : TABLE_SORT_KEY ,
@@ -220,8 +216,6 @@ describe('default properties', () => {
220
216
} ) ;
221
217
222
218
test ( 'can specify new and old images' , ( ) => {
223
- const stack = new Stack ( ) ;
224
-
225
219
new Table ( stack , CONSTRUCT_NAME , {
226
220
tableName : TABLE_NAME ,
227
221
readCapacity : 42 ,
@@ -249,8 +243,6 @@ describe('default properties', () => {
249
243
} ) ;
250
244
251
245
test ( 'can specify new images only' , ( ) => {
252
- const stack = new Stack ( ) ;
253
-
254
246
new Table ( stack , CONSTRUCT_NAME , {
255
247
tableName : TABLE_NAME ,
256
248
readCapacity : 42 ,
@@ -278,8 +270,6 @@ describe('default properties', () => {
278
270
} ) ;
279
271
280
272
test ( 'can specify old images only' , ( ) => {
281
- const stack = new Stack ( ) ;
282
-
283
273
new Table ( stack , CONSTRUCT_NAME , {
284
274
tableName : TABLE_NAME ,
285
275
readCapacity : 42 ,
@@ -305,6 +295,19 @@ describe('default properties', () => {
305
295
} ,
306
296
) ;
307
297
} ) ;
298
+
299
+ test ( 'can use PhysicalName.GENERATE_IF_NEEDED as the Table name' , ( ) => {
300
+ new Table ( stack , CONSTRUCT_NAME , {
301
+ tableName : PhysicalName . GENERATE_IF_NEEDED ,
302
+ partitionKey : TABLE_PARTITION_KEY ,
303
+ } ) ;
304
+
305
+ // since the resource has not been used in a cross-environment manner,
306
+ // so the name should not be filled
307
+ expect ( stack ) . toHaveResourceLike ( 'AWS::DynamoDB::Table' , {
308
+ TableName : ABSENT ,
309
+ } ) ;
310
+ } ) ;
308
311
} ) ;
309
312
310
313
test ( 'when specifying every property' , ( ) => {
0 commit comments