From 41377d138ae2570afb46abf18e324abdcd046448 Mon Sep 17 00:00:00 2001 From: SankyRed Date: Fri, 23 Feb 2024 16:59:35 -0600 Subject: [PATCH] unit test and debugging integ test --- .../aws-cdk/lib/api/cxapp/cloud-assembly.ts | 4 ++ packages/aws-cdk/test/list-stacks.test.ts | 60 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts index 6b827d4a2e363..679dc1ed0833e 100644 --- a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts +++ b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts @@ -102,9 +102,13 @@ export class CloudAssembly { public async selectStacks(selector: StackSelector, options: SelectStacksOptions): Promise { 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) { diff --git a/packages/aws-cdk/test/list-stacks.test.ts b/packages/aws-cdk/test/list-stacks.test.ts index d93f18c0d8263..e36081e99c1d2 100644 --- a/packages/aws-cdk/test/list-stacks.test.ts +++ b/packages/aws-cdk/test/list-stacks.test.ts @@ -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: [