From a91c3c3474905578f38a3cdb2ce17a97a94192f4 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Sat, 8 Oct 2022 19:59:32 +0300 Subject: [PATCH 1/8] fix(integ-runner): Fix call to spawnSync for hooks commands --- .../lib/runner/integ-test-runner.ts | 26 ++++++++++++------- packages/@aws-cdk/integ-runner/lib/utils.ts | 12 +++++++++ .../test/runner/integ-test-runner.test.ts | 8 +++--- .../integ.json | 8 +++--- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts index cf6fe6b9efb5b..a186ef7389b64 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts @@ -3,7 +3,7 @@ import { RequireApproval } from '@aws-cdk/cloud-assembly-schema'; import { DeployOptions, DestroyOptions } from 'cdk-cli-wrapper'; import * as fs from 'fs-extra'; import * as logger from '../logger'; -import { chain, exec } from '../utils'; +import { exec, prepareForExec } from '../utils'; import { DestructiveChange, AssertionResults, AssertionResult } from '../workers/common'; import { IntegRunnerOptions, IntegRunner, DEFAULT_SYNTH_OPTIONS } from './runner-base'; @@ -222,8 +222,10 @@ export class IntegTestRunner extends IntegRunner { const actualTestCase = this.actualTestSuite.testSuite[testCaseName]; try { if (actualTestCase.hooks?.preDestroy) { - exec([chain(actualTestCase.hooks.preDestroy)], { - cwd: path.dirname(this.snapshotDir), + actualTestCase.hooks.preDestroy.forEach(cmd => { + exec(prepareForExec(cmd), { + cwd: path.dirname(this.snapshotDir), + }); }); } this.cdk.destroy({ @@ -231,8 +233,10 @@ export class IntegTestRunner extends IntegRunner { }); if (actualTestCase.hooks?.postDestroy) { - exec([chain(actualTestCase.hooks.postDestroy)], { - cwd: path.dirname(this.snapshotDir), + actualTestCase.hooks.postDestroy.forEach(cmd => { + exec(prepareForExec(cmd), { + cwd: path.dirname(this.snapshotDir), + }); }); } } catch (e) { @@ -255,8 +259,10 @@ export class IntegTestRunner extends IntegRunner { const actualTestCase = this.actualTestSuite.testSuite[testCaseName]; try { if (actualTestCase.hooks?.preDeploy) { - exec([chain(actualTestCase.hooks?.preDeploy)], { - cwd: path.dirname(this.snapshotDir), + actualTestCase.hooks.preDeploy.forEach(cmd => { + exec(prepareForExec(cmd), { + cwd: path.dirname(this.snapshotDir), + }); }); } // if the update workflow is not disabled, first @@ -297,8 +303,10 @@ export class IntegTestRunner extends IntegRunner { }); if (actualTestCase.hooks?.postDeploy) { - exec([chain(actualTestCase.hooks?.postDeploy)], { - cwd: path.dirname(this.snapshotDir), + actualTestCase.hooks.postDeploy.forEach(cmd => { + exec(prepareForExec(cmd), { + cwd: path.dirname(this.snapshotDir), + }); }); } diff --git a/packages/@aws-cdk/integ-runner/lib/utils.ts b/packages/@aws-cdk/integ-runner/lib/utils.ts index 74e5eb2154ae7..2ade5bc857ec5 100644 --- a/packages/@aws-cdk/integ-runner/lib/utils.ts +++ b/packages/@aws-cdk/integ-runner/lib/utils.ts @@ -41,6 +41,18 @@ export function chain(commands: string[]): string { return commands.filter(c => !!c).join(' && '); } +/** + * Prepare command for execution by exec + */ +export function prepareForExec(command: string): string[] { + let chunks = command.split(/\s+/); + const cmd = chunks.shift(); + if (cmd !== undefined) { + return [cmd, chunks.join(' ')]; + } + return []; +} + /** * A class holding a set of items which are being crossed off in time 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..dbbe5b117a1a3 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 @@ -347,16 +347,16 @@ describe('IntegTest runIntegTests', () => { // THEN expect(spawnSyncMock.mock.calls).toEqual(expect.arrayContaining([ expect.arrayContaining([ - 'echo "preDeploy"', + 'echo', ['"preDeploy hook"'], ]), expect.arrayContaining([ - 'echo "postDeploy"', + 'echo', ['"postDeploy hook"'], ]), expect.arrayContaining([ - 'echo "preDestroy"', + 'echo', ['"preDestroy hook"'], ]), expect.arrayContaining([ - 'echo "postDestroy"', + 'echo', ['"postDestroy hook"'], ]), ])); }); 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..d4cf3dfdba923 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 @@ -6,10 +6,10 @@ "stackUpdateWorkflow": false, "diffAssets": false, "hooks": { - "preDeploy": ["echo \"preDeploy\""], - "postDeploy": ["echo \"postDeploy\""], - "preDestroy": ["echo \"preDestroy\""], - "postDestroy": ["echo \"postDestroy\""] + "preDeploy": ["echo \"preDeploy hook\""], + "postDeploy": ["echo \"postDeploy hook\""], + "preDestroy": ["echo \"preDestroy hook\""], + "postDestroy": ["echo \"postDestroy hook\""] }, "allowDestroy": [ "AWS::IAM::Role" From 1b798f3a63132f3a92e1e1a29a801cd35ba517d2 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Sat, 8 Oct 2022 21:57:38 +0300 Subject: [PATCH 2/8] Additional tests --- .../integ-runner/test/runner/integ-test-runner.test.ts | 6 ++++++ .../cdk-integ.out.test-with-snapshot-assets/integ.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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 dbbe5b117a1a3..2cfcbeebe8683 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 @@ -358,6 +358,12 @@ describe('IntegTest runIntegTests', () => { expect.arrayContaining([ 'echo', ['"postDestroy hook"'], ]), + expect.arrayContaining([ + 'ls', [''], + ]), + expect.arrayContaining([ + 'echo', ['-n "No new line"'], + ]), ])); }); 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 d4cf3dfdba923..126b54791cd02 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 @@ -6,7 +6,7 @@ "stackUpdateWorkflow": false, "diffAssets": false, "hooks": { - "preDeploy": ["echo \"preDeploy hook\""], + "preDeploy": ["echo \"preDeploy hook\"", "ls", "echo -n \"No new line\""], "postDeploy": ["echo \"postDeploy hook\""], "preDestroy": ["echo \"preDestroy hook\""], "postDestroy": ["echo \"postDestroy hook\""] From f71d813b01da874bc9a03aa5a0a34b3306293004 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Tue, 11 Oct 2022 17:13:36 +0300 Subject: [PATCH 3/8] Add sample integration test --- packages/@aws-cdk/integ-tests/package.json | 4 +- ...efaultTestDeployAssert4E6713E1.assets.json | 19 ++++++ ...aultTestDeployAssert4E6713E1.template.json | 36 ++++++++++++ .../test/app.integ.snapshot/cdk.out | 1 + .../test/app.integ.snapshot/integ.json | 18 ++++++ .../test/app.integ.snapshot/manifest.json | 58 +++++++++++++++++++ .../test/app.integ.snapshot/tree.json | 57 ++++++++++++++++++ .../@aws-cdk/integ-tests/test/integ.app.ts | 7 +++ 8 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json create mode 100644 packages/@aws-cdk/integ-tests/test/integ.app.ts diff --git a/packages/@aws-cdk/integ-tests/package.json b/packages/@aws-cdk/integ-tests/package.json index a42f2bd3796a2..6309a5732f95d 100644 --- a/packages/@aws-cdk/integ-tests/package.json +++ b/packages/@aws-cdk/integ-tests/package.json @@ -52,7 +52,8 @@ "compat": "cdk-compat", "rosetta:extract": "yarn --silent jsii-rosetta extract", "build+extract": "yarn build && yarn rosetta:extract", - "build+test+extract": "yarn build+test && yarn rosetta:extract" + "build+test+extract": "yarn build+test && yarn rosetta:extract", + "integ": "integ-runner" }, "author": { "name": "Amazon Web Services", @@ -65,6 +66,7 @@ "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cx-api": "0.0.0", "@aws-cdk/pkglint": "0.0.0", + "@aws-cdk/integ-runner": "0.0.0", "@types/fs-extra": "^8.1.2", "@types/jest": "^27.5.2", "@types/node": "^14.18.31", diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json new file mode 100644 index 0000000000000..1c86a68a43509 --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.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-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.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-tests/test/app.integ.snapshot/cdk.out b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json new file mode 100644 index 0000000000000..5dcefc60623e9 --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json @@ -0,0 +1,18 @@ +{ + "version": "21.0.0", + "testCases": { + "Integ/DefaultTest": { + "stacks": [ + "Default" + ], + "assertionStack": "Integ/DefaultTest/DeployAssert", + "assertionStackName": "IntegDefaultTestDeployAssert4E6713E1", + "hooks": { + "preDeploy": ["echo \"preDeploy\""], + "postDeploy": ["echo \"postDeploy\""], + "preDestroy": ["echo \"preDestroy\""], + "postDestroy": ["echo \"postDestroy\""] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..7a077e8868885 --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json @@ -0,0 +1,58 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "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-tests/test/app.integ.snapshot/tree.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json new file mode 100644 index 0000000000000..b953c7466a386 --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json @@ -0,0 +1,57 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.102" + } + }, + "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.102" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "Integ/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests/test/integ.app.ts b/packages/@aws-cdk/integ-tests/test/integ.app.ts new file mode 100644 index 0000000000000..25c30e10331f0 --- /dev/null +++ b/packages/@aws-cdk/integ-tests/test/integ.app.ts @@ -0,0 +1,7 @@ +import { App, Stack } from '@aws-cdk/core'; +import { IntegTest } from '../lib'; + +const app = new App(); +const stack = new Stack(); + +new IntegTest(app, 'Integ', { testCases: [stack] }); From b15c9a88bba59c9867c928c764b9fae176345732 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Fri, 14 Oct 2022 21:51:46 +0300 Subject: [PATCH 4/8] Remove excess integ test --- packages/@aws-cdk/integ-tests/package.json | 4 +--- packages/@aws-cdk/integ-tests/test/integ.app.ts | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 packages/@aws-cdk/integ-tests/test/integ.app.ts diff --git a/packages/@aws-cdk/integ-tests/package.json b/packages/@aws-cdk/integ-tests/package.json index 3c36a1eb65457..c81df25f0bb74 100644 --- a/packages/@aws-cdk/integ-tests/package.json +++ b/packages/@aws-cdk/integ-tests/package.json @@ -52,8 +52,7 @@ "compat": "cdk-compat", "rosetta:extract": "yarn --silent jsii-rosetta extract", "build+extract": "yarn build && yarn rosetta:extract", - "build+test+extract": "yarn build+test && yarn rosetta:extract", - "integ": "integ-runner" + "build+test+extract": "yarn build+test && yarn rosetta:extract" }, "author": { "name": "Amazon Web Services", @@ -66,7 +65,6 @@ "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cx-api": "0.0.0", "@aws-cdk/pkglint": "0.0.0", - "@aws-cdk/integ-runner": "0.0.0", "@types/fs-extra": "^8.1.2", "@types/jest": "^27.5.2", "@types/node": "^14.18.32", diff --git a/packages/@aws-cdk/integ-tests/test/integ.app.ts b/packages/@aws-cdk/integ-tests/test/integ.app.ts deleted file mode 100644 index 25c30e10331f0..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/integ.app.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { App, Stack } from '@aws-cdk/core'; -import { IntegTest } from '../lib'; - -const app = new App(); -const stack = new Stack(); - -new IntegTest(app, 'Integ', { testCases: [stack] }); From 24f7ba86ef7e5c14b1a1d3012d77a435fd0b48a0 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Fri, 14 Oct 2022 21:54:27 +0300 Subject: [PATCH 5/8] Remove excess snapshots --- ...efaultTestDeployAssert4E6713E1.assets.json | 19 ------ ...aultTestDeployAssert4E6713E1.template.json | 36 ------------ .../test/app.integ.snapshot/cdk.out | 1 - .../test/app.integ.snapshot/integ.json | 18 ------ .../test/app.integ.snapshot/manifest.json | 58 ------------------- .../test/app.integ.snapshot/tree.json | 57 ------------------ 6 files changed, 189 deletions(-) delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json delete mode 100644 packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json deleted file mode 100644 index 1c86a68a43509..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "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-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json deleted file mode 100644 index ad9d0fb73d1dd..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "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-tests/test/app.integ.snapshot/cdk.out b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out deleted file mode 100644 index 8ecc185e9dbee..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/cdk.out +++ /dev/null @@ -1 +0,0 @@ -{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json deleted file mode 100644 index 5dcefc60623e9..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/integ.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "21.0.0", - "testCases": { - "Integ/DefaultTest": { - "stacks": [ - "Default" - ], - "assertionStack": "Integ/DefaultTest/DeployAssert", - "assertionStackName": "IntegDefaultTestDeployAssert4E6713E1", - "hooks": { - "preDeploy": ["echo \"preDeploy\""], - "postDeploy": ["echo \"postDeploy\""], - "preDestroy": ["echo \"preDestroy\""], - "postDestroy": ["echo \"postDestroy\""] - } - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json deleted file mode 100644 index 7a077e8868885..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/manifest.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "version": "21.0.0", - "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, - "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-tests/test/app.integ.snapshot/tree.json b/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json deleted file mode 100644 index b953c7466a386..0000000000000 --- a/packages/@aws-cdk/integ-tests/test/app.integ.snapshot/tree.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.102" - } - }, - "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.102" - } - }, - "DeployAssert": { - "id": "DeployAssert", - "path": "Integ/DefaultTest/DeployAssert", - "constructInfo": { - "fqn": "@aws-cdk/core.Stack", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests.IntegTestCase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests.IntegTest", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/core.App", - "version": "0.0.0" - } - } -} \ No newline at end of file From 937e43d66e374f49a6a673f441aaedfde7f51c1e Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Wed, 19 Oct 2022 20:43:39 +0300 Subject: [PATCH 6/8] Refator the solution --- .../integ-runner/lib/runner/integ-test-runner.ts | 10 +++++----- packages/@aws-cdk/integ-runner/lib/utils.ts | 11 +++++------ .../test/runner/integ-test-runner.test.ts | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts index a186ef7389b64..5347928aa65f4 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts @@ -3,7 +3,7 @@ import { RequireApproval } from '@aws-cdk/cloud-assembly-schema'; import { DeployOptions, DestroyOptions } from 'cdk-cli-wrapper'; import * as fs from 'fs-extra'; import * as logger from '../logger'; -import { exec, prepareForExec } from '../utils'; +import { exec, chunks } from '../utils'; import { DestructiveChange, AssertionResults, AssertionResult } from '../workers/common'; import { IntegRunnerOptions, IntegRunner, DEFAULT_SYNTH_OPTIONS } from './runner-base'; @@ -223,7 +223,7 @@ export class IntegTestRunner extends IntegRunner { try { if (actualTestCase.hooks?.preDestroy) { actualTestCase.hooks.preDestroy.forEach(cmd => { - exec(prepareForExec(cmd), { + exec(chunks(cmd), { cwd: path.dirname(this.snapshotDir), }); }); @@ -234,7 +234,7 @@ export class IntegTestRunner extends IntegRunner { if (actualTestCase.hooks?.postDestroy) { actualTestCase.hooks.postDestroy.forEach(cmd => { - exec(prepareForExec(cmd), { + exec(chunks(cmd), { cwd: path.dirname(this.snapshotDir), }); }); @@ -260,7 +260,7 @@ export class IntegTestRunner extends IntegRunner { try { if (actualTestCase.hooks?.preDeploy) { actualTestCase.hooks.preDeploy.forEach(cmd => { - exec(prepareForExec(cmd), { + exec(chunks(cmd), { cwd: path.dirname(this.snapshotDir), }); }); @@ -304,7 +304,7 @@ export class IntegTestRunner extends IntegRunner { if (actualTestCase.hooks?.postDeploy) { actualTestCase.hooks.postDeploy.forEach(cmd => { - exec(prepareForExec(cmd), { + exec(chunks(cmd), { cwd: path.dirname(this.snapshotDir), }); }); diff --git a/packages/@aws-cdk/integ-runner/lib/utils.ts b/packages/@aws-cdk/integ-runner/lib/utils.ts index 2ade5bc857ec5..654c9e83e6165 100644 --- a/packages/@aws-cdk/integ-runner/lib/utils.ts +++ b/packages/@aws-cdk/integ-runner/lib/utils.ts @@ -42,13 +42,12 @@ export function chain(commands: string[]): string { } /** - * Prepare command for execution by exec + * Split command to chunks by space */ -export function prepareForExec(command: string): string[] { - let chunks = command.split(/\s+/); - const cmd = chunks.shift(); - if (cmd !== undefined) { - return [cmd, chunks.join(' ')]; +export function chunks(command: string): string[] { + const result = command.match(/(?:[^\s"]+|"[^"]*")+/g); + if (result !== null) { + return result; } return []; } 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 2cfcbeebe8683..b817c9bdb7f11 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 @@ -359,10 +359,10 @@ describe('IntegTest runIntegTests', () => { 'echo', ['"postDestroy hook"'], ]), expect.arrayContaining([ - 'ls', [''], + 'ls', [], ]), expect.arrayContaining([ - 'echo', ['-n "No new line"'], + 'echo', ['-n', '"No new line"'], ]), ])); }); From c5ed43015f3613597f4027b077ba90ad5b9a3a59 Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Wed, 19 Oct 2022 20:44:45 +0300 Subject: [PATCH 7/8] Tiny update --- packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts index 5347928aa65f4..dcdaa58f2e47f 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts @@ -3,7 +3,7 @@ import { RequireApproval } from '@aws-cdk/cloud-assembly-schema'; import { DeployOptions, DestroyOptions } from 'cdk-cli-wrapper'; import * as fs from 'fs-extra'; import * as logger from '../logger'; -import { exec, chunks } from '../utils'; +import { chunks, exec } from '../utils'; import { DestructiveChange, AssertionResults, AssertionResult } from '../workers/common'; import { IntegRunnerOptions, IntegRunner, DEFAULT_SYNTH_OPTIONS } from './runner-base'; From a899f7f409c71cfb7cbda7ff0520ff5c6c45ce5d Mon Sep 17 00:00:00 2001 From: Alexandr Rewa Date: Wed, 19 Oct 2022 21:44:03 +0300 Subject: [PATCH 8/8] Tiny update --- packages/@aws-cdk/integ-runner/lib/utils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/@aws-cdk/integ-runner/lib/utils.ts b/packages/@aws-cdk/integ-runner/lib/utils.ts index 654c9e83e6165..c783e6ca2a491 100644 --- a/packages/@aws-cdk/integ-runner/lib/utils.ts +++ b/packages/@aws-cdk/integ-runner/lib/utils.ts @@ -46,10 +46,7 @@ export function chain(commands: string[]): string { */ export function chunks(command: string): string[] { const result = command.match(/(?:[^\s"]+|"[^"]*")+/g); - if (result !== null) { - return result; - } - return []; + return result ?? []; }