Skip to content

Commit 157c37d

Browse files
authored
chore: make the Amplify integration tests respect AWS region assignments (#31944)
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. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8e4c247 commit 157c37d

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export type AwsContext = { readonly aws: AwsClients };
1010
*
1111
* Allocate the next region from the REGION pool and dispose it afterwards.
1212
*/
13-
export function withAws(
14-
block: (context: TestContext & AwsContext & DisableBootstrapContext) => Promise<void>,
13+
export function withAws<A extends TestContext>(
14+
block: (context: A & AwsContext & DisableBootstrapContext) => Promise<void>,
1515
disableBootstrap: boolean = false,
16-
): (context: TestContext) => Promise<void> {
17-
return (context: TestContext) => regionPool().using(async (region) => {
16+
): (context: A) => Promise<void> {
17+
return (context: A) => regionPool().using(async (region) => {
1818
const aws = await AwsClients.forRegion(region, context.output);
1919
await sanityCheck(aws);
2020

packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { promises as fs } from 'fs';
22
import * as path from 'path';
3-
import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext } from '../../lib';
3+
import { withToolContext } from './with-tool-context';
4+
import { integTest, ShellHelper, TemporaryDirectoryContext } from '../../lib';
45

56
const TIMEOUT = 1800_000;
67

7-
integTest('amplify integration', withTemporaryDirectory(withPackages(async (context) => {
8+
integTest('amplify integration', withToolContext(async (context) => {
89
const shell = ShellHelper.fromContext(context);
910

1011
await shell.shell(['npm', 'create', '-y', 'amplify@latest']);
@@ -14,9 +15,24 @@ integTest('amplify integration', withTemporaryDirectory(withPackages(async (cont
1415
await updateCdkDependency(context, context.packages.requestedCliVersion(), context.packages.requestedFrameworkVersion());
1516
await shell.shell(['npm', 'install']);
1617

17-
await shell.shell(['npx', 'ampx', 'sandbox', '--once']);
18-
await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes']);
19-
})), TIMEOUT);
18+
await shell.shell(['npx', 'ampx', 'sandbox', '--once'], {
19+
modEnv: {
20+
AWS_REGION: context.aws.region,
21+
},
22+
});
23+
try {
24+
25+
// Future code goes here, putting the try/finally here already so it doesn't
26+
// get forgotten.
27+
28+
} finally {
29+
await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes'], {
30+
modEnv: {
31+
AWS_REGION: context.aws.region,
32+
},
33+
});
34+
}
35+
}), TIMEOUT);
2036

2137
async function updateCdkDependency(context: TemporaryDirectoryContext, cliVersion: string, libVersion: string) {
2238
const filename = path.join(context.integTestDir, 'package.json');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { TestContext } from '../../lib/integ-test';
2+
import { AwsContext, withAws } from '../../lib/with-aws';
3+
import { DisableBootstrapContext } from '../../lib/with-cdk-app';
4+
import { PackageContext, withPackages } from '../../lib/with-packages';
5+
import { TemporaryDirectoryContext, withTemporaryDirectory } from '../../lib/with-temporary-directory';
6+
7+
/**
8+
* The default prerequisites for tests running tool integrations
9+
*/
10+
export function withToolContext<A extends TestContext>(
11+
block: (context: A & TemporaryDirectoryContext & PackageContext & AwsContext & DisableBootstrapContext
12+
) => Promise<void>) {
13+
return withAws(withTemporaryDirectory(withPackages(block)));
14+
}

0 commit comments

Comments
 (0)