From bb1968a70cfd7a67a5bd1f021080492b94198346 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 30 Oct 2024 11:10:57 +0100 Subject: [PATCH 1/3] chore: make the Amplify integration tests respect AWS region assignments We must qualify the test to use `withAws()`, so that it gets access to AWS clients (unused) and a region allocation (we use this!). Pass the region to the Amplify client. --- .../tool-integrations/amplify.integtest.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts index 50be902ef31d2..418878be1e762 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts @@ -1,10 +1,10 @@ import { promises as fs } from 'fs'; import * as path from 'path'; -import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext } from '../../lib'; +import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext, withAws } from '../../lib'; const TIMEOUT = 1800_000; -integTest('amplify integration', withTemporaryDirectory(withPackages(async (context) => { +integTest('amplify integration', withAws(withTemporaryDirectory(withPackages(async (context) => { const shell = ShellHelper.fromContext(context); await shell.shell(['npm', 'create', '-y', 'amplify@latest']); @@ -14,9 +14,24 @@ integTest('amplify integration', withTemporaryDirectory(withPackages(async (cont await updateCdkDependency(context, context.packages.requestedCliVersion(), context.packages.requestedFrameworkVersion()); await shell.shell(['npm', 'install']); - await shell.shell(['npx', 'ampx', 'sandbox', '--once']); - await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes']); -})), TIMEOUT); + await shell.shell(['npx', 'ampx', 'sandbox', '--once'], { + modEnv: { + AWS_REGION: context.aws.region, + }, + }); + try { + + // Future code goes here, putting the try/finally here already so it doesn't + // get forgotten. + + } finally { + await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes'], { + modEnv: { + AWS_REGION: context.aws.region, + }, + }); + } +}))), TIMEOUT); async function updateCdkDependency(context: TemporaryDirectoryContext, cliVersion: string, libVersion: string) { const filename = path.join(context.integTestDir, 'package.json'); From f571c9ba26dc8a9057c5881ad2716effa1c9dd50 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 30 Oct 2024 11:38:05 +0100 Subject: [PATCH 2/3] Add a copy/pasteable wrapper --- .../@aws-cdk-testing/cli-integ/lib/with-aws.ts | 8 ++++---- .../tests/tool-integrations/amplify.integtest.ts | 7 ++++--- .../tests/tool-integrations/with-tool-context.ts | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts diff --git a/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts b/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts index a9ebe5a2ba968..8f9ca8d51a612 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts @@ -10,11 +10,11 @@ export type AwsContext = { readonly aws: AwsClients }; * * Allocate the next region from the REGION pool and dispose it afterwards. */ -export function withAws( - block: (context: TestContext & AwsContext & DisableBootstrapContext) => Promise, +export function withAws( + block: (context: A & AwsContext & DisableBootstrapContext) => Promise, disableBootstrap: boolean = false, -): (context: TestContext) => Promise { - return (context: TestContext) => regionPool().using(async (region) => { +): (context: A) => Promise { + return (context: A) => regionPool().using(async (region) => { const aws = await AwsClients.forRegion(region, context.output); await sanityCheck(aws); diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts index 418878be1e762..8c926e010ef76 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts @@ -1,10 +1,11 @@ import { promises as fs } from 'fs'; import * as path from 'path'; -import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext, withAws } from '../../lib'; +import { withToolContext } from './with-tool-context'; +import { integTest, ShellHelper, TemporaryDirectoryContext } from '../../lib'; const TIMEOUT = 1800_000; -integTest('amplify integration', withAws(withTemporaryDirectory(withPackages(async (context) => { +integTest('amplify integration', withToolContext(async (context) => { const shell = ShellHelper.fromContext(context); await shell.shell(['npm', 'create', '-y', 'amplify@latest']); @@ -31,7 +32,7 @@ integTest('amplify integration', withAws(withTemporaryDirectory(withPackages(asy }, }); } -}))), TIMEOUT); +}), TIMEOUT); async function updateCdkDependency(context: TemporaryDirectoryContext, cliVersion: string, libVersion: string) { const filename = path.join(context.integTestDir, 'package.json'); diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts new file mode 100644 index 0000000000000..6c93489691ea0 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts @@ -0,0 +1,14 @@ +import { TestContext } from '../../lib/integ-test'; +import { AwsContext, withAws } from '../../lib/with-aws'; +import { DisableBootstrapContext } from '../../lib/with-cdk-app'; +import { PackageContext, withPackages } from '../../lib/with-packages'; +import { TemporaryDirectoryContext, withTemporaryDirectory } from '../../lib/with-temporary-directory'; + +/** + * The default prerequisites for tests running tool integrations + */ +export function withToolContext( + block: (context: A & TemporaryDirectoryContext & PackageContext & AwsContext & DisableBootstrapContext + ) => Promise) { + return withAws(withTemporaryDirectory(withPackages(block))); +} \ No newline at end of file From 113d7cfbbf12a9eb445cef8522ac2ff9d63e2c5d Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Wed, 30 Oct 2024 12:09:42 +0100 Subject: [PATCH 3/3] Update packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts Co-authored-by: Momo Kornher --- .../cli-integ/tests/tool-integrations/with-tool-context.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts index 6c93489691ea0..91a9bf3c688a7 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts @@ -11,4 +11,4 @@ export function withToolContext( block: (context: A & TemporaryDirectoryContext & PackageContext & AwsContext & DisableBootstrapContext ) => Promise) { return withAws(withTemporaryDirectory(withPackages(block))); -} \ No newline at end of file +}