Skip to content

Commit

Permalink
fix: select us-east-2 in integ tests (#3992)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle authored Apr 17, 2020
1 parent 74281cc commit ed48cf5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .circleci/amplify_init.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion packages/amplify-e2e-tests/src/categories/api.ts
Original file line number Diff line number Diff line change
@@ -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}`;
Expand Down
20 changes: 1 addition & 19 deletions packages/amplify-e2e-tests/src/categories/function.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 = <T>(chain: ExecutionContext, item: T, allChoices: T[]) => multiSelect(chain, [item], allChoices);

export const multiSelect = <T>(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,
Expand Down
29 changes: 24 additions & 5 deletions packages/amplify-e2e-tests/src/configure/index.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions packages/amplify-e2e-tests/src/configure_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 20 additions & 0 deletions packages/amplify-e2e-tests/src/utils/selectors.ts
Original file line number Diff line number Diff line change
@@ -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 = <T>(chain: ExecutionContext, item: T, allChoices: T[]) => multiSelect(chain, [item], allChoices);

export const multiSelect = <T>(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();
Original file line number Diff line number Diff line change
@@ -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)',
Expand Down

0 comments on commit ed48cf5

Please sign in to comment.