Skip to content

Commit b9baaae

Browse files
committed
chore: refactor telemetry integ tests
1 parent 0b16776 commit b9baaae

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export interface CdkCliOptions extends ShellOptions {
218218
options?: string[];
219219
neverRequireApproval?: boolean;
220220
verbose?: boolean;
221+
verboseLevel?: number;
221222
telemetryFile?: string;
222223
}
223224

@@ -579,11 +580,17 @@ export class TestFixture extends ShellHelper {
579580
public async cdk(args: string[], options: CdkCliOptions = {}) {
580581
const verbose = options.verbose ?? true;
581582

583+
if (!verbose && options.verboseLevel) {
584+
throw new Error(`Invalid verbose state: verbose is false and verboseLevel is ${options.verboseLevel}`);
585+
}
586+
587+
const verboseLevel = options.verboseLevel ?? 1;
588+
582589
await this.cli.makeCliAvailable();
583590

584591
return this.shell([
585592
'cdk',
586-
...(verbose ? ['-vvv'] : []), // if we set verbose, we get all the logs
593+
...(verbose ? [`-${'v'.repeat(verboseLevel)}`] : []), // if we set verbose, we get all the logs
587594
...args,
588595
], {
589596
...options,

packages/@aws-cdk-testing/cli-integ/tests/telemetry-integ-tests/cdk-cli-telemetry-disable-sends-no-data.integtest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { integTest, withDefaultFixture } from '../../lib';
2+
import { TELEMETRY_ENDPOINT } from './constants';
23

34
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
45

56
integTest(
67
'CLI Telemetry --disable does not send to endpoint',
78
withDefaultFixture(async (fixture) => {
8-
const output = await fixture.cdk(['cli-telemetry', '--disable'], { verbose: true });
9+
const output = await fixture.cdk(['cli-telemetry', '--disable'], { verboseLevel: 3, modEnv: { TELEMETRY_ENDPOINT: TELEMETRY_ENDPOINT }});
910

1011
// Check the trace that telemetry was not executed successfully
1112
expect(output).not.toContain('Telemetry Sent Successfully');

packages/@aws-cdk-testing/cli-integ/tests/telemetry-integ-tests/cdk-deploy-telemetry.integtest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as fs from 'fs-extra';
33
import { integTest, withDefaultFixture } from '../../lib';
4+
import { TELEMETRY_ENDPOINT } from './constants';
45

56
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
67

@@ -12,7 +13,8 @@ integTest(
1213
// Deploy stack while collecting telemetry
1314
const deployOutput = await fixture.cdkDeploy('test-1', {
1415
telemetryFile,
15-
verbose: true, // force trace mode
16+
verboseLevel: 3, // trace mode
17+
modEnv: { TELEMETRY_ENDPOINT: TELEMETRY_ENDPOINT },
1618
});
1719

1820
// Check the trace that telemetry was executed successfully

packages/@aws-cdk-testing/cli-integ/tests/telemetry-integ-tests/cdk-synth-telemetry-with-errors.integtest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as fs from 'fs-extra';
33
import { integTest, withDefaultFixture } from '../../lib';
4+
import { TELEMETRY_ENDPOINT } from './constants';
45

56
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
67

@@ -12,8 +13,9 @@ integTest(
1213
allowErrExit: true,
1314
modEnv: {
1415
INTEG_STACK_SET: 'stage-with-errors',
16+
TELEMETRY_ENDPOINT: TELEMETRY_ENDPOINT,
1517
},
16-
verbose: true, // force trace mode
18+
verboseLevel: 3, // trace mode
1719
});
1820

1921
expect(output).toContain('This is an error');

packages/@aws-cdk-testing/cli-integ/tests/telemetry-integ-tests/cdk-synth-telemetry.integtest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ integTest(
1111

1212
const synthOutput = await fixture.cdk(
1313
['synth', fixture.fullStackName('test-1'), '--unstable=telemetry', `--telemetry-file=${telemetryFile}`],
14-
{ verbose: true }, // force trace mode
14+
{ modEnv: { TELEMETRY_ENDPOINT: 'https://cdk-cli-telemetry.us-east-1.api.aws/metrics' }, verboseLevel: 3 }, // trace mode
1515
);
1616

1717
// Check the trace that telemetry was executed successfully
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const TELEMETRY_ENDPOINT = 'https://cdk-cli-telemetry.us-east-1.api.aws/metrics';

0 commit comments

Comments
 (0)