Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: this.node.addError does not cause cdk diff to fail #4700 #5284

Merged
merged 7 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class CdkToolkit {
defaultBehavior: DefaultSelection.AllStacks
});

this.appStacks.processMetadata(stacks);

const strict = !!options.strict;
const contextLines = options.contextLines || 3;
const stream = options.stream || process.stderr;
Expand Down
42 changes: 42 additions & 0 deletions packages/aws-cdk/test/test.diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ const FIXED_RESULT = testAssembly({
stackName: 'B',
depends: ['A'],
template: { resource: 'B' },
},
{
stackName: 'C',
depends: ['A'],
template: { resource: 'C'},
metadata: {
'/resource': [
{
type: cxapi.ERROR_METADATA_KEY,
data: 'this is an error'
}
]
}
}]
});

Expand Down Expand Up @@ -83,6 +96,35 @@ export = {

test.done();
},

async 'throws an error during diffs on stack with error metadata'(test: Test) {
// GIVEN
const provisioner: IDeploymentTarget = {
async readCurrentTemplate(_stack: cxapi.CloudFormationStackArtifact): Promise<Template> {
return {};
},
async deployStack(_options: DeployStackOptions): Promise<DeployStackResult> {
return { noOp: true, outputs: {}, stackArn: ''};
}
};
const toolkit = new CdkToolkit({ appStacks, provisioner });
const buffer = new StringWritable();

// WHEN
try {
const exitCode = await toolkit.diff({
stackNames: ['C'],
stream: buffer
});

// THEN
test.equals(1, exitCode);
} catch (e) {
test.ok(/Found errors/.test(e.toString()), 'Wrong error');
}

test.done();
},
};

class StringWritable extends Writable {
Expand Down