From ed48cf59a2e60cc25a78f83641ca8f3bc63bc68f Mon Sep 17 00:00:00 2001 From: Edward Foyle Date: Fri, 17 Apr 2020 15:18:33 -0700 Subject: [PATCH] fix: select us-east-2 in integ tests (#3992) --- .circleci/amplify_init.exp | 2 +- .../amplify-e2e-tests/src/categories/api.ts | 3 +- .../src/categories/function.ts | 20 +------------ .../amplify-e2e-tests/src/configure/index.ts | 29 +++++++++++++++---- .../amplify-e2e-tests/src/configure_tests.ts | 6 ++-- .../amplify-e2e-tests/src/utils/selectors.ts | 20 +++++++++++++ .../lib/aws-regions.js | 3 ++ 7 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 packages/amplify-e2e-tests/src/utils/selectors.ts diff --git a/.circleci/amplify_init.exp b/.circleci/amplify_init.exp index f79d2c2835d..2d4adb6d228 100644 --- a/.circleci/amplify_init.exp +++ b/.circleci/amplify_init.exp @@ -28,5 +28,5 @@ expect "secretAccessKey:" send -- "$env(AWS_SECRET_ACCESS_KEY)\r" expect -exact "region:" log_user 1; -send -- "\r" +send -- "j\r" # us-east-2 interact; diff --git a/packages/amplify-e2e-tests/src/categories/api.ts b/packages/amplify-e2e-tests/src/categories/api.ts index 2f0328d9387..16ad49c30fa 100644 --- a/packages/amplify-e2e-tests/src/categories/api.ts +++ b/packages/amplify-e2e-tests/src/categories/api.ts @@ -1,7 +1,8 @@ import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW } from 'amplify-e2e-core'; import * as fs from 'fs-extra'; import { getCLIPath, updateSchema } from '../utils'; -import { singleSelect, runtimeChoices, addFunction, nodeJSTemplateChoices, selectRuntime } from './function'; +import { nodeJSTemplateChoices, selectRuntime } from './function'; +import { singleSelect } from '../utils/selectors'; function getSchemaPath(schemaName: string): string { return `${__dirname}/../../schemas/${schemaName}`; diff --git a/packages/amplify-e2e-tests/src/categories/function.ts b/packages/amplify-e2e-tests/src/categories/function.ts index d90624579d7..1808d33bbe0 100644 --- a/packages/amplify-e2e-tests/src/categories/function.ts +++ b/packages/amplify-e2e-tests/src/categories/function.ts @@ -1,6 +1,7 @@ import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW } from 'amplify-e2e-core'; import { getCLIPath, getProjectMeta, invokeFunction } from '../utils'; import { Lambda } from 'aws-sdk'; +import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors'; type FunctionActions = 'create' | 'update'; @@ -32,25 +33,6 @@ export const nodeJSTemplateChoices = [ const pythonTemplateChoices = ['Hello World']; -export const moveDown = (chain: ExecutionContext, nMoves: number) => - Array.from(Array(nMoves).keys()).reduce((chain, _idx) => chain.send(KEY_DOWN_ARROW), chain); - -export const moveUp = (chain: ExecutionContext, nMoves: number) => - Array.from(Array(nMoves).keys()).reduce((chain, _idx) => chain.send('k'), chain); - -export const singleSelect = (chain: ExecutionContext, item: T, allChoices: T[]) => multiSelect(chain, [item], allChoices); - -export const multiSelect = (chain: ExecutionContext, items: T[], allChoices: T[]) => - items - .map(item => allChoices.indexOf(item)) - .filter(idx => idx > -1) - .sort() - // calculate the diff with the latest, since items are sorted, always positive - // represents the numbers of moves down we need to make to selection - .reduce((diffs, move) => (diffs.length > 0 ? [...diffs, move - diffs[diffs.length - 1]] : [move]), [] as number[]) - .reduce((chain, move) => moveDown(chain, move).send(' '), chain) - .sendCarriageReturn(); - const coreFunction = ( cwd: string, settings: any, diff --git a/packages/amplify-e2e-tests/src/configure/index.ts b/packages/amplify-e2e-tests/src/configure/index.ts index 9a5ca5bf84f..b1f19e38064 100644 --- a/packages/amplify-e2e-tests/src/configure/index.ts +++ b/packages/amplify-e2e-tests/src/configure/index.ts @@ -1,19 +1,35 @@ import { nspawn as spawn } from 'amplify-e2e-core'; import { getCLIPath } from '../utils'; +import { singleSelect } from '../utils/selectors'; type AmplifyConfiguration = { accessKeyId: string; secretAccessKey: string; profileName?: string; + region?: string; }; const defaultSettings = { profileName: 'amplify-integ-test-user', - region: '\r', + region: 'us-east-2', userName: '\r', }; -const MANDATORY_PARAMS = ['accessKeyId', 'secretAccessKey']; +const regionOptions = [ + 'us-east-1', + 'us-east-2', + 'us-west-2', + 'eu-west-1', + 'eu-west-2', + 'eu-central-1', + 'ap-northeast-1', + 'ap-northeast-2', + 'ap-southeast-1', + 'ap-southeast-2', + 'ap-south-1', +]; + +const MANDATORY_PARAMS = ['accessKeyId', 'secretAccessKey', 'region']; export default function amplifyConfigure(settings: AmplifyConfiguration) { const s = { ...defaultSettings, ...settings }; const missingParam = MANDATORY_PARAMS.filter(p => !Object.keys(s).includes(p)); @@ -22,12 +38,15 @@ export default function amplifyConfigure(settings: AmplifyConfiguration) { } return new Promise((resolve, reject) => { - spawn(getCLIPath(), ['configure'], { stripColors: true }) + const chain = spawn(getCLIPath(), ['configure'], { stripColors: true }) .wait('Sign in to your AWS administrator account:') .wait('Press Enter to continue') .sendCarriageReturn() - .wait('Specify the AWS Region') - .sendCarriageReturn() + .wait('Specify the AWS Region'); + + singleSelect(chain, s.region, regionOptions); + + chain .wait('user name:') .sendCarriageReturn() .wait('Press Enter to continue') diff --git a/packages/amplify-e2e-tests/src/configure_tests.ts b/packages/amplify-e2e-tests/src/configure_tests.ts index a5ba5572a2c..b56a37b300d 100644 --- a/packages/amplify-e2e-tests/src/configure_tests.ts +++ b/packages/amplify-e2e-tests/src/configure_tests.ts @@ -5,13 +5,15 @@ async function setupAmplify() { if (isCI()) { const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID; const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY; - if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY) { - throw new Error('Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in .env'); + const REGION = process.env.CLI_REGION; + if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !REGION) { + throw new Error('Please set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and CLI_REGION in .env'); } await configure({ accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY, profileName: 'amplify-integ-test-user', + region: REGION, }); } else { console.log('AWS Profile is already configured'); diff --git a/packages/amplify-e2e-tests/src/utils/selectors.ts b/packages/amplify-e2e-tests/src/utils/selectors.ts new file mode 100644 index 00000000000..56a8485d8fb --- /dev/null +++ b/packages/amplify-e2e-tests/src/utils/selectors.ts @@ -0,0 +1,20 @@ +import { ExecutionContext } from 'amplify-e2e-core'; + +export const moveDown = (chain: ExecutionContext, nMoves: number) => + Array.from(Array(nMoves).keys()).reduce((chain, _idx) => chain.send('j'), chain); + +export const moveUp = (chain: ExecutionContext, nMoves: number) => + Array.from(Array(nMoves).keys()).reduce((chain, _idx) => chain.send('k'), chain); + +export const singleSelect = (chain: ExecutionContext, item: T, allChoices: T[]) => multiSelect(chain, [item], allChoices); + +export const multiSelect = (chain: ExecutionContext, items: T[], allChoices: T[]) => + items + .map(item => allChoices.indexOf(item)) + .filter(idx => idx > -1) + .sort() + // calculate the diff with the latest, since items are sorted, always positive + // represents the numbers of moves down we need to make to selection + .reduce((diffs, move) => (diffs.length > 0 ? [...diffs, move - diffs[diffs.length - 1]] : [move]), [] as number[]) + .reduce((chain, move) => moveDown(chain, move).send(' '), chain) + .sendCarriageReturn(); \ No newline at end of file diff --git a/packages/amplify-provider-awscloudformation/lib/aws-regions.js b/packages/amplify-provider-awscloudformation/lib/aws-regions.js index 515ecb49643..1e6f289bb15 100644 --- a/packages/amplify-provider-awscloudformation/lib/aws-regions.js +++ b/packages/amplify-provider-awscloudformation/lib/aws-regions.js @@ -1,3 +1,6 @@ +// *** NOTE! *** +// If updating this list, also update the corresponding list in amplify-e2e-tests/src/configure/index.ts +// *** NOTE! *** const regionMappings = { 'us-east-1': 'US East (N. Virginia)', 'us-east-2': 'US East (Ohio)',