Skip to content

Commit

Permalink
tests that dont work
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Feb 28, 2025
1 parent d756eaf commit b127679
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export class TestIoHost implements IIoHost {
return true;
}
}
}
}
69 changes: 69 additions & 0 deletions packages/aws-cdk/test/toolkit/cli-io-host.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PassThrough } from 'stream';
import * as chalk from 'chalk';
import { CliIoHost, IoMessage, IoMessageLevel, IoRequest } from '../../lib/toolkit/cli-io-host';
import { RequireApproval } from '@aws-cdk/cloud-assembly-schema';

let passThrough: PassThrough;

Expand All @@ -24,6 +25,7 @@ describe('CliIoHost', () => {
ioHost.isTTY = process.stdout.isTTY ?? false;
ioHost.isCI = false;
ioHost.currentAction = 'synth';
ioHost.requireApproval = RequireApproval.ANYCHANGE;
(process as any).stdin = passThrough = new PassThrough();

defaultMessage = {
Expand Down Expand Up @@ -378,6 +380,73 @@ describe('CliIoHost', () => {
expect(response).toEqual([1, 2, 3]);
});
});

describe('requireApproval', () => {
test('require approval by default', async () => {
const response = await ioHost.requestResponse({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I5060',
message: 'test message',
defaultResponse: true,
});

expect(mockStderr).toHaveBeenCalledWith('test message\n');
expect(response).toEqual(true);
});

test('never require approval', async () => {
ioHost.requireApproval = RequireApproval.NEVER;
const response = await ioHost.requestResponse({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I5060',
message: 'test message',
defaultResponse: true,
});

expect(mockStderr).not.toHaveBeenCalledWith('test message\n');
expect(response).toEqual(true);
});

test('broadening - require approval on broadening changes', async () => {
ioHost.requireApproval = RequireApproval.BROADENING;
const response = await ioHost.requestResponse({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I5060',
message: 'test message',
data: {
permissionChangeType: 'broadening',
},
defaultResponse: true,
});

expect(mockStderr).toHaveBeenCalledWith('test message\n');
expect(response).toEqual(true);
});

test('broadening - do notrequire approval on non-broadening changes', async () => {
ioHost.requireApproval = RequireApproval.BROADENING;
const response = await ioHost.requestResponse({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I5060',
message: 'test message',
data: {
permissionChangeType: 'non-broadening',
},
defaultResponse: true,
});

expect(mockStderr).not.toHaveBeenCalledWith('test message\n');
expect(response).toEqual(true);
});
});
});
});

Expand Down

0 comments on commit b127679

Please sign in to comment.