Skip to content
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

This file was deleted.

53 changes: 53 additions & 0 deletions packages/@aws-cdk/toolkit-lib/test/actions/drift.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,57 @@ describe('drift', () => {
expect(Object.keys(result).length).toBe(0);
ioHost.expectMessage({ containing: 'No drift results available' });
});

test('resources without a drift record are reported as unchecked in the summary', async () => {
// GIVEN - drift detection completes, but CloudFormation returns no drift
// record for the bucket (e.g. the resource type does not support drift
// detection)
mockCloudFormationClient.on(DetectStackDriftCommand).resolves({ StackDriftDetectionId: '12345' });
mockCloudFormationClient.on(DescribeStackDriftDetectionStatusCommand).resolves({ DetectionStatus: 'DETECTION_COMPLETE' });
mockCloudFormationClient.on(DescribeStackResourceDriftsCommand).resolvesOnce({
StackResourceDrifts: [],
});

// WHEN
const cx = await builderFixture(toolkit, 'stack-with-bucket');
const result = await toolkit.drift(cx, {
stacks: { strategy: StackSelectionStrategy.ALL_STACKS },
});

// THEN
expect(result.Stack1.numResourcesWithDrift).toBe(0);
expect(result.Stack1.numResourcesUnchecked).toBe(1);
// the final tally includes the unchecked count
ioHost.expectMessage({ containing: 'Number of resources with drift: 0 (1 unchecked)' });
});

test('summary has no unchecked suffix when all resources were checked', async () => {
// GIVEN - every resource has a drift record
mockCloudFormationClient.on(DetectStackDriftCommand).resolves({ StackDriftDetectionId: '12345' });
mockCloudFormationClient.on(DescribeStackDriftDetectionStatusCommand).resolves({ DetectionStatus: 'DETECTION_COMPLETE' });
mockCloudFormationClient.on(DescribeStackResourceDriftsCommand).resolvesOnce({
StackResourceDrifts: [
{
StackId: 'some:stack:arn',
StackResourceDriftStatus: 'IN_SYNC',
LogicalResourceId: 'MyBucketF68F3FF0',
PhysicalResourceId: 'physical-id-1',
ResourceType: 'AWS::S3::Bucket',
Timestamp: new Date(Date.now()),
},
],
});

// WHEN
const cx = await builderFixture(toolkit, 'stack-with-bucket');
const result = await toolkit.drift(cx, {
stacks: { strategy: StackSelectionStrategy.ALL_STACKS },
});

// THEN
expect(result.Stack1.numResourcesWithDrift).toBe(0);
expect(result.Stack1.numResourcesUnchecked).toBe(0);
ioHost.expectMessage({ containing: 'Number of resources with drift: 0' });
expect(() => ioHost.expectMessage({ containing: 'unchecked' })).toThrow();
});
});
Loading