@@ -5,27 +5,19 @@ import * as iam from '@aws-cdk/aws-iam';
5
5
import * as cxschema from '@aws-cdk/cloud-assembly-schema' ;
6
6
import { App , DefaultStackSynthesizer , IgnoreMode , Lazy , LegacyStackSynthesizer , Stack , Stage } from '@aws-cdk/core' ;
7
7
import * as cxapi from '@aws-cdk/cx-api' ;
8
+ import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag' ;
8
9
import { DockerImageAsset } from '../lib' ;
9
10
10
11
/* eslint-disable quote-props */
11
12
12
13
const DEMO_IMAGE_ASSET_HASH = 'b2c69bfbfe983b634456574587443159b3b7258849856a118ad3d2772238f1a5' ;
13
14
14
-
15
- let app : App ;
16
- let stack : Stack ;
17
- beforeEach ( ( ) => {
18
- app = new App ( {
19
- context : {
20
- '@aws-cdk/aws-ecr-assets:dockerIgnoreSupport' : true ,
21
- } ,
22
- } ) ;
23
- stack = new Stack ( app , 'Stack' ) ;
24
- } ) ;
15
+ const flags = { [ cxapi . DOCKER_IGNORE_SUPPORT ] : true } ;
25
16
26
17
describe ( 'image asset' , ( ) => {
27
- test ( 'test instantiating Asset Image' , ( ) => {
18
+ testFutureBehavior ( 'test instantiating Asset Image' , flags , App , ( app ) => {
28
19
// WHEN
20
+ const stack = new Stack ( app ) ;
29
21
new DockerImageAsset ( stack , 'Image' , {
30
22
directory : path . join ( __dirname , 'demo-image' ) ,
31
23
} ) ;
@@ -47,8 +39,9 @@ describe('image asset', () => {
47
39
48
40
} ) ;
49
41
50
- test ( 'with build args' , ( ) => {
42
+ testFutureBehavior ( 'with build args' , flags , App , ( app ) => {
51
43
// WHEN
44
+ const stack = new Stack ( app ) ;
52
45
new DockerImageAsset ( stack , 'Image' , {
53
46
directory : path . join ( __dirname , 'demo-image' ) ,
54
47
buildArgs : {
@@ -62,8 +55,9 @@ describe('image asset', () => {
62
55
63
56
} ) ;
64
57
65
- test ( 'with target' , ( ) => {
58
+ testFutureBehavior ( 'with target' , flags , App , ( app ) => {
66
59
// WHEN
60
+ const stack = new Stack ( app ) ;
67
61
new DockerImageAsset ( stack , 'Image' , {
68
62
directory : path . join ( __dirname , 'demo-image' ) ,
69
63
buildArgs : {
@@ -78,8 +72,9 @@ describe('image asset', () => {
78
72
79
73
} ) ;
80
74
81
- test ( 'with file' , ( ) => {
75
+ testFutureBehavior ( 'with file' , flags , App , ( app ) => {
82
76
// GIVEN
77
+ const stack = new Stack ( app ) ;
83
78
const directoryPath = path . join ( __dirname , 'demo-image-custom-docker-file' ) ;
84
79
// WHEN
85
80
new DockerImageAsset ( stack , 'Image' , {
@@ -93,8 +88,9 @@ describe('image asset', () => {
93
88
94
89
} ) ;
95
90
96
- test ( 'asset.repository.grantPull can be used to grant a principal permissions to use the image' , ( ) => {
91
+ testFutureBehavior ( 'asset.repository.grantPull can be used to grant a principal permissions to use the image' , flags , App , ( app ) => {
97
92
// GIVEN
93
+ const stack = new Stack ( app ) ;
98
94
const user = new iam . User ( stack , 'MyUser' ) ;
99
95
const asset = new DockerImageAsset ( stack , 'Image' , {
100
96
directory : path . join ( __dirname , 'demo-image' ) ,
@@ -155,6 +151,7 @@ describe('image asset', () => {
155
151
} ) ;
156
152
157
153
test ( 'fails if the directory does not exist' , ( ) => {
154
+ const stack = new Stack ( ) ;
158
155
// THEN
159
156
expect ( ( ) => {
160
157
new DockerImageAsset ( stack , 'MyAsset' , {
@@ -165,6 +162,7 @@ describe('image asset', () => {
165
162
} ) ;
166
163
167
164
test ( 'fails if the directory does not contain a Dockerfile' , ( ) => {
165
+ const stack = new Stack ( ) ;
168
166
// THEN
169
167
expect ( ( ) => {
170
168
new DockerImageAsset ( stack , 'Asset' , {
@@ -175,6 +173,7 @@ describe('image asset', () => {
175
173
} ) ;
176
174
177
175
test ( 'fails if the file does not exist' , ( ) => {
176
+ const stack = new Stack ( ) ;
178
177
// THEN
179
178
expect ( ( ) => {
180
179
new DockerImageAsset ( stack , 'Asset' , {
@@ -185,7 +184,8 @@ describe('image asset', () => {
185
184
186
185
} ) ;
187
186
188
- test ( 'docker directory is staged if asset staging is enabled' , ( ) => {
187
+ testFutureBehavior ( 'docker directory is staged if asset staging is enabled' , flags , App , ( app ) => {
188
+ const stack = new Stack ( app ) ;
189
189
const image = new DockerImageAsset ( stack , 'MyAsset' , {
190
190
directory : path . join ( __dirname , 'demo-image' ) ,
191
191
} ) ;
@@ -197,15 +197,16 @@ describe('image asset', () => {
197
197
198
198
} ) ;
199
199
200
- test ( 'docker directory is staged without files specified in .dockerignore' , ( ) => {
201
- testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( ) ;
200
+ testFutureBehavior ( 'docker directory is staged without files specified in .dockerignore' , flags , App , ( app ) => {
201
+ testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( app ) ;
202
202
} ) ;
203
203
204
- test ( 'docker directory is staged without files specified in .dockerignore with IgnoreMode.GLOB' , ( ) => {
205
- testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( IgnoreMode . GLOB ) ;
204
+ testFutureBehavior ( 'docker directory is staged without files specified in .dockerignore with IgnoreMode.GLOB' , flags , App , ( app ) => {
205
+ testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( app , IgnoreMode . GLOB ) ;
206
206
} ) ;
207
207
208
- test ( 'docker directory is staged with whitelisted files specified in .dockerignore' , ( ) => {
208
+ testFutureBehavior ( 'docker directory is staged with whitelisted files specified in .dockerignore' , flags , App , ( app ) => {
209
+ const stack = new Stack ( app ) ;
209
210
const image = new DockerImageAsset ( stack , 'MyAsset' , {
210
211
directory : path . join ( __dirname , 'whitelisted-image' ) ,
211
212
} ) ;
@@ -227,16 +228,17 @@ describe('image asset', () => {
227
228
228
229
} ) ;
229
230
230
- test ( 'docker directory is staged without files specified in exclude option' , ( ) => {
231
- testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( ) ;
231
+ testFutureBehavior ( 'docker directory is staged without files specified in exclude option' , flags , App , ( app ) => {
232
+ testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( app ) ;
232
233
} ) ;
233
234
234
- test ( 'docker directory is staged without files specified in exclude option with IgnoreMode.GLOB' , ( ) => {
235
- testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( IgnoreMode . GLOB ) ;
235
+ testFutureBehavior ( 'docker directory is staged without files specified in exclude option with IgnoreMode.GLOB' , flags , App , ( app ) => {
236
+ testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( app , IgnoreMode . GLOB ) ;
236
237
} ) ;
237
238
238
239
test ( 'fails if using tokens in build args keys or values' , ( ) => {
239
240
// GIVEN
241
+ const stack = new Stack ( ) ;
240
242
const token = Lazy . string ( { produce : ( ) => 'foo' } ) ;
241
243
const expected = / C a n n o t u s e t o k e n s i n k e y s o r v a l u e s o f " b u i l d A r g s " s i n c e t h e y a r e n e e d e d b e f o r e d e p l o y m e n t / ;
242
244
@@ -256,6 +258,7 @@ describe('image asset', () => {
256
258
257
259
test ( 'fails if using token as repositoryName' , ( ) => {
258
260
// GIVEN
261
+ const stack = new Stack ( ) ;
259
262
const token = Lazy . string ( { produce : ( ) => 'foo' } ) ;
260
263
261
264
// THEN
@@ -267,8 +270,9 @@ describe('image asset', () => {
267
270
268
271
} ) ;
269
272
270
- test ( 'docker build options are included in the asset id' , ( ) => {
273
+ testFutureBehavior ( 'docker build options are included in the asset id' , flags , App , ( app ) => {
271
274
// GIVEN
275
+ const stack = new Stack ( app ) ;
272
276
const directory = path . join ( __dirname , 'demo-image-custom-docker-file' ) ;
273
277
274
278
const asset1 = new DockerImageAsset ( stack , 'Asset1' , { directory } ) ;
@@ -290,7 +294,8 @@ describe('image asset', () => {
290
294
} ) ;
291
295
} ) ;
292
296
293
- function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( ignoreMode ?: IgnoreMode ) {
297
+ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore ( app : App , ignoreMode ?: IgnoreMode ) {
298
+ const stack = new Stack ( app ) ;
294
299
const image = new DockerImageAsset ( stack , 'MyAsset' , {
295
300
ignoreMode,
296
301
directory : path . join ( __dirname , 'dockerignore-image' ) ,
@@ -309,7 +314,8 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore(ignoreMo
309
314
310
315
}
311
316
312
- function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( ignoreMode ?: IgnoreMode ) {
317
+ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption ( app : App , ignoreMode ?: IgnoreMode ) {
318
+ const stack = new Stack ( app ) ;
313
319
const image = new DockerImageAsset ( stack , 'MyAsset' , {
314
320
directory : path . join ( __dirname , 'dockerignore-image' ) ,
315
321
exclude : [ 'subdirectory' ] ,
@@ -328,7 +334,7 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(ignoreM
328
334
329
335
}
330
336
331
- test ( 'nested assemblies share assets: legacy synth edition' , ( ) => {
337
+ testFutureBehavior ( 'nested assemblies share assets: legacy synth edition' , flags , App , ( app ) => {
332
338
// GIVEN
333
339
const stack1 = new Stack ( new Stage ( app , 'Stage1' ) , 'Stack' , { synthesizer : new LegacyStackSynthesizer ( ) } ) ;
334
340
const stack2 = new Stack ( new Stage ( app , 'Stage2' ) , 'Stack' , { synthesizer : new LegacyStackSynthesizer ( ) } ) ;
@@ -354,7 +360,7 @@ test('nested assemblies share assets: legacy synth edition', () => {
354
360
}
355
361
} ) ;
356
362
357
- test ( 'nested assemblies share assets: default synth edition' , ( ) => {
363
+ testFutureBehavior ( 'nested assemblies share assets: default synth edition' , flags , App , ( app ) => {
358
364
// GIVEN
359
365
const stack1 = new Stack ( new Stage ( app , 'Stage1' ) , 'Stack' , { synthesizer : new DefaultStackSynthesizer ( ) } ) ;
360
366
const stack2 = new Stack ( new Stage ( app , 'Stage2' ) , 'Stack' , { synthesizer : new DefaultStackSynthesizer ( ) } ) ;
0 commit comments