Skip to content

Commit

Permalink
Merge branch 'main' into scanlonp/fix-diff-newstack-changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Mar 7, 2024
2 parents 8338c2a + 54f0f43 commit d357495
Show file tree
Hide file tree
Showing 71 changed files with 78,503 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
aws_sns: sns,
aws_sqs: sqs,
aws_lambda: lambda,
aws_ecr_assets: docker
aws_ecr_assets: docker,
Stack
} = require('aws-cdk-lib');
}

Expand Down Expand Up @@ -65,6 +66,59 @@ class YourStack extends cdk.Stack {
}
}

class ListMultipleDependentStack extends Stack {
constructor(scope, id) {
super(scope, id);

const dependentStack1 = new DependentStack1(this, 'DependentStack1');
const dependentStack2 = new DependentStack2(this, 'DependentStack2');

this.addDependency(dependentStack1);
this.addDependency(dependentStack2);
}
}

class DependentStack1 extends Stack {
constructor(scope, id) {
super(scope, id);

}
}

class DependentStack2 extends Stack {
constructor(scope, id) {
super(scope, id);

}
}

class ListStack extends Stack {
constructor(scope, id) {
super(scope, id);

const dependentStack = new DependentStack(this, 'DependentStack');

this.addDependency(dependentStack);
}
}

class DependentStack extends Stack {
constructor(scope, id) {
super(scope, id);

const innerDependentStack = new InnerDependentStack(this, 'InnerDependentStack');

this.addDependency(innerDependentStack);
}
}

class InnerDependentStack extends Stack {
constructor(scope, id) {
super(scope, id);

}
}

class MigrateStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);
Expand Down Expand Up @@ -498,6 +552,8 @@ switch (stackSet) {

new StackWithNestedStack(app, `${stackPrefix}-with-nested-stack`);
new StackWithNestedStackUsingParameters(app, `${stackPrefix}-with-nested-stack-using-parameters`);
new ListStack(app, `${stackPrefix}-list-stacks`)
new ListMultipleDependentStack(app, `${stackPrefix}-list-multiple-dependent-stacks`);

new YourStack(app, `${stackPrefix}-termination-protection`, {
terminationProtection: process.env.TERMINATION_PROTECTION !== 'FALSE' ? true : false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,139 @@ integTest('cdk ls', withDefaultFixture(async (fixture) => {
}
}));

/**
* Type to store stack dependencies recursively
*/
type DependencyDetails = {
id: string;
dependencies: DependencyDetails[];
};

type StackDetails = {
id: string;
dependencies: DependencyDetails[];
};

integTest('cdk ls --show-dependencies --json', withDefaultFixture(async (fixture) => {
const listing = await fixture.cdk(['ls --show-dependencies --json'], { captureStderr: false });

const expectedStacks = [
{
id: 'test-1',
dependencies: [],
},
{
id: 'order-providing',
dependencies: [],
},
{
id: 'order-consuming',
dependencies: [
{
id: 'order-providing',
dependencies: [],
},
],
},
{
id: 'with-nested-stack',
dependencies: [],
},
{
id: 'list-stacks',
dependencies: [
{
id: 'liststacksDependentStack',
dependencies: [
{
id: 'liststacksDependentStackInnerDependentStack',
dependencies: [],
},
],
},
],
},
{
id: 'list-multiple-dependent-stacks',
dependencies: [
{
id: 'listmultipledependentstacksDependentStack1',
dependencies: [],
},
{
id: 'listmultipledependentstacksDependentStack2',
dependencies: [],
},
],
},
];

function validateStackDependencies(stack: StackDetails) {
expect(listing).toContain(stack.id);

function validateDependencies(dependencies: DependencyDetails[]) {
for (const dependency of dependencies) {
expect(listing).toContain(dependency.id);
if (dependency.dependencies.length > 0) {
validateDependencies(dependency.dependencies);
}
}
}

if (stack.dependencies.length > 0) {
validateDependencies(stack.dependencies);
}
}

for (const stack of expectedStacks) {
validateStackDependencies(stack);
}
}));

integTest('cdk ls --show-dependencies --json --long', withDefaultFixture(async (fixture) => {
const listing = await fixture.cdk(['ls --show-dependencies --json --long'], { captureStderr: false });

const expectedStacks = [
{
id: 'order-providing',
name: 'order-providing',
enviroment: {
account: 'unknown-account',
region: 'unknown-region',
name: 'aws://unknown-account/unknown-region',
},
dependencies: [],
},
{
id: 'order-consuming',
name: 'order-consuming',
enviroment: {
account: 'unknown-account',
region: 'unknown-region',
name: 'aws://unknown-account/unknown-region',
},
dependencies: [
{
id: 'order-providing',
dependencies: [],
},
],
},
];

for (const stack of expectedStacks) {
expect(listing).toContain(fixture.fullStackName(stack.id));
expect(listing).toContain(fixture.fullStackName(stack.name));
expect(listing).toContain(stack.enviroment.account);
expect(listing).toContain(stack.enviroment.name);
expect(listing).toContain(stack.enviroment.region);
for (const dependency of stack.dependencies) {
expect(listing).toContain(fixture.fullStackName(dependency.id));
}
}

}));

integTest('synthing a stage with errors leads to failure', withDefaultFixture(async (fixture) => {
const output = await fixture.cdk(['synth'], {
allowErrExit: true,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d357495

Please sign in to comment.