From 8d0a5238bdb4f63d7259a8ced8392fb0161b0110 Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Sun, 16 Oct 2022 18:30:50 +0300 Subject: [PATCH 1/7] Added parameter to integ-runner CLI to specify a custom run command for the tests. This allows for tests written in other languages than TypeScript to be evaluated. Changed integration test file discovery to work with the naming conventions of all languages supported by CDK. Updated unit tests for integ-runner. --- packages/@aws-cdk/integ-runner/lib/cli.ts | 3 + .../lib/runner/integration-tests.ts | 18 ++- .../integ-runner/lib/runner/runner-base.ts | 13 ++- .../integ-runner/lib/workers/common.ts | 14 +++ .../lib/workers/extract/extract_worker.ts | 3 +- .../lib/workers/integ-test-worker.ts | 1 + .../test/runner/integ-test-runner.test.ts | 103 ++++++++++------ .../test/runner/snapshot-test-runner.test.ts | 36 +++--- .../test/test-data-python/__init__.py | 0 .../test-data-python/integ_python_test.py | 14 +++ ...efaultTestDeployAssertE3E7D2A4.assets.json | 19 +++ ...aultTestDeployAssertE3E7D2A4.template.json | 36 ++++++ .../Stack.assets.json | 19 +++ .../Stack.template.json | 36 ++++++ .../python_test.integ.snapshot/cdk.out | 1 + .../python_test.integ.snapshot/integ.json | 12 ++ .../python_test.integ.snapshot/manifest.json | 105 +++++++++++++++++ .../python_test.integ.snapshot/tree.json | 65 +++++++++++ .../cdk-integ.out.integ-test1/integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- ...xx.integ-test1.ts => integ.integ-test1.ts} | 0 ...xx.integ-test2.ts => integ.integ-test2.ts} | 0 ....ts => integ.test-with-new-assets-diff.ts} | 0 ...ssets.ts => integ.test-with-new-assets.ts} | 0 ...> integ.test-with-snapshot-assets-diff.ts} | 0 ....ts => integ.test-with-snapshot-assets.ts} | 0 ...napshot.ts => integ.test-with-snapshot.ts} | 0 .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../integ.json | 2 +- .../test/workers/integ-worker.test.ts | 110 +++++++++--------- .../test/workers/snapshot-worker.test.ts | 6 +- 38 files changed, 508 insertions(+), 128 deletions(-) create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/__init__.py create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/integ_python_test.py create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.assets.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.template.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/tree.json rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.integ-test1.ts => integ.integ-test1.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.integ-test2.ts => integ.integ-test2.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.test-with-new-assets-diff.ts => integ.test-with-new-assets-diff.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.test-with-new-assets.ts => integ.test-with-new-assets.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.test-with-snapshot-assets-diff.ts => integ.test-with-snapshot-assets-diff.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.test-with-snapshot-assets.ts => integ.test-with-snapshot-assets.ts} (100%) rename packages/@aws-cdk/integ-runner/test/test-data/{xxxxx.test-with-snapshot.ts => integ.test-with-snapshot.ts} (100%) diff --git a/packages/@aws-cdk/integ-runner/lib/cli.ts b/packages/@aws-cdk/integ-runner/lib/cli.ts index 0904ffb96d438..bbcf269e27ba7 100644 --- a/packages/@aws-cdk/integ-runner/lib/cli.ts +++ b/packages/@aws-cdk/integ-runner/lib/cli.ts @@ -30,6 +30,7 @@ async function main() { .options('from-file', { type: 'string', desc: 'Read TEST names from a file (one TEST per line)' }) .option('inspect-failures', { type: 'boolean', desc: 'Keep the integ test cloud assembly if a failure occurs for inspection', default: false }) .option('disable-update-workflow', { type: 'boolean', default: false, desc: 'If this is "true" then the stack update workflow will be disabled' }) + .option('test-run-command', { type: 'string', default: 'node', desc: 'The CLI command (such as python, node, or others) that will be applied to the test files. Defaults to node.' }) .strict() .argv; @@ -76,6 +77,7 @@ async function main() { failedSnapshots = await runSnapshotTests(pool, testsFromArgs, { retain: argv['inspect-failures'], verbose: Boolean(argv.verbose), + runCommand: argv['test-run-command'], }); for (const failure of failedSnapshots) { destructiveChanges.push(...failure.destructiveChanges ?? []); @@ -99,6 +101,7 @@ async function main() { dryRun: argv['dry-run'], verbosity: argv.verbose, updateWorkflow: !argv['disable-update-workflow'], + runCommand: argv['test-run-command'], }); testsSucceeded = success; diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts index 5259a9d0ff85c..0979992c24e87 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts @@ -97,7 +97,7 @@ export class IntegTest { ? parsed.name : path.join(path.relative(this.info.discoveryRoot, parsed.dir), parsed.name); - const nakedTestName = parsed.name.slice(6); // Leave name without 'integ.' and '.ts' + const nakedTestName = IntegrationTests.stripPrefix(parsed.name); // Leave name without 'integ.' and '.ts' this.normalizedTestName = parsed.name; this.snapshotDir = path.join(this.directory, `${nakedTestName}.integ.snapshot`); this.temporaryOutputDir = path.join(this.directory, `${CDK_OUTDIR_PREFIX}.${nakedTestName}`); @@ -146,6 +146,20 @@ export interface IntegrationTestFileConfig { * Discover integration tests */ export class IntegrationTests { + + public static stripPrefix(fileName: string): string { + return fileName.replace(this.acceptedPrefixes, ''); + } + + /** + * Will discover integration tests with naming conventions typical to most languages. Examples: + * - TypeScript/JavaScript: integ.test.ts or integ-test.ts + * - Python: integ_test.py + * - Java/C#: IntegTest.cs + * @private + */ + private static acceptedPrefixes: RegExp = new RegExp('^[iI]nteg[-_.]?'); + constructor(private readonly directory: string) { } @@ -212,7 +226,7 @@ export class IntegrationTests { private async discover(): Promise { const files = await this.readTree(); - const integs = files.filter(fileName => path.basename(fileName).startsWith('integ.') && path.basename(fileName).endsWith('.js')); + const integs = files.filter(fileName => IntegrationTests.acceptedPrefixes.test(path.basename(fileName))); return this.request(integs); } diff --git a/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts b/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts index 9ddaf2e7e4de4..0adaeca581080 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts @@ -49,6 +49,14 @@ export interface IntegRunnerOptions { */ readonly cdk?: ICdk; + /** + * Integration tests don't have a cdk.json to get the run command from. + * You can specify a custom run command, and it will be applied to all test files. + * + * @default - test run command will be `node` + */ + readonly runCommand?: string; + /** * Show output from running integration tests * @@ -150,7 +158,10 @@ export abstract class IntegRunner { }, }); this.cdkOutDir = options.integOutDir ?? this.test.temporaryOutputDir; - this.cdkApp = `node ${path.relative(this.directory, this.test.fileName)}`; + + const testRunCommand = options.runCommand ?? 'node'; + this.cdkApp = `${testRunCommand} ${path.relative(this.directory, this.test.fileName)}`; + this.profile = options.profile; if (this.hasSnapshot()) { this.expectedTestSuite = this.loadManifest(); diff --git a/packages/@aws-cdk/integ-runner/lib/workers/common.ts b/packages/@aws-cdk/integ-runner/lib/workers/common.ts index 7f49cb73b864c..48bdd0e1cde25 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/common.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/common.ts @@ -103,6 +103,13 @@ export interface SnapshotVerificationOptions { * @default false */ readonly verbose?: boolean; + + /** + * The CLI command used to run the test files. + * + * @default - run command will be `node` + */ + readonly runCommand?: string; } /** @@ -162,6 +169,13 @@ export interface IntegTestOptions { * @default true */ readonly updateWorkflow?: boolean; + + /** + * The CLI command used to run the test files. + * + * @default - run command will be `node` + */ + readonly runCommand?: string; } /** diff --git a/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts b/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts index a8166680fb7ba..5e465dcbaf43f 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts @@ -27,6 +27,7 @@ export function integTestWorker(request: IntegTestBatchRequest): IntegTestWorker env: { AWS_REGION: request.region, }, + runCommand: request.runCommand, showOutput: verbosity >= 2, }, testInfo.destructiveChanges); @@ -105,7 +106,7 @@ export function snapshotTestWorker(testInfo: IntegTestInfo, options: SnapshotVer }, 60_000); try { - const runner = new IntegSnapshotRunner({ test }); + const runner = new IntegSnapshotRunner({ test, runCommand: options.runCommand }); if (!runner.hasSnapshot()) { workerpool.workerEmit({ reason: DiagnosticReason.NO_SNAPSHOT, diff --git a/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts b/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts index 77752c029abbb..0b824a0ecff93 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts @@ -135,6 +135,7 @@ export async function runIntegrationTestsInParallel( dryRun: options.dryRun, verbosity: options.verbosity, updateWorkflow: options.updateWorkflow, + runCommand: options.runCommand, }], { on: printResults, }); diff --git a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts index 9fad8eb71a1a9..530364cc254eb 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts @@ -54,12 +54,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot', + testCaseName: 'integ.test-with-snapshot', }); // THEN @@ -82,7 +82,7 @@ describe('IntegTest runIntegTests', () => { stacks: ['test-stack'], }); expect(deployMock).toHaveBeenCalledWith({ - app: 'node xxxxx.test-with-snapshot.js', + app: 'node integ.test-with-snapshot.js', requireApproval: 'never', pathMetadata: false, assetMetadata: false, @@ -99,7 +99,7 @@ describe('IntegTest runIntegTests', () => { stacks: ['test-stack', 'new-test-stack'], }); expect(destroyMock).toHaveBeenCalledWith({ - app: 'node xxxxx.test-with-snapshot.js', + app: 'node integ.test-with-snapshot.js', pathMetadata: false, assetMetadata: false, context: expect.not.objectContaining({ @@ -120,12 +120,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.integ-test1', + testCaseName: 'integ.integ-test1', }); // THEN @@ -133,7 +133,7 @@ describe('IntegTest runIntegTests', () => { expect(destroyMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledTimes(1); expect(deployMock).toHaveBeenCalledWith({ - app: 'node xxxxx.integ-test1.js', + app: 'node integ.integ-test1.js', requireApproval: 'never', pathMetadata: false, assetMetadata: false, @@ -148,7 +148,7 @@ describe('IntegTest runIntegTests', () => { output: 'cdk-integ.out.integ-test1', }); expect(destroyMock).toHaveBeenCalledWith({ - app: 'node xxxxx.integ-test1.js', + app: 'node integ.integ-test1.js', pathMetadata: false, assetMetadata: false, versionReporting: false, @@ -164,12 +164,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot-assets-diff.js', + fileName: 'test/test-data/integ.test-with-snapshot-assets-diff.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot-assets-diff', + testCaseName: 'integ.test-with-snapshot-assets-diff', }); // THEN @@ -177,7 +177,7 @@ describe('IntegTest runIntegTests', () => { expect(destroyMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledTimes(2); expect(deployMock).toHaveBeenCalledWith({ - app: 'node xxxxx.test-with-snapshot-assets-diff.js', + app: 'node integ.test-with-snapshot-assets-diff.js', requireApproval: 'never', pathMetadata: false, assetMetadata: false, @@ -194,7 +194,7 @@ describe('IntegTest runIntegTests', () => { profile: undefined, }); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.test-with-snapshot-assets-diff.js'], + execCmd: ['node', 'integ.test-with-snapshot-assets-diff.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', @@ -203,7 +203,7 @@ describe('IntegTest runIntegTests', () => { output: 'test-with-snapshot-assets-diff.integ.snapshot', }); expect(destroyMock).toHaveBeenCalledWith({ - app: 'node xxxxx.test-with-snapshot-assets-diff.js', + app: 'node integ.test-with-snapshot-assets-diff.js', pathMetadata: false, assetMetadata: false, context: expect.not.objectContaining({ @@ -223,12 +223,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.integ-test1', + testCaseName: 'integ.integ-test1', clean: false, }); @@ -243,12 +243,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.integ-test1', + testCaseName: 'integ.integ-test1', dryRun: true, }); @@ -263,7 +263,7 @@ describe('IntegTest runIntegTests', () => { new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }), }); @@ -271,7 +271,7 @@ describe('IntegTest runIntegTests', () => { // THEN expect(synthFastMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.integ-test1.js'], + execCmd: ['node', 'integ.integ-test1.js'], output: 'cdk-integ.out.integ-test1', env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', @@ -285,13 +285,13 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }), profile: 'test-profile', }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.integ-test1', + testCaseName: 'integ.integ-test1', }); // THEN @@ -299,7 +299,7 @@ describe('IntegTest runIntegTests', () => { expect(destroyMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledTimes(1); expect(deployMock).toHaveBeenCalledWith({ - app: 'node xxxxx.integ-test1.js', + app: 'node integ.integ-test1.js', requireApproval: 'never', pathMetadata: false, assetMetadata: false, @@ -316,7 +316,7 @@ describe('IntegTest runIntegTests', () => { output: 'cdk-integ.out.integ-test1', }); expect(destroyMock).toHaveBeenCalledWith({ - app: 'node xxxxx.integ-test1.js', + app: 'node integ.integ-test1.js', pathMetadata: false, assetMetadata: false, versionReporting: false, @@ -336,12 +336,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot-assets.js', + fileName: 'test/test-data/integ.test-with-snapshot-assets.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot-assets', + testCaseName: 'integ.test-with-snapshot-assets', }); // THEN @@ -383,12 +383,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot', + testCaseName: 'integ.test-with-snapshot', }); // THEN @@ -421,12 +421,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot', + testCaseName: 'integ.test-with-snapshot', }); // THEN @@ -460,12 +460,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot', + testCaseName: 'integ.test-with-snapshot', }); // THEN @@ -480,12 +480,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot-assets.js', + fileName: 'test/test-data/integ.test-with-snapshot-assets.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot-assets', + testCaseName: 'integ.test-with-snapshot-assets', }); expect(removeSyncMock.mock.calls).toEqual([ @@ -501,12 +501,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot-assets-diff.js', + fileName: 'test/test-data/integ.test-with-snapshot-assets-diff.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot-assets-diff', + testCaseName: 'integ.test-with-snapshot-assets-diff', }); expect(removeSyncMock.mock.calls).toEqual([ @@ -530,12 +530,12 @@ describe('IntegTest runIntegTests', () => { const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); integTest.runIntegTestCase({ - testCaseName: 'xxxxx.test-with-snapshot', + testCaseName: 'integ.test-with-snapshot', verbosity: verbosity, }); @@ -553,4 +553,33 @@ describe('IntegTest runIntegTests', () => { debug, })); }); + + test('with custom app run command', () => { + // WHEN + const integTest = new IntegTestRunner({ + cdk: cdkMock.cdk, + test: new IntegTest({ + fileName: 'test/test-data-python/integ_python_test.py', + discoveryRoot: 'test/test-data-python', + }), + runCommand: 'python', + }); + integTest.runIntegTestCase({ + testCaseName: 'integ_python_test', + }); + + // THEN + expect(deployMock).toHaveBeenCalledTimes(1); + expect(destroyMock).toHaveBeenCalledTimes(1); + expect(synthFastMock).toHaveBeenCalledTimes(1); + expect(deployMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'python integ_python_test.py', + })); + expect(synthFastMock).toHaveBeenCalledWith(expect.objectContaining({ + execCmd: ['python', 'integ_python_test.py'], + })); + expect(destroyMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'python integ_python_test.py', + })); + }); }); diff --git a/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts b/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts index 76ae2fb0f0176..c5bb10f222c70 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts @@ -47,7 +47,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/test-with-snapshot.integ.snapshot', @@ -61,7 +61,7 @@ describe('IntegTest runSnapshotTests', () => { CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', }), - execCmd: ['node', 'xxxxx.test-with-snapshot.js'], + execCmd: ['node', 'integ.test-with-snapshot.js'], output: 'test-with-snapshot.integ.snapshot', }); expect(results.diagnostics).toEqual([]); @@ -72,7 +72,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), }); @@ -85,7 +85,7 @@ describe('IntegTest runSnapshotTests', () => { CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', }), - execCmd: ['node', 'xxxxx.test-with-snapshot.js'], + execCmd: ['node', 'integ.test-with-snapshot.js'], output: 'cdk-integ.out.test-with-snapshot', }); expect(results.diagnostics).toEqual(expect.arrayContaining([expect.objectContaining({ @@ -100,7 +100,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/test-with-snapshot-diff.integ.snapshot', @@ -110,7 +110,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(synthFastMock).toHaveBeenCalledTimes(2); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.test-with-snapshot.js'], + execCmd: ['node', 'integ.test-with-snapshot.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', @@ -141,7 +141,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: path.join(__dirname, '../test-data/xxxxx.test-with-new-assets-diff.js'), + fileName: path.join(__dirname, '../test-data/integ.test-with-new-assets-diff.js'), discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/cdk-integ.out.test-with-new-assets', @@ -152,7 +152,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(synthFastMock).toHaveBeenCalledTimes(2); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.test-with-new-assets-diff.js'], + execCmd: ['node', 'integ.test-with-new-assets-diff.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', @@ -166,7 +166,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: path.join(__dirname, '../test-data/xxxxx.test-with-new-assets.js'), + fileName: path.join(__dirname, '../test-data/integ.test-with-new-assets.js'), discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/cdk-integ.out.test-with-new-assets-diff', @@ -186,7 +186,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: path.join(__dirname, '../test-data/xxxxx.test-with-snapshot-assets-diff.js'), + fileName: path.join(__dirname, '../test-data/integ.test-with-snapshot-assets-diff.js'), discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/test-with-snapshot-assets.integ.snapshot', @@ -197,7 +197,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(synthFastMock).toHaveBeenCalledTimes(2); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.test-with-snapshot-assets-diff.js'], + execCmd: ['node', 'integ.test-with-snapshot-assets-diff.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', @@ -211,7 +211,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test', }), integOutDir: 'does/not/exist', @@ -219,7 +219,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(integTest.actualTests()).toEqual(expect.objectContaining({ - 'xxxxx.integ-test1': { + 'integ.integ-test1': { diffAssets: false, stackUpdateWorkflow: true, stacks: ['stack1'], @@ -233,7 +233,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: 'test/test-data/xxxxx.integ-test2.js', + fileName: 'test/test-data/integ.integ-test2.js', discoveryRoot: 'test', }), integOutDir: 'does/not/exist', @@ -241,7 +241,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(integTest.actualTests()).toEqual(expect.objectContaining({ - 'xxxxx.integ-test2': { + 'integ.integ-test2': { diffAssets: false, stackUpdateWorkflow: true, stacks: ['stackabc'], @@ -249,7 +249,7 @@ describe('IntegTest runSnapshotTests', () => { })); expect(synthFastMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.integ-test2.js'], + execCmd: ['node', 'integ.integ-test2.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', @@ -263,7 +263,7 @@ describe('IntegTest runSnapshotTests', () => { const integTest = new IntegSnapshotRunner({ cdk: cdkMock.cdk, test: new IntegTest({ - fileName: path.join(__dirname, '../test-data/xxxxx.test-with-snapshot-assets.js'), + fileName: path.join(__dirname, '../test-data/integ.test-with-snapshot-assets.js'), discoveryRoot: 'test/test-data', }), integOutDir: 'test/test-data/test-with-snapshot-assets-diff.integ.snapshot', @@ -273,7 +273,7 @@ describe('IntegTest runSnapshotTests', () => { // THEN expect(synthFastMock).toHaveBeenCalledTimes(2); expect(synthFastMock).toHaveBeenCalledWith({ - execCmd: ['node', 'xxxxx.test-with-snapshot-assets.js'], + execCmd: ['node', 'integ.test-with-snapshot-assets.js'], env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', CDK_INTEG_REGION: 'test-region', diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/__init__.py b/packages/@aws-cdk/integ-runner/test/test-data-python/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/integ_python_test.py b/packages/@aws-cdk/integ-runner/test/test-data-python/integ_python_test.py new file mode 100644 index 0000000000000..4fe865b5292a0 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/integ_python_test.py @@ -0,0 +1,14 @@ +# To run this and get the snapshot, you need to install: +# pip install aws-cdk-lib aws-cdk.integ-tests-alpha + +from aws_cdk import ( + App, Stack +) +from aws_cdk.integ_tests_alpha import IntegTest + +app = App() +stack = Stack(app, "Stack") + +IntegTest(app, "IntegTest", test_cases=[stack]) + +app.synth() diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json new file mode 100644 index 0000000000000..f1a05d45137d4 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.assets.json new file mode 100644 index 0000000000000..63717fe62a2ec --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "Stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/Stack.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/cdk.out b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/integ.json new file mode 100644 index 0000000000000..0e3cb3d13679a --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "IntegTest/DefaultTest": { + "stacks": [ + "Stack" + ], + "assertionStack": "IntegTest/DefaultTest/DeployAssert", + "assertionStackName": "IntegTestDefaultTestDeployAssertE3E7D2A4" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/manifest.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..83f053d5eadfc --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/manifest.json @@ -0,0 +1,105 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "Stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "Stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "Stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "Stack.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "Stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "Stack.assets" + ], + "metadata": { + "/Stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Stack" + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "metadata": { + "/IntegTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/IntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "IntegTest/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/tree.json b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/tree.json new file mode 100644 index 0000000000000..0fdf573b603a9 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-python/python_test.integ.snapshot/tree.json @@ -0,0 +1,65 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.131" + } + }, + "Stack": { + "id": "Stack", + "path": "Stack", + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.46.0" + } + }, + "IntegTest": { + "id": "IntegTest", + "path": "IntegTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "IntegTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "IntegTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.131" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "IntegTest/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.46.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "2.46.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "2.46.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "2.46.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.integ-test1/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.integ-test1/integ.json index c07eabcac5353..d6c8196db49eb 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.integ-test1/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.integ-test1/integ.json @@ -1,7 +1,7 @@ { "version": "v19.0.0", "testCases": { - "xxxxx.integ-test1": { + "integ.integ-test1": { "stacks": ["stack1"] } } diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets-diff/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets-diff/integ.json index c0acf5e475336..dbdf068fee932 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets-diff/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets-diff/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-new-assets": { + "integ.test-with-new-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": true, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets/integ.json index d8b60d982deca..c37da3991d37b 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-new-assets/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-new-assets": { + "integ.test-with-new-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": false, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot-assets/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot-assets/integ.json index 2cd7ddd429f8a..876a9c0aaa075 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot-assets/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot-assets/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-snapshot-assets": { + "integ.test-with-snapshot-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": false, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot/integ.json index aefc17a9ec3b7..86b02855c4265 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.test-with-snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-snapshot": { + "integ.test-with-snapshot": { "stacks": ["test-stack", "new-test-stack"], "diffAssets": true, "allowDestroy": [ diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.integ-test1.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.integ-test1.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.integ-test1.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.integ-test1.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.integ-test2.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.integ-test2.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.integ-test2.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.integ-test2.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-new-assets-diff.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-new-assets-diff.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-new-assets.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-new-assets.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot-assets-diff.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot-assets-diff.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot-assets-diff.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot-assets-diff.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot-assets.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot-assets.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot-assets.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot-assets.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot.ts b/packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot.ts similarity index 100% rename from packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-snapshot.ts rename to packages/@aws-cdk/integ-runner/test/test-data/integ.test-with-snapshot.ts diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets-diff.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets-diff.integ.snapshot/integ.json index c0acf5e475336..dbdf068fee932 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets-diff.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets-diff.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-new-assets": { + "integ.test-with-new-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": true, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets.integ.snapshot/integ.json index c0acf5e475336..dbdf068fee932 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-new-assets.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-new-assets": { + "integ.test-with-new-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": true, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets-diff.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets-diff.integ.snapshot/integ.json index c602dbd383d72..2fe9f1bc22c06 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets-diff.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets-diff.integ.snapshot/integ.json @@ -2,7 +2,7 @@ "version": "v1.0.0", "testCases": { "enableLookups": true, - "xxxxx.test-with-snapshot-assets-diff": { + "integ.test-with-snapshot-assets-diff": { "stacks": ["test-stack"], "diffAssets": false, "allowDestroy": [ diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets.integ.snapshot/integ.json index 0b72458952056..c9f8b3a3f157a 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-assets.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-snapshot-assets": { + "integ.test-with-snapshot-assets": { "stacks": ["test-stack"], "stackUpdateWorkflow": false, "diffAssets": false, diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-diff.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-diff.integ.snapshot/integ.json index 25baeac5899fd..6938103ade87e 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-diff.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot-diff.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-snapshot": { + "integ.test-with-snapshot": { "stacks": ["test-stack"], "diffAssets": true, "allowDestroy": [ diff --git a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot.integ.snapshot/integ.json index 25baeac5899fd..6938103ade87e 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot.integ.snapshot/integ.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/test-with-snapshot.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "v1.0.0", "testCases": { - "xxxxx.test-with-snapshot": { + "integ.test-with-snapshot": { "stacks": ["test-stack"], "diffAssets": true, "allowDestroy": [ diff --git a/packages/@aws-cdk/integ-runner/test/workers/integ-worker.test.ts b/packages/@aws-cdk/integ-runner/test/workers/integ-worker.test.ts index 8f2e332a639b2..eab088f05275f 100644 --- a/packages/@aws-cdk/integ-runner/test/workers/integ-worker.test.ts +++ b/packages/@aws-cdk/integ-runner/test/workers/integ-worker.test.ts @@ -64,7 +64,7 @@ describe('test runner', () => { test('no snapshot', () => { // WHEN const test = { - fileName: 'test/test-data/xxxxx.integ-test1.js', + fileName: 'test/test-data/integ.integ-test1.js', discoveryRoot: 'test/test-data', }; integTestWorker({ @@ -74,7 +74,7 @@ describe('test runner', () => { expect(spawnSyncMock).toHaveBeenCalledWith( expect.stringMatching(/node/), - ['xxxxx.integ-test1.js'], + ['integ.integ-test1.js'], expect.objectContaining({ env: expect.objectContaining({ CDK_INTEG_ACCOUNT: '12345678', @@ -88,7 +88,7 @@ describe('test runner', () => { // WHEN const test = { - fileName: 'test/test-data/xxxxx.integ-test2.js', + fileName: 'test/test-data/integ.integ-test2.js', discoveryRoot: 'test/test-data', }; spawnSyncMock.mockReset(); @@ -110,14 +110,14 @@ describe('test runner', () => { // THEN expect(results).toEqual([{ discoveryRoot: 'test/test-data', - fileName: 'test/test-data/xxxxx.integ-test2.js', + fileName: 'test/test-data/integ.integ-test2.js', }]); }); test('has snapshot', () => { // WHEN const test = { - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }; const results = integTestWorker({ @@ -155,7 +155,7 @@ describe('test runner', () => { test('deploy failed', () => { // WHEN const test = { - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }; jest.spyOn(child_process, 'spawnSync').mockReturnValue({ @@ -172,7 +172,7 @@ describe('test runner', () => { }); expect(results[0]).toEqual({ - fileName: 'test/test-data/xxxxx.test-with-snapshot.js', + fileName: 'test/test-data/integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }); }); @@ -182,11 +182,11 @@ describe('parallel worker', () => { test('run all integration tests', async () => { const tests = [ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]; @@ -203,16 +203,16 @@ describe('parallel worker', () => { 'Running in parallel across regions: us-east-1, us-east-2', ); expect(stderrMock.mock.calls[2][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot.js in us-east-1', + 'Running test integ.another-test-with-snapshot.js in us-east-1', ); expect(stderrMock.mock.calls[3][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in us-east-2', + 'Running test integ.test-with-snapshot.js in us-east-2', ); }); test('run tests', async () => { const tests = [{ - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }]; const results = await runIntegrationTestsInParallel({ @@ -222,12 +222,12 @@ describe('parallel worker', () => { }); expect(stderrMock.mock.calls[0][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in us-east-1', + 'Running test integ.test-with-snapshot.js in us-east-1', ); expect(results).toEqual({ failedTests: expect.arrayContaining([ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]), @@ -236,7 +236,7 @@ describe('parallel worker', () => { duration: expect.anything(), region: 'us-east-1', tests: { - 'xxxxx.test-with-snapshot.js': expect.anything(), + 'integ.test-with-snapshot.js': expect.anything(), }, }, ]), @@ -246,19 +246,19 @@ describe('parallel worker', () => { test('run multiple tests with profiles', async () => { const tests = [ { - fileName: 'xxxxx.another-test-with-snapshot3.js', + fileName: 'integ.another-test-with-snapshot3.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot2.js', + fileName: 'integ.another-test-with-snapshot2.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]; @@ -270,33 +270,33 @@ describe('parallel worker', () => { }); expect(stderrMock.mock.calls[3][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot3.js in profile2/us-east-2', + 'Running test integ.another-test-with-snapshot3.js in profile2/us-east-2', ); expect(stderrMock.mock.calls[2][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot2.js in profile2/us-east-1', + 'Running test integ.another-test-with-snapshot2.js in profile2/us-east-1', ); expect(stderrMock.mock.calls[1][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot.js in profile1/us-east-2', + 'Running test integ.another-test-with-snapshot.js in profile1/us-east-2', ); expect(stderrMock.mock.calls[0][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in profile1/us-east-1', + 'Running test integ.test-with-snapshot.js in profile1/us-east-1', ); expect(results).toEqual({ failedTests: expect.arrayContaining([ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot2.js', + fileName: 'integ.another-test-with-snapshot2.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot3.js', + fileName: 'integ.another-test-with-snapshot3.js', discoveryRoot: 'test/test-data', }, ]), @@ -306,7 +306,7 @@ describe('parallel worker', () => { region: 'us-east-1', profile: 'profile1', tests: { - 'xxxxx.test-with-snapshot.js': expect.any(Number), + 'integ.test-with-snapshot.js': expect.any(Number), }, }, { @@ -314,7 +314,7 @@ describe('parallel worker', () => { region: 'us-east-2', profile: 'profile1', tests: { - 'xxxxx.another-test-with-snapshot.js': expect.any(Number), + 'integ.another-test-with-snapshot.js': expect.any(Number), }, }, { @@ -322,7 +322,7 @@ describe('parallel worker', () => { region: 'us-east-1', profile: 'profile2', tests: { - 'xxxxx.another-test-with-snapshot2.js': expect.any(Number), + 'integ.another-test-with-snapshot2.js': expect.any(Number), }, }, { @@ -330,7 +330,7 @@ describe('parallel worker', () => { region: 'us-east-2', profile: 'profile2', tests: { - 'xxxxx.another-test-with-snapshot3.js': expect.any(Number), + 'integ.another-test-with-snapshot3.js': expect.any(Number), }, }, ]), @@ -340,11 +340,11 @@ describe('parallel worker', () => { test('run multiple tests', async () => { const tests = [ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]; @@ -355,19 +355,19 @@ describe('parallel worker', () => { }); expect(stderrMock.mock.calls[1][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in us-east-2', + 'Running test integ.test-with-snapshot.js in us-east-2', ); expect(stderrMock.mock.calls[0][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot.js in us-east-1', + 'Running test integ.another-test-with-snapshot.js in us-east-1', ); expect(results).toEqual({ failedTests: expect.arrayContaining([ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]), @@ -376,14 +376,14 @@ describe('parallel worker', () => { duration: expect.anything(), region: 'us-east-2', tests: { - 'xxxxx.test-with-snapshot.js': expect.anything(), + 'integ.test-with-snapshot.js': expect.anything(), }, }, { duration: expect.anything(), region: 'us-east-1', tests: { - 'xxxxx.another-test-with-snapshot.js': expect.anything(), + 'integ.another-test-with-snapshot.js': expect.anything(), }, }, ]), @@ -393,11 +393,11 @@ describe('parallel worker', () => { test('more tests than regions', async () => { const tests = [ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]; @@ -408,19 +408,19 @@ describe('parallel worker', () => { }); expect(stderrMock.mock.calls[1][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in us-east-1', + 'Running test integ.test-with-snapshot.js in us-east-1', ); expect(stderrMock.mock.calls[0][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot.js in us-east-1', + 'Running test integ.another-test-with-snapshot.js in us-east-1', ); expect(results).toEqual({ failedTests: expect.arrayContaining([ { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]), @@ -429,8 +429,8 @@ describe('parallel worker', () => { duration: expect.anything(), region: 'us-east-1', tests: { - 'xxxxx.test-with-snapshot.js': expect.anything(), - 'xxxxx.another-test-with-snapshot.js': expect.anything(), + 'integ.test-with-snapshot.js': expect.anything(), + 'integ.another-test-with-snapshot.js': expect.anything(), }, }, ]), @@ -440,11 +440,11 @@ describe('parallel worker', () => { test('more regions than tests', async () => { const tests = [ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]; @@ -455,19 +455,19 @@ describe('parallel worker', () => { }); expect(stderrMock.mock.calls[1][0]).toContain( - 'Running test xxxxx.test-with-snapshot.js in us-east-2', + 'Running test integ.test-with-snapshot.js in us-east-2', ); expect(stderrMock.mock.calls[0][0]).toContain( - 'Running test xxxxx.another-test-with-snapshot.js in us-east-1', + 'Running test integ.another-test-with-snapshot.js in us-east-1', ); expect(results).toEqual({ failedTests: expect.arrayContaining([ { - fileName: 'xxxxx.test-with-snapshot.js', + fileName: 'integ.test-with-snapshot.js', discoveryRoot: 'test/test-data', }, { - fileName: 'xxxxx.another-test-with-snapshot.js', + fileName: 'integ.another-test-with-snapshot.js', discoveryRoot: 'test/test-data', }, ]), @@ -476,14 +476,14 @@ describe('parallel worker', () => { duration: expect.anything(), region: 'us-east-2', tests: { - 'xxxxx.test-with-snapshot.js': expect.anything(), + 'integ.test-with-snapshot.js': expect.anything(), }, }, { duration: expect.anything(), region: 'us-east-1', tests: { - 'xxxxx.another-test-with-snapshot.js': expect.anything(), + 'integ.another-test-with-snapshot.js': expect.anything(), }, }, ]), diff --git a/packages/@aws-cdk/integ-runner/test/workers/snapshot-worker.test.ts b/packages/@aws-cdk/integ-runner/test/workers/snapshot-worker.test.ts index 015b53861b622..9bf1120365770 100644 --- a/packages/@aws-cdk/integ-runner/test/workers/snapshot-worker.test.ts +++ b/packages/@aws-cdk/integ-runner/test/workers/snapshot-worker.test.ts @@ -21,7 +21,7 @@ describe('Snapshot tests', () => { test('no snapshot', () => { // WHEN const test = { - fileName: path.join(directory, 'xxxxx.integ-test1.js'), + fileName: path.join(directory, 'integ.integ-test1.js'), discoveryRoot: directory, }; const result = snapshotTestWorker(test); @@ -35,7 +35,7 @@ describe('Snapshot tests', () => { // WHEN jest.spyOn(child_process, 'spawnSync').mockResolvedValue; const test = { - fileName: path.join(directory, 'xxxxx.test-with-snapshot.js'), + fileName: path.join(directory, 'integ.test-with-snapshot.js'), discoveryRoot: directory, }; const result = snapshotTestWorker(test); @@ -48,7 +48,7 @@ describe('Snapshot tests', () => { // WHEN jest.spyOn(child_process, 'spawnSync').mockRejectedValue; const test = { - fileName: path.join(directory, 'xxxxx.test-with-snapshot-assets-diff.js'), + fileName: path.join(directory, 'integ.test-with-snapshot-assets-diff.js'), discoveryRoot: directory, destructiveChanges: [], }; From 574581f5adf1658480b6d9f7c432302d229c7c66 Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Sun, 16 Oct 2022 18:40:18 +0300 Subject: [PATCH 2/7] Updated README.md --- packages/@aws-cdk/integ-runner/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@aws-cdk/integ-runner/README.md b/packages/@aws-cdk/integ-runner/README.md index ef4b44c16f965..94a281e46486c 100644 --- a/packages/@aws-cdk/integ-runner/README.md +++ b/packages/@aws-cdk/integ-runner/README.md @@ -68,6 +68,8 @@ to be a self contained CDK app. The runner will execute the following for each f Read the list of tests from this file - `--disable-update-workflow` (default=`false`) If this is set to `true` then the [update workflow](#update-workflow) will be disabled +- `--test-run-command` (default=`node`) + The command used by the test runner to synth the test files. This will depend on the language the tests are written in. For example, if the tests are written in Python, you could set this parameter to 'python', 'python3' or 'python3.8'. Example: From 5359a18996c6bc4f18bcafb59d420e780ba79979 Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:39:04 +0300 Subject: [PATCH 3/7] Added a list of valid file extensions for the test discovery. --- .../@aws-cdk/integ-runner/lib/runner/integration-tests.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts index 0979992c24e87..3c020f763f894 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts @@ -160,6 +160,8 @@ export class IntegrationTests { */ private static acceptedPrefixes: RegExp = new RegExp('^[iI]nteg[-_.]?'); + private static acceptedSuffixes: RegExp = new RegExp('\\.(py|js|cs|go|java)$'); + constructor(private readonly directory: string) { } @@ -226,7 +228,9 @@ export class IntegrationTests { private async discover(): Promise { const files = await this.readTree(); - const integs = files.filter(fileName => IntegrationTests.acceptedPrefixes.test(path.basename(fileName))); + const integs = files.filter(fileName => ( + IntegrationTests.acceptedPrefixes.test(path.basename(fileName)) && + IntegrationTests.acceptedSuffixes.test(path.basename(fileName)))); return this.request(integs); } From 4a16192322c5f2e4e0308fb7f5001b6d5912291e Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Sun, 16 Oct 2022 21:26:58 +0300 Subject: [PATCH 4/7] Using a single regex to validate prefixes for tests in all languages was problematic and broke some existing tests (unit tests in TS named integration-tests.ts for example). Changed to use a different regex pattern to discover tests with different extensions. --- .../lib/runner/integration-tests.ts | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts index 3c020f763f894..53bd7b0569d67 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts @@ -97,7 +97,7 @@ export class IntegTest { ? parsed.name : path.join(path.relative(this.info.discoveryRoot, parsed.dir), parsed.name); - const nakedTestName = IntegrationTests.stripPrefix(parsed.name); // Leave name without 'integ.' and '.ts' + const nakedTestName = IntegrationTests.stripPrefixAndSuffix(parsed.base); // Leave name without 'integ.' and '.ts' this.normalizedTestName = parsed.name; this.snapshotDir = path.join(this.directory, `${nakedTestName}.integ.snapshot`); this.temporaryOutputDir = path.join(this.directory, `${CDK_OUTDIR_PREFIX}.${nakedTestName}`); @@ -147,20 +147,30 @@ export interface IntegrationTestFileConfig { */ export class IntegrationTests { - public static stripPrefix(fileName: string): string { - return fileName.replace(this.acceptedPrefixes, ''); + public static stripPrefixAndSuffix(fileName: string): string { + const [suffix, prefix] = Array.from(this.acceptedSuffixPrefixMapping) + .find(([suff]) => suff.test(fileName)) ?? ['', '']; + + return fileName.replace(prefix, '').replace(suffix, ''); } /** - * Will discover integration tests with naming conventions typical to most languages. Examples: - * - TypeScript/JavaScript: integ.test.ts or integ-test.ts - * - Python: integ_test.py + * Will discover integration tests with naming conventions typical to each language. Examples: + * - TypeScript/JavaScript: integ.test.ts or integ-test.ts or integ_test.ts + * - Python/Go: integ_test.py * - Java/C#: IntegTest.cs * @private */ - private static acceptedPrefixes: RegExp = new RegExp('^[iI]nteg[-_.]?'); - - private static acceptedSuffixes: RegExp = new RegExp('\\.(py|js|cs|go|java)$'); + private static acceptedSuffixPrefixMapping: Map = new Map([ + [new RegExp('\\.(cs|java)$'), new RegExp('^Integ')], + [new RegExp('\\.(py|go)$'), new RegExp('^integ_')], + [new RegExp('\\.(js)$'), new RegExp('^integ[-_.]')], + ]); + + private static hasValidPrefixSuffix(fileName: string): boolean { + return Array.from(this.acceptedSuffixPrefixMapping) + .some(([suffix, prefix]) => suffix.test(fileName) && prefix.test(fileName)); + } constructor(private readonly directory: string) { } @@ -228,9 +238,7 @@ export class IntegrationTests { private async discover(): Promise { const files = await this.readTree(); - const integs = files.filter(fileName => ( - IntegrationTests.acceptedPrefixes.test(path.basename(fileName)) && - IntegrationTests.acceptedSuffixes.test(path.basename(fileName)))); + const integs = files.filter(fileName => IntegrationTests.hasValidPrefixSuffix(path.basename(fileName))); return this.request(integs); } From fa8a56e87ac3a72ce33408dae9a745329a09786d Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:34:25 +0300 Subject: [PATCH 5/7] Added test for Java IntegTest execution. --- .../test/runner/integ-test-runner.test.ts | 31 +++++- .../integ-runner/test/test-data-java/pom.xml | 37 ++++++ .../main/java/com/myorg/IntegTestJava.java | 29 +++++ ...efaultTestDeployAssert4E6713E1.assets.json | 19 ++++ ...aultTestDeployAssert4E6713E1.template.json | 36 ++++++ .../TestJava.integ.snapshot/Stack.assets.json | 19 ++++ .../Stack.template.json | 36 ++++++ .../com/myorg/TestJava.integ.snapshot/cdk.out | 1 + .../myorg/TestJava.integ.snapshot/integ.json | 12 ++ .../TestJava.integ.snapshot/manifest.json | 105 ++++++++++++++++++ .../myorg/TestJava.integ.snapshot/tree.json | 65 +++++++++++ 11 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/IntegTestJava.java create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.assets.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.template.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/tree.json diff --git a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts index 530364cc254eb..0df88c1bb23bc 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts @@ -554,7 +554,7 @@ describe('IntegTest runIntegTests', () => { })); }); - test('with custom app run command', () => { + test('with custom app run command for Python', () => { // WHEN const integTest = new IntegTestRunner({ cdk: cdkMock.cdk, @@ -582,4 +582,33 @@ describe('IntegTest runIntegTests', () => { app: 'python integ_python_test.py', })); }); + + test('with custom app run command for Java', () => { + // WHEN + const integTest = new IntegTestRunner({ + cdk: cdkMock.cdk, + test: new IntegTest({ + fileName: 'test/test-data-java/src/main/java/com/myorg/IntegTestJava.java', + discoveryRoot: 'test/test-data-java/src/main/java/com/myorg', + }), + runCommand: 'java -cp $CLASSPATH', + }); + integTest.runIntegTestCase({ + testCaseName: 'IntegTestJava', + }); + + // THEN + expect(deployMock).toHaveBeenCalledTimes(1); + expect(destroyMock).toHaveBeenCalledTimes(1); + expect(synthFastMock).toHaveBeenCalledTimes(1); + expect(deployMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'java -cp $CLASSPATH IntegTestJava.java', + })); + expect(synthFastMock).toHaveBeenCalledWith(expect.objectContaining({ + execCmd: ['java', '-cp', '$CLASSPATH', 'IntegTestJava.java'], + })); + expect(destroyMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'java -cp $CLASSPATH IntegTestJava.java', + })); + }); }); diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml b/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml new file mode 100644 index 0000000000000..e83f92d58d24a --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + com.myorg + test-data-java + 0.1 + + + UTF-8 + [2.0.0,3.0.0) + [2.0.0-alpha.0,3.0.0-alpha.0) + [10.0.0,11.0.0) + + + + + + software.amazon.awscdk + aws-cdk-lib + ${cdk.version} + + + + software.amazon.awscdk + cdk-integ-tests-alpha + ${cdk-integ-tests.version} + + + + software.constructs + constructs + ${constructs.version} + + + diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/IntegTestJava.java b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/IntegTestJava.java new file mode 100644 index 0000000000000..46c0a3a640e2e --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/IntegTestJava.java @@ -0,0 +1,29 @@ +/** +To run this and get the snapshot, you need to: +- install the dependencies from pom.xml by running `mvn dependency:resolve` in the test-data-java directory +- set the Java classpath for the module's dependencies and provide a command that can execute each test in the + package separately: + `export $CLASSPATH="$(cd test/test-data-java; mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout)"; node bin/integ-runner --directory test/test-data-java/src/main/java/com/myorg --update-on-failed --dry-run --test-run-command="java -cp $CLASSPATH"` +**/ +package com.myorg; + +import software.amazon.awscdk.App; +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.Environment; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.integtests.alpha.IntegTest; + +import java.util.List; + + +public class IntegTestJava { + public static void main(final String[] args) { + App app = new App(); + + Stack stack = new Stack(app, "Stack", StackProps.builder().build()); + + IntegTest.Builder.create(app, "Integ").testCases(List.of(stack)).build(); + + app.synth(); + } +} diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json new file mode 100644 index 0000000000000..1c86a68a43509 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "IntegDefaultTestDeployAssert4E6713E1.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.assets.json new file mode 100644 index 0000000000000..63717fe62a2ec --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "Stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/Stack.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/cdk.out b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/integ.json new file mode 100644 index 0000000000000..2fb51e2403590 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "Integ/DefaultTest": { + "stacks": [ + "Stack" + ], + "assertionStack": "Integ/DefaultTest/DeployAssert", + "assertionStackName": "IntegDefaultTestDeployAssert4E6713E1" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/manifest.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..b1760a6bb8429 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/manifest.json @@ -0,0 +1,105 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "Stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "Stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "Stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "Stack.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "Stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "Stack.assets" + ], + "metadata": { + "/Stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Stack" + }, + "IntegDefaultTestDeployAssert4E6713E1.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IntegDefaultTestDeployAssert4E6713E1.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IntegDefaultTestDeployAssert4E6713E1": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IntegDefaultTestDeployAssert4E6713E1.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IntegDefaultTestDeployAssert4E6713E1.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IntegDefaultTestDeployAssert4E6713E1.assets" + ], + "metadata": { + "/Integ/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Integ/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Integ/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/tree.json b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/tree.json new file mode 100644 index 0000000000000..66b65338d47b8 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/src/main/java/com/myorg/TestJava.integ.snapshot/tree.json @@ -0,0 +1,65 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.131" + } + }, + "Stack": { + "id": "Stack", + "path": "Stack", + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.46.0" + } + }, + "Integ": { + "id": "Integ", + "path": "Integ", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "Integ/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "Integ/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.131" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "Integ/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.46.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "2.46.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "2.46.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "2.46.0" + } + } +} \ No newline at end of file From 4d211590cfe4ed6c75750bb00b554629ad21b802 Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Tue, 18 Oct 2022 15:29:17 +0300 Subject: [PATCH 6/7] Added more customizability options to the integ-runner CLI Now implements default run commands for all languages. Implemented different matching patterns for different file extensions. Now filters out duplicate test names, and makes sure to give precedence to .ts files over their compiled .js files. Java default Maven run command is now inferred from the directory structure of the Java project. The classpath for each individual test will automatically be discovered, together with the closest pom.xml file in the project hierarchy. --- packages/@aws-cdk/integ-runner/lib/cli.ts | 15 ++- .../lib/runner/integration-tests.ts | 107 ++++++++++++++---- .../integ-runner/lib/runner/runner-base.ts | 58 +++++++++- .../integ-runner/lib/workers/common.ts | 8 +- .../lib/workers/extract/extract_worker.ts | 4 +- .../lib/workers/integ-test-worker.ts | 2 +- .../test/runner/integ-test-runner.test.ts | 54 ++++++++- .../test/runner/integration-tests.test.ts | 65 ++++++++++- .../integ-runner/test/test-data-java/pom.xml | 20 ++++ packages/aws-cdk/lib/index.ts | 1 + packages/aws-cdk/lib/init.ts | 2 +- 11 files changed, 291 insertions(+), 45 deletions(-) diff --git a/packages/@aws-cdk/integ-runner/lib/cli.ts b/packages/@aws-cdk/integ-runner/lib/cli.ts index bbcf269e27ba7..197e40f90b0ef 100644 --- a/packages/@aws-cdk/integ-runner/lib/cli.ts +++ b/packages/@aws-cdk/integ-runner/lib/cli.ts @@ -30,10 +30,14 @@ async function main() { .options('from-file', { type: 'string', desc: 'Read TEST names from a file (one TEST per line)' }) .option('inspect-failures', { type: 'boolean', desc: 'Keep the integ test cloud assembly if a failure occurs for inspection', default: false }) .option('disable-update-workflow', { type: 'boolean', default: false, desc: 'If this is "true" then the stack update workflow will be disabled' }) - .option('test-run-command', { type: 'string', default: 'node', desc: 'The CLI command (such as python, node, or others) that will be applied to the test files. Defaults to node.' }) + .option('app', { type: 'string', default: undefined, desc: 'The custom CLI command that will be used to run the test files. You can include {filePath} to specify where in the command the test file name should be inserted. Example: --app="python3.8 {filePath}"' }) + .option('language', { type: 'array', default: ['csharp', 'fsharp', 'go', 'java', 'javascript', 'python', 'typescript'], desc: 'The languages that tests will search for. Defaults to all languages supported by CDK.' }) + .option('test-regex', { type: 'string', default: undefined, desc: 'A custom pattern in the JS RegExp format to match integration test file prefixes.' }) .strict() .argv; + const customRegex = argv['test-regex'] ? new RegExp(argv['test-regex']) : undefined; + const pool = workerpool.pool(path.join(__dirname, '../lib/workers/extract/index.js'), { maxWorkers: argv['max-workers'], }); @@ -57,7 +61,7 @@ async function main() { let testsSucceeded = false; try { if (argv.list) { - const tests = await new IntegrationTests(argv.directory).fromCliArgs(); + const tests = await new IntegrationTests(argv.directory, customRegex, argv.language).fromCliArgs(); process.stdout.write(tests.map(t => t.discoveryRelativeFileName).join('\n') + '\n'); return; } @@ -69,7 +73,8 @@ async function main() { ? (await fs.readFile(fromFile, { encoding: 'utf8' })).split('\n').filter(x => x) : (argv._.length > 0 ? argv._ : undefined); // 'undefined' means no request - testsFromArgs.push(...(await new IntegrationTests(path.resolve(argv.directory)).fromCliArgs(requestedTests, exclude))); + testsFromArgs.push(...(await new IntegrationTests(path.resolve(argv.directory), customRegex, argv.language) + .fromCliArgs(requestedTests, exclude))); // always run snapshot tests, but if '--force' is passed then // run integration tests on all failed tests, not just those that @@ -77,7 +82,7 @@ async function main() { failedSnapshots = await runSnapshotTests(pool, testsFromArgs, { retain: argv['inspect-failures'], verbose: Boolean(argv.verbose), - runCommand: argv['test-run-command'], + appCommand: argv.app, }); for (const failure of failedSnapshots) { destructiveChanges.push(...failure.destructiveChanges ?? []); @@ -101,7 +106,7 @@ async function main() { dryRun: argv['dry-run'], verbosity: argv.verbose, updateWorkflow: !argv['disable-update-workflow'], - runCommand: argv['test-run-command'], + appCommand: argv.app, }); testsSucceeded = success; diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts index 53bd7b0569d67..a970ee1603904 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts @@ -79,6 +79,11 @@ export class IntegTest { */ public readonly temporaryOutputDir: string; + /** + * Language the test is written in + */ + public readonly language: string; + constructor(public readonly info: IntegTestInfo) { this.absoluteFileName = path.resolve(info.fileName); this.fileName = path.relative(process.cwd(), info.fileName); @@ -97,10 +102,16 @@ export class IntegTest { ? parsed.name : path.join(path.relative(this.info.discoveryRoot, parsed.dir), parsed.name); - const nakedTestName = IntegrationTests.stripPrefixAndSuffix(parsed.base); // Leave name without 'integ.' and '.ts' + const nakedTestName = new IntegrationTests(this.directory).stripPrefixAndSuffix(parsed.base); // Leave name without 'integ.' and '.ts' this.normalizedTestName = parsed.name; this.snapshotDir = path.join(this.directory, `${nakedTestName}.integ.snapshot`); this.temporaryOutputDir = path.join(this.directory, `${CDK_OUTDIR_PREFIX}.${nakedTestName}`); + + const language = new IntegrationTests(this.directory).getLanguage(parsed.base); + if (!language) { + throw new Error('Given file does not match any of the allowed languages for this test'); + } + this.language = language; } /** @@ -146,14 +157,6 @@ export interface IntegrationTestFileConfig { * Discover integration tests */ export class IntegrationTests { - - public static stripPrefixAndSuffix(fileName: string): string { - const [suffix, prefix] = Array.from(this.acceptedSuffixPrefixMapping) - .find(([suff]) => suff.test(fileName)) ?? ['', '']; - - return fileName.replace(prefix, '').replace(suffix, ''); - } - /** * Will discover integration tests with naming conventions typical to each language. Examples: * - TypeScript/JavaScript: integ.test.ts or integ-test.ts or integ_test.ts @@ -161,18 +164,68 @@ export class IntegrationTests { * - Java/C#: IntegTest.cs * @private */ - private static acceptedSuffixPrefixMapping: Map = new Map([ - [new RegExp('\\.(cs|java)$'), new RegExp('^Integ')], - [new RegExp('\\.(py|go)$'), new RegExp('^integ_')], - [new RegExp('\\.(js)$'), new RegExp('^integ[-_.]')], + private readonly prefixMapping: Map = new Map([ + ['csharp', new RegExp(/^Integ/)], + ['fsharp', new RegExp(/^Integ/)], + ['go', new RegExp(/^integ_/)], + ['java', new RegExp(/^Integ/)], + ['javascript', new RegExp(/^integ\./)], + ['python', new RegExp(/^integ_/)], + ['typescript', new RegExp(/^integ\./)], + ]); + private readonly suffixMapping: Map = new Map([ + ['csharp', new RegExp(/\.cs$/)], + ['fsharp', new RegExp(/\.fs$/)], + ['go', new RegExp(/\.go$/)], + ['java', new RegExp(/\.java$/)], + ['javascript', new RegExp(/\.js$/)], + ['python', new RegExp(/\.py$/)], + // Allow files ending in .ts but not in .d.ts + ['typescript', new RegExp(/(? suffix.test(fileName) && prefix.test(fileName)); + constructor(private readonly directory: string, customPrefix?: RegExp, allowedLanguages?: Array) { + if (customPrefix) { + for (const language of this.prefixMapping.keys()) { + this.prefixMapping.set(language, customPrefix); + } + } + if (allowedLanguages) { + const disallowedLanguages = Array.from(this.prefixMapping.keys()).filter((language) => !allowedLanguages.includes(language)); + for (const disallowedLanguage of disallowedLanguages) { + this.prefixMapping.delete(disallowedLanguage); + this.suffixMapping.delete(disallowedLanguage); + } + } } - constructor(private readonly directory: string) { + public stripPrefixAndSuffix(fileName: string): string { + const language = this.getLanguage(fileName); + if (!language) { + return fileName; + } + + const suffix = this.suffixMapping.get(language) ?? ''; + const prefix = this.prefixMapping.get(language) ?? ''; + + return fileName.replace(prefix, '').replace(suffix, ''); + } + + private hasValidPrefixSuffix(fileName: string): boolean { + const language = this.getLanguage(fileName); + if (!language) { + return false; + } + + const suffix = this.suffixMapping.get(language); + const prefix = this.prefixMapping.get(language); + + return (suffix?.test(fileName) && prefix?.test(fileName)); + } + + public getLanguage(fileName: string): string | undefined { + const [language] = Array.from(this.suffixMapping.entries()).find(([, regex]) => regex.test(fileName)) ?? [undefined, undefined]; + return language; } /** @@ -238,8 +291,24 @@ export class IntegrationTests { private async discover(): Promise { const files = await this.readTree(); - const integs = files.filter(fileName => IntegrationTests.hasValidPrefixSuffix(path.basename(fileName))); - return this.request(integs); + const integs = files.filter(fileName => this.hasValidPrefixSuffix(path.basename(fileName))); + + const discoveredTestNames = new Set(); + const integsWithoutDuplicates = new Array(); + + // Remove duplicate test names that would just overwrite each other's snapshots anyway. + // To make sure the precendence of files is deterministic, iterate the files in lexicographic order. + // Additionally, to give precedence to .ts files over their compiled .js version, + // use descending lexicographic ordering, so the .ts files are picked up first. + for (const integFileName of integs.sort().reverse()) { + const testName = this.stripPrefixAndSuffix(path.basename(integFileName)); + if (!discoveredTestNames.has(testName)) { + integsWithoutDuplicates.push(integFileName); + } + discoveredTestNames.add(testName); + } + + return this.request(integsWithoutDuplicates); } private request(files: string[]): IntegTest[] { diff --git a/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts b/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts index 0adaeca581080..1e725f86d1964 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import { TestCase, DefaultCdkOptions } from '@aws-cdk/cloud-assembly-schema'; import { AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY, FUTURE_FLAGS, TARGET_PARTITIONS, FUTURE_FLAGS_EXPIRED } from '@aws-cdk/cx-api'; +import { pythonExecutable } from 'aws-cdk/lib/init'; import { CdkCliWrapper, ICdk } from 'cdk-cli-wrapper'; import * as fs from 'fs-extra'; import { flatten } from '../utils'; @@ -50,12 +51,12 @@ export interface IntegRunnerOptions { readonly cdk?: ICdk; /** - * Integration tests don't have a cdk.json to get the run command from. * You can specify a custom run command, and it will be applied to all test files. + * If it contains {filePath}, the test file names will be substituted at that place in the command for each run. * * @default - test run command will be `node` */ - readonly runCommand?: string; + readonly appCommand?: string; /** * Show output from running integration tests @@ -72,6 +73,41 @@ export interface IntegRunnerOptions { * Represents an Integration test runner */ export abstract class IntegRunner { + + // Best-effort reconstruction of the classpath of the file in the project. + // Example: /absolute/file/path/src/main/java/com/myorg/IntegTest.java -> com.myorg.IntegTest + // Should work for standard Java project layouts. + private static getJavaClassPath(absoluteFilePath: string): string | undefined { + const packagePath = absoluteFilePath.split('/java/').slice(-1)[0]; + if (!packagePath) { + return undefined; + } + // string.replaceAll isn't available in the TS version the project uses + return packagePath.split('/').join('.').replace('.java', ''); + } + // Will find the closest pom.xml file in the directory structure for this file + private static getJavaPomPath(executionDirectoryPath: string): string | undefined { + // Will generate the full list of ancestors in the directory path + // Example: ['/', '/home', '/home/MyUser', '/home/MyUser/Desktop'] + const dirHierarchy = executionDirectoryPath + .split(path.sep) + .filter(dirName => dirName !== '') + .reduce((hierarchy, segment) => { + hierarchy.push(path.join(hierarchy[hierarchy.length - 1], segment)); + return hierarchy; + }, + // For Windows support + [path.toNamespacedPath('/')]); + + for (const parentDir of dirHierarchy.reverse()) { + const searchPath = path.join(parentDir, 'pom.xml'); + if (fs.existsSync(searchPath)) { + return path.relative(executionDirectoryPath, searchPath); + } + } + return undefined; + } + /** * The directory where the snapshot will be stored */ @@ -159,8 +195,22 @@ export abstract class IntegRunner { }); this.cdkOutDir = options.integOutDir ?? this.test.temporaryOutputDir; - const testRunCommand = options.runCommand ?? 'node'; - this.cdkApp = `${testRunCommand} ${path.relative(this.directory, this.test.fileName)}`; + const defaultAppCommands = new Map([ + ['javascript', 'node {filePath}'], + ['typescript', 'node -r ts-node/register {filePath}'], + ['python', `${pythonExecutable()} {filePath}`], + ['go', 'go mod download && go run {filePath}'], + ['csharp', 'dotnet run {filePath}'], + ['fsharp', 'dotnet run {filePath}'], + ['java', `mvn -f ${IntegRunner.getJavaPomPath(path.dirname(options.test.absoluteFileName))} -e -q compile exec:java clean -Dexec.mainClass=${IntegRunner.getJavaClassPath(options.test.absoluteFileName)}`], + ]); + const testRunCommand = options.appCommand ?? defaultAppCommands.get(this.test.language); + + if (!testRunCommand) { + throw new Error('Could not find default run command for this file extension. Try specifying a custom one with the --app flag.'); + } + + this.cdkApp = testRunCommand.replace('{filePath}', path.relative(this.directory, this.test.fileName)); this.profile = options.profile; if (this.hasSnapshot()) { diff --git a/packages/@aws-cdk/integ-runner/lib/workers/common.ts b/packages/@aws-cdk/integ-runner/lib/workers/common.ts index 48bdd0e1cde25..342c32c3d2f86 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/common.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/common.ts @@ -107,9 +107,9 @@ export interface SnapshotVerificationOptions { /** * The CLI command used to run the test files. * - * @default - run command will be `node` + * @default - based on language of each file */ - readonly runCommand?: string; + readonly appCommand?: string; } /** @@ -173,9 +173,9 @@ export interface IntegTestOptions { /** * The CLI command used to run the test files. * - * @default - run command will be `node` + * @default - based on language of each file */ - readonly runCommand?: string; + readonly appCommand?: string; } /** diff --git a/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts b/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts index 5e465dcbaf43f..047e03463efdf 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts @@ -27,7 +27,7 @@ export function integTestWorker(request: IntegTestBatchRequest): IntegTestWorker env: { AWS_REGION: request.region, }, - runCommand: request.runCommand, + appCommand: request.appCommand, showOutput: verbosity >= 2, }, testInfo.destructiveChanges); @@ -106,7 +106,7 @@ export function snapshotTestWorker(testInfo: IntegTestInfo, options: SnapshotVer }, 60_000); try { - const runner = new IntegSnapshotRunner({ test, runCommand: options.runCommand }); + const runner = new IntegSnapshotRunner({ test, appCommand: options.appCommand }); if (!runner.hasSnapshot()) { workerpool.workerEmit({ reason: DiagnosticReason.NO_SNAPSHOT, diff --git a/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts b/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts index 0b824a0ecff93..06d73967a2d25 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/integ-test-worker.ts @@ -135,7 +135,7 @@ export async function runIntegrationTestsInParallel( dryRun: options.dryRun, verbosity: options.verbosity, updateWorkflow: options.updateWorkflow, - runCommand: options.runCommand, + appCommand: options.appCommand, }], { on: printResults, }); diff --git a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts index 0df88c1bb23bc..1ca84c6781fa8 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts @@ -562,7 +562,7 @@ describe('IntegTest runIntegTests', () => { fileName: 'test/test-data-python/integ_python_test.py', discoveryRoot: 'test/test-data-python', }), - runCommand: 'python', + appCommand: 'python3.8 {filePath}', }); integTest.runIntegTestCase({ testCaseName: 'integ_python_test', @@ -573,13 +573,57 @@ describe('IntegTest runIntegTests', () => { expect(destroyMock).toHaveBeenCalledTimes(1); expect(synthFastMock).toHaveBeenCalledTimes(1); expect(deployMock).toHaveBeenCalledWith(expect.objectContaining({ - app: 'python integ_python_test.py', + app: 'python3.8 integ_python_test.py', })); expect(synthFastMock).toHaveBeenCalledWith(expect.objectContaining({ - execCmd: ['python', 'integ_python_test.py'], + execCmd: ['python3.8', 'integ_python_test.py'], })); expect(destroyMock).toHaveBeenCalledWith(expect.objectContaining({ - app: 'python integ_python_test.py', + app: 'python3.8 integ_python_test.py', + })); + }); + + test('with default app run command for Java, point to project root', () => { + // WHEN + const integTest = new IntegTestRunner({ + cdk: cdkMock.cdk, + test: new IntegTest({ + fileName: 'test/test-data-java/src/main/java/com/myorg/IntegTestJava.java', + discoveryRoot: 'test/test-data-java', + }), + }); + integTest.runIntegTestCase({ + testCaseName: 'IntegTestJava', + }); + + // THEN + expect(deployMock).toHaveBeenCalledTimes(1); + expect(destroyMock).toHaveBeenCalledTimes(1); + expect(synthFastMock).toHaveBeenCalledTimes(1); + expect(deployMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'mvn -f ../../../../../pom.xml -e -q compile exec:java clean -Dexec.mainClass=com.myorg.IntegTestJava', + })); + }); + + test('with default app run command for Java, point to specific package', () => { + // WHEN + const integTest = new IntegTestRunner({ + cdk: cdkMock.cdk, + test: new IntegTest({ + fileName: 'test/test-data-java/src/main/java/com/myorg/IntegTestJava.java', + discoveryRoot: 'test/test-data-java/src/main/java/com/myorg', + }), + }); + integTest.runIntegTestCase({ + testCaseName: 'IntegTestJava', + }); + + // THEN + expect(deployMock).toHaveBeenCalledTimes(1); + expect(destroyMock).toHaveBeenCalledTimes(1); + expect(synthFastMock).toHaveBeenCalledTimes(1); + expect(deployMock).toHaveBeenCalledWith(expect.objectContaining({ + app: 'mvn -f ../../../../../pom.xml -e -q compile exec:java clean -Dexec.mainClass=com.myorg.IntegTestJava', })); }); @@ -591,7 +635,7 @@ describe('IntegTest runIntegTests', () => { fileName: 'test/test-data-java/src/main/java/com/myorg/IntegTestJava.java', discoveryRoot: 'test/test-data-java/src/main/java/com/myorg', }), - runCommand: 'java -cp $CLASSPATH', + appCommand: 'java -cp $CLASSPATH {filePath}', }); integTest.runIntegTestCase({ testCaseName: 'IntegTestJava', diff --git a/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts b/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts index 22b796b9fe52e..3d94e82c55849 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts @@ -2,15 +2,20 @@ import * as mockfs from 'mock-fs'; import { IntegrationTests } from '../../lib/runner/integration-tests'; describe('IntegrationTests', () => { - const tests = new IntegrationTests('test'); + const tests = new IntegrationTests('test', undefined, ['javascript']); let stderrMock: jest.SpyInstance; stderrMock = jest.spyOn(process.stderr, 'write').mockImplementation(() => { return true; }); beforeEach(() => { mockfs({ 'test/test-data': { + 'integ.integ-test1.ts': 'content', 'integ.integ-test1.js': 'content', + 'integ.integ-test2.ts': 'content', 'integ.integ-test2.js': 'content', + 'integ.integ-test3.ts': 'content', 'integ.integ-test3.js': 'content', + 'integ_test_python.py': 'content', + 'integ-integ-test-custom-prefix.js': 'content', }, }); }); @@ -33,9 +38,10 @@ describe('IntegrationTests', () => { expect(stderrMock.mock.calls[0][0]).toContain( 'No such integ test: test-data/integ.integ-test16.js', ); - expect(stderrMock.mock.calls[1][0]).toContain( - 'Available tests: test-data/integ.integ-test1.js test-data/integ.integ-test2.js test-data/integ.integ-test3.js', - ); + expect(stderrMock.mock.calls[1][0]).toEqual(expect.stringMatching(/Available tests/)); + expect(stderrMock.mock.calls[1][0]).toEqual(expect.stringMatching(/test-data\/integ.integ-test1.js/)); + expect(stderrMock.mock.calls[1][0]).toEqual(expect.stringMatching(/test-data\/integ.integ-test2.js/)); + expect(stderrMock.mock.calls[1][0]).toEqual(expect.stringMatching(/test-data\/integ.integ-test3.js/)); }); test('from cli args, exclude', async () => { @@ -47,4 +53,55 @@ describe('IntegrationTests', () => { 'test/test-data/integ.integ-test1.js', ); }); + + test('from cli args, only Python files', async () => { + const onlyPythonTests = new IntegrationTests('test', undefined, ['python']); + const integTests = await onlyPythonTests.fromCliArgs(); + + expect(integTests.length).toEqual(1); + }); + + test('from cli args, Python and JavaScript files', async () => { + const onlyPythonAndJavascriptTests = new IntegrationTests('test', undefined, ['python', 'javascript']); + const integTests = await onlyPythonAndJavascriptTests.fromCliArgs(); + + expect(integTests.length).toEqual(4); + }); + + test('from cli args, JavaScript custom prefix', async () => { + const jsCustomPrefixTests = new IntegrationTests('test', new RegExp('^integ-'), ['javascript']); + const integTests = await jsCustomPrefixTests.fromCliArgs(); + + expect(integTests.length).toEqual(1); + }); + + test('from cli args, TypeScript compiled to JavaScript, does not pick up the compiled tests for both .ts and .js versions', async () => { + const tsCompiledTests = new IntegrationTests('test', undefined, ['javascript', 'typescript']); + const integTests = await tsCompiledTests.fromCliArgs(); + + expect(integTests.length).toEqual(3); + }); + + test('from cli args, TypeScript compiled to JavaScript, gives precedence to TypeScript files', async () => { + const tsCompiledTests = new IntegrationTests('test', undefined, ['javascript', 'typescript']); + const integTests = await tsCompiledTests.fromCliArgs(); + + for (const test of integTests) { + expect(test.fileName).toEqual(expect.stringMatching(/integ.integ-test[1-3].ts/)); + } + }); + + test('from cli args, TypeScript .d.ts files should be ignored', async () => { + mockfs({ + 'test/test-data': { + 'integ.integ-test1.ts': 'content', + 'integ.integ-test1.d.ts': 'content', + }, + }); + const tsCompiledTests = new IntegrationTests('test'); + const integTests = await tsCompiledTests.fromCliArgs(); + + expect(integTests.length).toEqual(1); + expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.ts/)); + }); }); diff --git a/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml b/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml index e83f92d58d24a..5981fb0d48a08 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml +++ b/packages/@aws-cdk/integ-runner/test/test-data-java/pom.xml @@ -14,6 +14,26 @@ [10.0.0,11.0.0) + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + + diff --git a/packages/aws-cdk/lib/index.ts b/packages/aws-cdk/lib/index.ts index 57502a1035caf..0561268a049f8 100644 --- a/packages/aws-cdk/lib/index.ts +++ b/packages/aws-cdk/lib/index.ts @@ -1,2 +1,3 @@ export * from './api'; export { cli } from './cli'; +export { pythonExecutable } from './init'; \ No newline at end of file diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index 810aa53113bd4..b116ce271afc7 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -46,7 +46,7 @@ export async function cliInit(type?: string, language?: string, canUseNetwork = /** * Returns the name of the Python executable for this OS */ -function pythonExecutable() { +export function pythonExecutable() { let python = 'python3'; if (process.platform === 'win32') { python = 'python'; From d110bce978470bab000276234f45c1feb383ffdc Mon Sep 17 00:00:00 2001 From: karakter98 <37190268+karakter98@users.noreply.github.com> Date: Tue, 18 Oct 2022 17:54:06 +0300 Subject: [PATCH 7/7] Fixed existing integration test that worked when executed as a .js compiled file, but broke if run with ts-node directly. --- .../aws-events-targets/test/aws-api/integ.aws-api.ts | 7 ++++--- packages/@aws-cdk/integ-runner/README.md | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-events-targets/test/aws-api/integ.aws-api.ts b/packages/@aws-cdk/aws-events-targets/test/aws-api/integ.aws-api.ts index 9dc135dfef993..495361a19be2e 100644 --- a/packages/@aws-cdk/aws-events-targets/test/aws-api/integ.aws-api.ts +++ b/packages/@aws-cdk/aws-events-targets/test/aws-api/integ.aws-api.ts @@ -1,5 +1,6 @@ import * as events from '@aws-cdk/aws-events'; import * as cdk from '@aws-cdk/core'; +import { ECS, RDS } from 'aws-sdk'; import * as targets from '../../lib'; const app = new cdk.App(); @@ -22,7 +23,7 @@ class AwsApi extends cdk.Stack { parameters: { service: 'cool-service', forceNewDeployment: true, - } as AWS.ECS.UpdateServiceRequest, + } as ECS.UpdateServiceRequest, })); scheduleRule.addTarget(new targets.AwsApi({ @@ -30,7 +31,7 @@ class AwsApi extends cdk.Stack { action: 'stopDBInstance', parameters: { DBInstanceIdentifier: 'dev-instance', - } as AWS.RDS.StopDBInstanceMessage, + } as RDS.StopDBInstanceMessage, })); // Create snapshots when a DB instance restarts @@ -48,7 +49,7 @@ class AwsApi extends cdk.Stack { action: 'createDBSnapshot', parameters: { DBInstanceIdentifier: events.EventField.fromPath('$.detail.SourceArn'), - } as AWS.RDS.CreateDBSnapshotMessage, + } as RDS.CreateDBSnapshotMessage, })); } } diff --git a/packages/@aws-cdk/integ-runner/README.md b/packages/@aws-cdk/integ-runner/README.md index 94a281e46486c..4cddd5dafdf27 100644 --- a/packages/@aws-cdk/integ-runner/README.md +++ b/packages/@aws-cdk/integ-runner/README.md @@ -68,8 +68,12 @@ to be a self contained CDK app. The runner will execute the following for each f Read the list of tests from this file - `--disable-update-workflow` (default=`false`) If this is set to `true` then the [update workflow](#update-workflow) will be disabled -- `--test-run-command` (default=`node`) - The command used by the test runner to synth the test files. This will depend on the language the tests are written in. For example, if the tests are written in Python, you could set this parameter to 'python', 'python3' or 'python3.8'. +- `--app` + The command used by the test runner to synth the test files. Uses default run commands based on the language the test is written in. You can use {filePath} in the command to specify where the test file name should be inserted in the command. Example: `--app "python3.8 {filePath}"` +- `--language` (default=`['csharp', 'fsharp', 'go', 'java', 'javascript', 'python', 'typescript']`) + The list of languages to discover tests for. Defaults to all CDK-supported languages. Example: `--language python --language typescript` +- `--test-regex` + A custom pattern in the JS RegExp format to match integration test file prefixes. Defaults are set based on naming conventions for the language the test is written in. Example: `--test-regex "^Integ\."` Example: