-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(cdk): cdk diff --quiet
to print stack name when there is diffs
#28576
Changes from all commits
d9b6bc8
fd24c9b
7243fd2
2e2f68c
3b9c9e9
3120ac5
5192cb0
7e6866c
6625a4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,10 @@ export function printStackDiff( | |
context: number, | ||
quiet: boolean, | ||
changeSet?: CloudFormation.DescribeChangeSetOutput, | ||
stream?: cfnDiff.FormatStream): number { | ||
stream?: cfnDiff.FormatStream, | ||
stackDiff?: cfnDiff.TemplateDiff): number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
let diff = cfnDiff.fullDiff(oldTemplate, newTemplate.template, changeSet); | ||
let diff = stackDiff ?? cfnDiff.fullDiff(oldTemplate, newTemplate.template, changeSet); | ||
|
||
// detect and filter out mangled characters from the diff | ||
let filteredChangesCount = 0; | ||
|
@@ -81,8 +82,9 @@ export function printSecurityDiff( | |
newTemplate: cxapi.CloudFormationStackArtifact, | ||
requireApproval: RequireApproval, | ||
changeSet?: CloudFormation.DescribeChangeSetOutput, | ||
stackDiff?: cfnDiff.TemplateDiff, | ||
): boolean { | ||
const diff = cfnDiff.fullDiff(oldTemplate, newTemplate.template, changeSet); | ||
const diff = stackDiff ?? cfnDiff.fullDiff(oldTemplate, newTemplate.template, changeSet); | ||
|
||
if (difRequiresApproval(diff, requireApproval)) { | ||
// eslint-disable-next-line max-len | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -281,15 +281,37 @@ describe('non-nested stacks', () => { | |||||
|
||||||
// WHEN | ||||||
const exitCode = await toolkit.diff({ | ||||||
stackNames: ['A', 'A'], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was broken, so fixed this.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch here! |
||||||
stackNames: ['D'], | ||||||
stream: buffer, | ||||||
fail: false, | ||||||
quiet: true, | ||||||
}); | ||||||
|
||||||
// THEN | ||||||
expect(buffer.data.trim()).not.toContain('Stack A'); | ||||||
expect(buffer.data.trim()).not.toContain('There were no differences'); | ||||||
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, ''); | ||||||
expect(plainTextOutput).not.toContain('Stack D'); | ||||||
expect(plainTextOutput).not.toContain('There were no differences'); | ||||||
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 0'); | ||||||
expect(exitCode).toBe(0); | ||||||
}); | ||||||
|
||||||
test('when quiet mode is enabled, stacks with diffs should print stack name to stdout', async () => { | ||||||
// GIVEN | ||||||
const buffer = new StringWritable(); | ||||||
|
||||||
// WHEN | ||||||
const exitCode = await toolkit.diff({ | ||||||
stackNames: ['A'], | ||||||
stream: buffer, | ||||||
fail: false, | ||||||
quiet: true, | ||||||
}); | ||||||
|
||||||
// THEN | ||||||
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, ''); | ||||||
expect(plainTextOutput).toContain('Stack A'); | ||||||
expect(plainTextOutput).not.toContain('There were no differences'); | ||||||
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1'); | ||||||
expect(exitCode).toBe(0); | ||||||
}); | ||||||
}); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not pass the
diff
in the same function that takes the inputs to create the diff (the old template and new template). Instead let's move theto
printStackDiff
(you can access thestackName
from thestack
object passed as the second argument toprintStackDiff
).