|
| 1 | +import { FileAssetPackaging } from '@aws-cdk/cloud-assembly-schema'; |
| 2 | +import { App } from '../../lib/app'; |
| 3 | +import { Stack } from '../../lib/stack'; |
| 4 | +import { BootstraplessSynthesizer } from '../../lib/stack-synthesizers/bootstrapless-synthesizer'; |
| 5 | +import { DefaultStackSynthesizer } from '../../lib/stack-synthesizers/default-synthesizer'; |
| 6 | +import { getAssetManifest, readAssetManifest } from './_helpers'; |
| 7 | + |
| 8 | +describe('BootstraplessSynthesizer', () => { |
| 9 | + test('differs from DefaultStackSynthesizer in bootstrap requirements', () => { |
| 10 | + // GIVEN |
| 11 | + const app = new App(); |
| 12 | + new Stack(app, 'BootstraplessStack', { |
| 13 | + synthesizer: new BootstraplessSynthesizer(), |
| 14 | + env: { |
| 15 | + account: '111111111111', |
| 16 | + region: 'us-east-1', |
| 17 | + }, |
| 18 | + }); |
| 19 | + |
| 20 | + const assembly = app.synth(); |
| 21 | + |
| 22 | + // THEN - bootstrapless stack has no bootstrap requirements |
| 23 | + const bootstraplessArtifact = assembly.getStackArtifact('BootstraplessStack'); |
| 24 | + expect(bootstraplessArtifact.requiresBootstrapStackVersion).toBeUndefined(); |
| 25 | + expect(bootstraplessArtifact.template.Parameters?.BootstrapVersion).toBeUndefined(); |
| 26 | + expect(bootstraplessArtifact.template.Parameters?.FileAssetsBucketName).toBeUndefined(); |
| 27 | + expect(bootstraplessArtifact.template.Parameters?.ImageRepositoryName).toBeUndefined(); |
| 28 | + }); |
| 29 | + |
| 30 | + test('throws when attempting to add assets', () => { |
| 31 | + // GIVEN |
| 32 | + const app = new App(); |
| 33 | + const stack = new Stack(app, 'Stack', { |
| 34 | + synthesizer: new BootstraplessSynthesizer(), |
| 35 | + env: { |
| 36 | + account: '111111111111', |
| 37 | + region: 'us-east-1', |
| 38 | + }, |
| 39 | + }); |
| 40 | + |
| 41 | + // THEN |
| 42 | + expect(() => stack.synthesizer.addFileAsset({ |
| 43 | + fileName: __filename, |
| 44 | + packaging: FileAssetPackaging.FILE, |
| 45 | + sourceHash: 'file-hash', |
| 46 | + })).toThrow('Cannot add assets to a Stack that uses the BootstraplessSynthesizer'); |
| 47 | + |
| 48 | + expect(() => stack.synthesizer.addDockerImageAsset({ |
| 49 | + directoryName: '.', |
| 50 | + sourceHash: 'docker-hash', |
| 51 | + })).toThrow('Cannot add assets to a Stack that uses the BootstraplessSynthesizer'); |
| 52 | + }); |
| 53 | + |
| 54 | + test('uses qualifier in deployment and execution roles', () => { |
| 55 | + // GIVEN |
| 56 | + const qualifier = 'custom-qualifier'; |
| 57 | + const app = new App(); |
| 58 | + const stack = new Stack(app, 'Stack', { |
| 59 | + synthesizer: new BootstraplessSynthesizer({ |
| 60 | + qualifier, |
| 61 | + }), |
| 62 | + env: { |
| 63 | + account: '111111111111', |
| 64 | + region: 'us-east-1', |
| 65 | + }, |
| 66 | + }); |
| 67 | + |
| 68 | + // WHEN |
| 69 | + const assembly = app.synth(); |
| 70 | + const artifact = assembly.getStackArtifact('Stack'); |
| 71 | + |
| 72 | + // THEN |
| 73 | + // The deployment role should contain the custom qualifier and use AWS::Partition placeholder |
| 74 | + expect(artifact.assumeRoleArn).toBe(`arn:\${AWS::Partition}:iam::111111111111:role/cdk-${qualifier}-deploy-role-111111111111-us-east-1`); |
| 75 | + |
| 76 | + // The CloudFormation execution role should contain the custom qualifier and use AWS::Partition placeholder |
| 77 | + expect(artifact.cloudFormationExecutionRoleArn).toBe(`arn:\${AWS::Partition}:iam::111111111111:role/cdk-${qualifier}-cfn-exec-role-111111111111-us-east-1`); |
| 78 | + }); |
| 79 | +}); |
0 commit comments