Skip to content

Commit 6d6aa0c

Browse files
author
Niranjan Jayakar
authored
chore: update unit tests and assertions to support feature flag expiry in CDKv2 (#13217)
In CDKv2, we will be expiring the feature flags - '@aws-cdk/aws-ecr-assets:dockerIgnoreSupport' and '@aws-cdk/aws-s3:grantWriteWithoutAcl'. Tests across the CDK code base explicitly or implicitly are verifying the behaviour of these modules that are affected by these feature flags. Update the unit tests appropriately so that they explicitly depend on one of the two behaviours, or test both. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6318e26 commit 6d6aa0c

25 files changed

+124
-95
lines changed

packages/@aws-cdk/aws-codepipeline-actions/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"devDependencies": {
6969
"@aws-cdk/assert": "0.0.0",
7070
"@aws-cdk/aws-cloudtrail": "0.0.0",
71+
"@aws-cdk/cx-api": "0.0.0",
7172
"@types/lodash": "^4.14.168",
7273
"cdk-build-tools": "0.0.0",
7374
"cdk-integ-tools": "0.0.0",

packages/@aws-cdk/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import * as lambda from '@aws-cdk/aws-lambda';
44
import * as s3 from '@aws-cdk/aws-s3';
55
import * as sns from '@aws-cdk/aws-sns';
66
import { App, Aws, Lazy, SecretValue, Stack, Token } from '@aws-cdk/core';
7+
import * as cxapi from '@aws-cdk/cx-api';
78
import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag';
89
import * as cpactions from '../../lib';
910

1011
/* eslint-disable quote-props */
1112

12-
const s3GrantWriteCtx = { '@aws-cdk/aws-s3:grantWriteWithoutAcl': true };
13+
const s3GrantWriteCtx = { [cxapi.S3_GRANT_WRITE_WITHOUT_ACL]: true };
1314

1415
describe('', () => {
1516
describe('Lambda invoke Action', () => {

packages/@aws-cdk/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '@aws-cdk/assert/jest';
22
import * as codepipeline from '@aws-cdk/aws-codepipeline';
33
import * as s3 from '@aws-cdk/aws-s3';
44
import { App, Duration, SecretValue, Stack } from '@aws-cdk/core';
5+
import * as cxapi from '@aws-cdk/cx-api';
56
import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag';
67
import * as cpactions from '../../lib';
78

@@ -48,7 +49,7 @@ describe('', () => {
4849

4950
});
5051

51-
testFutureBehavior('grant the pipeline correct access to the target bucket', { '@aws-cdk/aws-s3:grantWriteWithoutAcl': true }, App, (app) => {
52+
testFutureBehavior('grant the pipeline correct access to the target bucket', { [cxapi.S3_GRANT_WRITE_WITHOUT_ACL]: true }, App, (app) => {
5253
const stack = new Stack(app);
5354
minimalPipeline(stack);
5455

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

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"license": "Apache-2.0",
7373
"devDependencies": {
7474
"@aws-cdk/assert": "0.0.0",
75+
"@aws-cdk/cx-api": "0.0.0",
7576
"cdk-build-tools": "0.0.0",
7677
"cdk-integ-tools": "0.0.0",
7778
"cfn2ts": "0.0.0",

packages/@aws-cdk/aws-ec2/test/volume.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@aws-cdk/aws-iam';
1212
import * as kms from '@aws-cdk/aws-kms';
1313
import * as cdk from '@aws-cdk/core';
14+
import * as cxapi from '@aws-cdk/cx-api';
1415
import { testFutureBehavior, testLegacyBehavior } from 'cdk-build-tools/lib/feature-flag';
1516
import {
1617
AmazonLinuxGeneration,
@@ -575,7 +576,7 @@ describe('volume', () => {
575576

576577
});
577578

578-
testFutureBehavior('with future flag aws-kms:defaultKeyPolicies', { '@aws-cdk/aws-kms:defaultKeyPolicies': true }, cdk.App, (app) => {
579+
testFutureBehavior('with future flag aws-kms:defaultKeyPolicies', { [cxapi.KMS_DEFAULT_KEY_POLICIES]: true }, cdk.App, (app) => {
579580
// GIVEN
580581
const stack = new cdk.Stack(app);
581582
const role = new Role(stack, 'Role', { assumedBy: new AccountRootPrincipal() });

packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts

+37-31
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@ import * as iam from '@aws-cdk/aws-iam';
55
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
66
import { App, DefaultStackSynthesizer, IgnoreMode, Lazy, LegacyStackSynthesizer, Stack, Stage } from '@aws-cdk/core';
77
import * as cxapi from '@aws-cdk/cx-api';
8+
import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag';
89
import { DockerImageAsset } from '../lib';
910

1011
/* eslint-disable quote-props */
1112

1213
const DEMO_IMAGE_ASSET_HASH = 'b2c69bfbfe983b634456574587443159b3b7258849856a118ad3d2772238f1a5';
1314

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 };
2516

2617
describe('image asset', () => {
27-
test('test instantiating Asset Image', () => {
18+
testFutureBehavior('test instantiating Asset Image', flags, App, (app) => {
2819
// WHEN
20+
const stack = new Stack(app);
2921
new DockerImageAsset(stack, 'Image', {
3022
directory: path.join(__dirname, 'demo-image'),
3123
});
@@ -47,8 +39,9 @@ describe('image asset', () => {
4739

4840
});
4941

50-
test('with build args', () => {
42+
testFutureBehavior('with build args', flags, App, (app) => {
5143
// WHEN
44+
const stack = new Stack(app);
5245
new DockerImageAsset(stack, 'Image', {
5346
directory: path.join(__dirname, 'demo-image'),
5447
buildArgs: {
@@ -62,8 +55,9 @@ describe('image asset', () => {
6255

6356
});
6457

65-
test('with target', () => {
58+
testFutureBehavior('with target', flags, App, (app) => {
6659
// WHEN
60+
const stack = new Stack(app);
6761
new DockerImageAsset(stack, 'Image', {
6862
directory: path.join(__dirname, 'demo-image'),
6963
buildArgs: {
@@ -78,8 +72,9 @@ describe('image asset', () => {
7872

7973
});
8074

81-
test('with file', () => {
75+
testFutureBehavior('with file', flags, App, (app) => {
8276
// GIVEN
77+
const stack = new Stack(app);
8378
const directoryPath = path.join(__dirname, 'demo-image-custom-docker-file');
8479
// WHEN
8580
new DockerImageAsset(stack, 'Image', {
@@ -93,8 +88,9 @@ describe('image asset', () => {
9388

9489
});
9590

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) => {
9792
// GIVEN
93+
const stack = new Stack(app);
9894
const user = new iam.User(stack, 'MyUser');
9995
const asset = new DockerImageAsset(stack, 'Image', {
10096
directory: path.join(__dirname, 'demo-image'),
@@ -155,6 +151,7 @@ describe('image asset', () => {
155151
});
156152

157153
test('fails if the directory does not exist', () => {
154+
const stack = new Stack();
158155
// THEN
159156
expect(() => {
160157
new DockerImageAsset(stack, 'MyAsset', {
@@ -165,6 +162,7 @@ describe('image asset', () => {
165162
});
166163

167164
test('fails if the directory does not contain a Dockerfile', () => {
165+
const stack = new Stack();
168166
// THEN
169167
expect(() => {
170168
new DockerImageAsset(stack, 'Asset', {
@@ -175,6 +173,7 @@ describe('image asset', () => {
175173
});
176174

177175
test('fails if the file does not exist', () => {
176+
const stack = new Stack();
178177
// THEN
179178
expect(() => {
180179
new DockerImageAsset(stack, 'Asset', {
@@ -185,7 +184,8 @@ describe('image asset', () => {
185184

186185
});
187186

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);
189189
const image = new DockerImageAsset(stack, 'MyAsset', {
190190
directory: path.join(__dirname, 'demo-image'),
191191
});
@@ -197,15 +197,16 @@ describe('image asset', () => {
197197

198198
});
199199

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);
202202
});
203203

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);
206206
});
207207

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);
209210
const image = new DockerImageAsset(stack, 'MyAsset', {
210211
directory: path.join(__dirname, 'whitelisted-image'),
211212
});
@@ -227,16 +228,17 @@ describe('image asset', () => {
227228

228229
});
229230

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);
232233
});
233234

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);
236237
});
237238

238239
test('fails if using tokens in build args keys or values', () => {
239240
// GIVEN
241+
const stack = new Stack();
240242
const token = Lazy.string({ produce: () => 'foo' });
241243
const expected = /Cannot use tokens in keys or values of "buildArgs" since they are needed before deployment/;
242244

@@ -256,6 +258,7 @@ describe('image asset', () => {
256258

257259
test('fails if using token as repositoryName', () => {
258260
// GIVEN
261+
const stack = new Stack();
259262
const token = Lazy.string({ produce: () => 'foo' });
260263

261264
// THEN
@@ -267,8 +270,9 @@ describe('image asset', () => {
267270

268271
});
269272

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) => {
271274
// GIVEN
275+
const stack = new Stack(app);
272276
const directory = path.join(__dirname, 'demo-image-custom-docker-file');
273277

274278
const asset1 = new DockerImageAsset(stack, 'Asset1', { directory });
@@ -290,7 +294,8 @@ describe('image asset', () => {
290294
});
291295
});
292296

293-
function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore(ignoreMode?: IgnoreMode) {
297+
function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore(app: App, ignoreMode?: IgnoreMode) {
298+
const stack = new Stack(app);
294299
const image = new DockerImageAsset(stack, 'MyAsset', {
295300
ignoreMode,
296301
directory: path.join(__dirname, 'dockerignore-image'),
@@ -309,7 +314,8 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInDockerignore(ignoreMo
309314

310315
}
311316

312-
function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(ignoreMode?: IgnoreMode) {
317+
function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(app: App, ignoreMode?: IgnoreMode) {
318+
const stack = new Stack(app);
313319
const image = new DockerImageAsset(stack, 'MyAsset', {
314320
directory: path.join(__dirname, 'dockerignore-image'),
315321
exclude: ['subdirectory'],
@@ -328,7 +334,7 @@ function testDockerDirectoryIsStagedWithoutFilesSpecifiedInExcludeOption(ignoreM
328334

329335
}
330336

331-
test('nested assemblies share assets: legacy synth edition', () => {
337+
testFutureBehavior('nested assemblies share assets: legacy synth edition', flags, App, (app) => {
332338
// GIVEN
333339
const stack1 = new Stack(new Stage(app, 'Stage1'), 'Stack', { synthesizer: new LegacyStackSynthesizer() });
334340
const stack2 = new Stack(new Stage(app, 'Stage2'), 'Stack', { synthesizer: new LegacyStackSynthesizer() });
@@ -354,7 +360,7 @@ test('nested assemblies share assets: legacy synth edition', () => {
354360
}
355361
});
356362

357-
test('nested assemblies share assets: default synth edition', () => {
363+
testFutureBehavior('nested assemblies share assets: default synth edition', flags, App, (app) => {
358364
// GIVEN
359365
const stack1 = new Stack(new Stage(app, 'Stage1'), 'Stack', { synthesizer: new DefaultStackSynthesizer() });
360366
const stack2 = new Stack(new Stage(app, 'Stage2'), 'Stack', { synthesizer: new DefaultStackSynthesizer() });

packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as path from 'path';
22
import * as iam from '@aws-cdk/aws-iam';
33
import * as cdk from '@aws-cdk/core';
4+
import * as cxapi from '@aws-cdk/cx-api';
45
import * as assets from '../lib';
56

67
const app = new cdk.App({
78
context: {
8-
'@aws-cdk/aws-ecr-assets:dockerIgnoreSupport': true,
9+
[cxapi.DOCKER_IGNORE_SUPPORT]: true,
910
},
1011
});
1112
const stack = new cdk.Stack(app, 'integ-assets-docker');

packages/@aws-cdk/aws-ecr-assets/test/integ.nested-stacks-docker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as iam from '@aws-cdk/aws-iam';
33
import { App, CfnOutput, NestedStack, NestedStackProps, Stack, StackProps } from '@aws-cdk/core';
4+
import * as cxapi from '@aws-cdk/cx-api';
45
import { Construct } from 'constructs';
56
import * as ecr_assets from '../lib';
67

@@ -29,7 +30,7 @@ class TheParentStack extends Stack {
2930

3031
const app = new App({
3132
context: {
32-
'@aws-cdk/aws-ecr-assets:dockerIgnoreSupport': true,
33+
[cxapi.DOCKER_IGNORE_SUPPORT]: true,
3334
},
3435
});
3536
new TheParentStack(app, 'nested-stacks-docker');

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

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"devDependencies": {
7474
"@aws-cdk/assert": "0.0.0",
7575
"@aws-cdk/aws-s3-deployment": "0.0.0",
76+
"@aws-cdk/cx-api": "0.0.0",
7677
"@types/nodeunit": "^0.0.31",
7778
"@types/proxyquire": "^1.3.28",
7879
"cdk-build-tools": "0.0.0",

packages/@aws-cdk/aws-ecs/test/container-definition.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as s3 from '@aws-cdk/aws-s3';
66
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
77
import * as ssm from '@aws-cdk/aws-ssm';
88
import * as cdk from '@aws-cdk/core';
9+
import * as cxapi from '@aws-cdk/cx-api';
910
import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag';
1011
import * as ecs from '../lib';
1112

@@ -1643,7 +1644,7 @@ describe('container definition', () => {
16431644
});
16441645
});
16451646

1646-
testFutureBehavior('can use a DockerImageAsset directly for a container image', { '@aws-cdk/aws-ecr-assets:dockerIgnoreSupport': true }, cdk.App, (app) => {
1647+
testFutureBehavior('can use a DockerImageAsset directly for a container image', { [cxapi.DOCKER_IGNORE_SUPPORT]: true }, cdk.App, (app) => {
16471648
// GIVEN
16481649
const stack = new cdk.Stack(app, 'Stack');
16491650
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

packages/@aws-cdk/aws-ecs/test/ec2/ec2-task-definition.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as iam from '@aws-cdk/aws-iam';
66
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
77
import * as ssm from '@aws-cdk/aws-ssm';
88
import * as cdk from '@aws-cdk/core';
9+
import * as cxapi from '@aws-cdk/cx-api';
910
import { testFutureBehavior } from 'cdk-build-tools/lib/feature-flag';
1011
import * as ecs from '../../lib';
1112

@@ -585,7 +586,7 @@ describe('ec2 task definition', () => {
585586

586587
});
587588

588-
testFutureBehavior('correctly sets containers from asset using default props', { '@aws-cdk/aws-ecr-assets:dockerIgnoreSupport': true }, cdk.App, (app) => {
589+
testFutureBehavior('correctly sets containers from asset using default props', { [cxapi.DOCKER_IGNORE_SUPPORT]: true }, cdk.App, (app) => {
589590
// GIVEN
590591
const stack = new cdk.Stack(app, 'Stack');
591592

0 commit comments

Comments
 (0)