Skip to content

Commit

Permalink
unit test and debugging integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
SankyRed committed Feb 23, 2024
1 parent ab8a01f commit 41377d1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ export class CloudAssembly {
public async selectStacks(selector: StackSelector, options: SelectStacksOptions): Promise<StackCollection> {
const asm = this.assembly;
const topLevelStacks = asm.stacks;
// eslint-disable-next-line no-console
console.log('---Top level stacks--- :'+topLevelStacks);
const stacks = semver.major(asm.version) < 10 ? asm.stacks : asm.stacksRecursively;
const allTopLevel = selector.allTopLevel ?? false;
const patterns = sanitizePatterns(selector.patterns);
// eslint-disable-next-line no-console
console.log('---Patterns--- :'+ patterns);

if (stacks.length === 0) {
if (options.ignoreNoStacks) {
Expand Down
60 changes: 60 additions & 0 deletions packages/aws-cdk/test/list-stacks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,66 @@ describe('list', () => {
}]));
});

// In the context where we have a display name set to hieraricalId/stackName
// we would need to pass in the displayName to list the stacks.
test('stacks with dependent stacks and have display name set to hieraricalId/stackName', async () => {
let cloudExecutable = new MockCloudExecutable({
stacks: [
MockStack.MOCK_STACK_A,
{
stackName: 'Test-Stack-B',
template: { Resources: { TemplateName: 'Test-Stack-B' } },
env: 'aws://123456789012/bermuda-triangle-1',
metadata: {
'/Test-Stack-B': [
{
type: cxschema.ArtifactMetadataEntryType.STACK_TAGS,
},
],
},
depends: ['Test-Stack-A'],
displayName: 'Test-Stack-A/Test-Stack-B',
},
],
});

// GIVEN
const toolkit = new CdkToolkit({
cloudExecutable,
configuration: cloudExecutable.configuration,
sdkProvider: cloudExecutable.sdkProvider,
deployments: cloudFormation,
});

// WHEN
const workflow = await listStacks( toolkit, { selectors: ['Test-Stack-A', 'Test-Stack-A/Test-Stack-B'] });

// THEN
expect(JSON.stringify(workflow)).toEqual(JSON.stringify([{
id: 'Test-Stack-A',
name: 'Test-Stack-A',
environment: {
account: '123456789012',
region: 'bermuda-triangle-1',
name: 'aws://123456789012/bermuda-triangle-1',
},
dependencies: [],
},
{
id: 'Test-Stack-B',
name: 'Test-Stack-B',
environment: {
account: '123456789012',
region: 'bermuda-triangle-1',
name: 'aws://123456789012/bermuda-triangle-1',
},
dependencies: [{
id: 'Test-Stack-A',
dependencies: [],
}],
}]));
});

test('stacks with nested dependencies', async () => {
let cloudExecutable = new MockCloudExecutable({
stacks: [
Expand Down

0 comments on commit 41377d1

Please sign in to comment.