Skip to content

Commit 9bcaf75

Browse files
authored
fix(diff): deepEqual may miss difference other than DependsOn (#10394)
Fixes #10322 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 93ba604 commit 9bcaf75

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/@aws-cdk/cloudformation-diff/lib/diff/util.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export function deepEqual(lvalue: any, rvalue: any): boolean {
4444
if (keys.length !== Object.keys(rvalue).length) { return false; }
4545
for (const key of keys) {
4646
if (!rvalue.hasOwnProperty(key)) { return false; }
47-
if (key === 'DependsOn') { return dependsOnEqual(lvalue[key], rvalue[key]); }
47+
if (key === 'DependsOn') {
48+
if (!dependsOnEqual(lvalue[key], rvalue[key])) { return false; };
49+
// check differences other than `DependsOn`
50+
continue;
51+
}
4852
if (!deepEqual(lvalue[key], rvalue[key])) { return false; }
4953
}
5054
return true;

packages/@aws-cdk/cloudformation-diff/test/diff-template.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,36 @@ test('boolean properties are considered equal with their stringified counterpart
520520
// THEN
521521
expect(differences.differenceCount).toBe(0);
522522
});
523+
524+
test('when a property changes including equivalent DependsOn', () => {
525+
// GIVEN
526+
const bucketName = 'ShineyBucketName';
527+
const currentTemplate = {
528+
Resources: {
529+
BucketResource: {
530+
Type: 'AWS::S3::Bucket',
531+
DependsOn: ['SomeResource'],
532+
BucketName: bucketName,
533+
},
534+
},
535+
};
536+
537+
// WHEN
538+
const newBucketName = `${bucketName}-v2`;
539+
const newTemplate = {
540+
Resources: {
541+
BucketResource: {
542+
Type: 'AWS::S3::Bucket',
543+
DependsOn: ['SomeResource'],
544+
BucketName: newBucketName,
545+
},
546+
},
547+
};
548+
549+
// THEN
550+
let differences = diffTemplate(currentTemplate, newTemplate);
551+
expect(differences.resources.differenceCount).toBe(1);
552+
553+
differences = diffTemplate(newTemplate, currentTemplate);
554+
expect(differences.resources.differenceCount).toBe(1);
555+
});

0 commit comments

Comments
 (0)