Skip to content

Commit 4f3c609

Browse files
committed
unit and integ tests
1 parent 8851450 commit 4f3c609

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
257257
private readonly deployRoleArn?: string;
258258

259259
constructor(scope: App, id: string, private readonly props: DefaultStagingStackProps) {
260-
// eslint-disable-next-line no-console
261-
console.log('hello');
262260
super(scope, id, {
263261
...props,
264262
synthesizer: new BootstraplessSynthesizer({

packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ describe(AppStagingSynthesizer, () => {
2626
});
2727
});
2828

29+
test('uses qualifier in deployment roles and staging context', () => {
30+
// GIVEN
31+
const qualifier = 'custom-qualifier';
32+
const customApp = new App({
33+
defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({
34+
appId: APP_ID,
35+
bootstrapQualifier: qualifier,
36+
stagingBucketEncryption: BucketEncryption.S3_MANAGED,
37+
}),
38+
});
39+
new Stack(customApp, 'CustomStack', {
40+
env: {
41+
account: '111111111111',
42+
region: 'us-east-1',
43+
},
44+
});
45+
46+
// WHEN
47+
const assembly = customApp.synth();
48+
const artifact = assembly.getStackArtifact('CustomStack');
49+
50+
// THEN
51+
// The deployment role should contain the custom qualifier
52+
expect(artifact.assumeRoleArn).toBe(`arn:\${AWS::Partition}:iam::111111111111:role/cdk-${qualifier}-deploy-role-111111111111-us-east-1`);
53+
54+
// The CloudFormation execution role should contain the custom qualifier
55+
expect(artifact.cloudFormationExecutionRoleArn).toBe(`arn:\${AWS::Partition}:iam::111111111111:role/cdk-${qualifier}-cfn-exec-role-111111111111-us-east-1`);
56+
});
57+
2958
test('stack template is in asset manifest', () => {
3059
// GIVEN
3160
new CfnResource(stack, 'Resource', {

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as integ from '@aws-cdk/integ-tests-alpha';
33
import { App, Stack } from 'aws-cdk-lib';
4+
import { Template } from 'aws-cdk-lib/assertions';
45
import * as lambda from 'aws-cdk-lib/aws-lambda';
56
import { BucketEncryption } from 'aws-cdk-lib/aws-s3';
67
import { APP_ID_MAX } from './util';
@@ -9,13 +10,34 @@ import { AppStagingSynthesizer } from '../lib';
910
// IMAGE_COPIES env variable is used to test maximum number of ECR repositories allowed.
1011
const IMAGE_COPIES = Number(process.env.IMAGE_COPIES) ?? 1;
1112

13+
// Test with custom qualifier
14+
const CUSTOM_QUALIFIER = 'custom-qualifier';
15+
1216
const app = new App({
1317
context: {
1418
'@aws-cdk/aws-iam:minimizePolicies': true,
1519
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
1620
},
1721
});
1822

23+
// Stack with custom qualifier
24+
const stackWithQualifier = new Stack(app, 'synthesize-with-qualifier', {
25+
synthesizer: AppStagingSynthesizer.defaultResources({
26+
appId: APP_ID_MAX,
27+
bootstrapQualifier: CUSTOM_QUALIFIER,
28+
stagingBucketEncryption: BucketEncryption.KMS,
29+
}),
30+
});
31+
32+
// Add a lambda to trigger asset creation
33+
new lambda.Function(stackWithQualifier, 'lambda-with-qualifier', {
34+
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'assets')),
35+
handler: 'index.handler',
36+
runtime: lambda.Runtime.PYTHON_3_10,
37+
});
38+
39+
// Default stack without qualifier
40+
1941
const stack = new Stack(app, 'synthesize-default-resources', {
2042
synthesizer: AppStagingSynthesizer.defaultResources({
2143
appId: APP_ID_MAX, // this has implications on the overall template size
@@ -57,13 +79,27 @@ new lambda.Function(stack, 'lambda-ecr-two', {
5779
runtime: lambda.Runtime.FROM_IMAGE,
5880
});
5981

82+
// Get both staging stacks
6083
const defaultStagingStack = app.node.tryFindChild(`StagingStack-${APP_ID_MAX}-ACCOUNT-REGION`) as Stack;
61-
if (!defaultStagingStack) {
62-
throw new Error('Default Staging Stack not found');
84+
const qualifierStagingStack = app.node.tryFindChild(`StagingStack-${CUSTOM_QUALIFIER}-ACCOUNT-REGION`) as Stack;
85+
86+
if (!defaultStagingStack || !qualifierStagingStack) {
87+
throw new Error('One or more staging stacks not found');
6388
}
6489

90+
// Add assertions to verify qualifier usage
6591
new integ.IntegTest(app, 'integ-tests', {
66-
testCases: [stack, defaultStagingStack],
92+
testCases: [stack, stackWithQualifier, defaultStagingStack, qualifierStagingStack],
93+
diffAssets: true,
94+
});
95+
96+
// Verify qualifier is used in role names
97+
Template.fromStack(qualifierStagingStack).hasResourceProperties('AWS::IAM::Role', {
98+
RoleName: `cdk-${CUSTOM_QUALIFIER}-deploy-role-ACCOUNT-REGION`,
99+
});
100+
101+
Template.fromStack(qualifierStagingStack).hasResourceProperties('AWS::IAM::Role', {
102+
RoleName: `cdk-${CUSTOM_QUALIFIER}-file-role-REGION`,
67103
});
68104

69105
app.synth();

packages/aws-cdk-lib/core/test/stack-synthesizers/bootstrapless-synthesizer.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { FileAssetPackaging } from '@aws-cdk/cloud-assembly-schema';
22
import { App } from '../../lib/app';
33
import { Stack } from '../../lib/stack';
44
import { BootstraplessSynthesizer } from '../../lib/stack-synthesizers/bootstrapless-synthesizer';
5-
import { DefaultStackSynthesizer } from '../../lib/stack-synthesizers/default-synthesizer';
6-
import { getAssetManifest, readAssetManifest } from './_helpers';
75

86
describe('BootstraplessSynthesizer', () => {
97
test('differs from DefaultStackSynthesizer in bootstrap requirements', () => {

0 commit comments

Comments
 (0)