Skip to content

Commit

Permalink
ci: update migration tests with updated versions, version checks and …
Browse files Browse the repository at this point in the history
…env paths (aws-amplify#8887)

* test: update migration tests with v5.2 and v6.1

* Test/migration fix (#1)

* ci: remove env variables for migration related tests

* test: migration test fixes

Co-authored-by: SwaySway <7465495+SwaySway@users.noreply.github.com>
Co-authored-by: AmmarKarachi <ammkara@dev-dsk-ammkara-2a-8b7d2720.us-west-2.amazon.com>

* test: update test configs to use v5 & v6, remove latest tests, add version check

* refactor(amplify-migration-tests): update comments

* fix: udpate correct version in allowed version list and correct names in split e2e

Co-authored-by: Ammar <56042290+ammarkarachi@users.noreply.github.com>
Co-authored-by: AmmarKarachi <ammkara@dev-dsk-ammkara-2a-8b7d2720.us-west-2.amazon.com>
  • Loading branch information
3 people authored Nov 19, 2021
1 parent acfefd4 commit a59cf94
Show file tree
Hide file tree
Showing 23 changed files with 336 additions and 130 deletions.
48 changes: 24 additions & 24 deletions .circleci/config.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ jobs:
# - clean_e2e_resources:
# os: << parameters.os >>

amplify_migration_tests_v4:
amplify_migration_tests_v5:
<<: *defaults
steps:
- attach_workspace:
Expand All @@ -300,12 +300,12 @@ jobs:
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- run:
name: Run tests migrating from CLI v4.0.0
name: Run tests migrating from CLI v5.2.0
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
retry yarn run migration_v4.0.0 --maxWorkers=3 $TEST_SUITE
retry yarn run migration_v5.2.0 --maxWorkers=3 $TEST_SUITE
no_output_timeout: 90m
- run: *scan_e2e_test_artifacts
- store_test_results:
Expand All @@ -314,24 +314,24 @@ jobs:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
working_directory: ~/repo

amplify_migration_tests_non_multi_env_layers:
<<: *defaults
amplify_migration_tests_v6:
environment:
AMPLIFY_PATH: /home/circleci/.npm-global/lib/node_modules/@aws-amplify/cli/bin/amplify
<<: *defaults
steps:
- attach_workspace:
at: ./
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ arch }}
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- run:
name: Run tests migrating from CLI v4.28.2
name: Run tests migrating from CLI v6.1.0
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
retry yarn run migration_v4.28.2_nonmultienv_layers --maxWorkers=3 $TEST_SUITE
retry yarn run migration_v6.1.0 --maxWorkers=3 $TEST_SUITE
no_output_timeout: 90m
- run: *scan_e2e_test_artifacts
- store_test_results:
Expand All @@ -340,24 +340,24 @@ jobs:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
working_directory: ~/repo

amplify_migration_tests_multi_env_layers:
amplify_migration_tests_non_multi_env_layers:
<<: *defaults
environment:
AMPLIFY_PATH: /home/circleci/.npm-global/lib/node_modules/@aws-amplify/cli/bin/amplify
steps:
- attach_workspace:
at: ./
- restore_cache:
key: amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ arch }}
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ arch }}
- run:
name: Run tests migrating from CLI v4.52.0
name: Run tests migrating from CLI v4.28.2
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
retry yarn run migration_v4.52.0_multienv_layers --maxWorkers=3 $TEST_SUITE
retry yarn run migration_v4.28.2_nonmultienv_layers --maxWorkers=3 $TEST_SUITE
no_output_timeout: 90m
- run: *scan_e2e_test_artifacts
- store_test_results:
Expand All @@ -366,10 +366,10 @@ jobs:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
working_directory: ~/repo

amplify_migration_tests_latest:
amplify_migration_tests_multi_env_layers:
<<: *defaults
environment:
AMPLIFY_PATH: /home/circleci/.npm-global/lib/node_modules/@aws-amplify/cli/bin/amplify
<<: *defaults
steps:
- attach_workspace:
at: ./
Expand All @@ -378,12 +378,12 @@ jobs:
- restore_cache:
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
- run:
name: Run tests migrating from latest CLI
name: Run tests migrating from CLI v4.52.0
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
retry yarn run migration --maxWorkers=3 $TEST_SUITE
retry yarn run migration_v4.52.0_multienv_layers --maxWorkers=3 $TEST_SUITE
no_output_timeout: 90m
- run: *scan_e2e_test_artifacts
- store_test_results:
Expand Down Expand Up @@ -762,7 +762,7 @@ workflows:
- /run-e2e\/.*/
requires:
- build_pkg_binaries
- amplify_migration_tests_latest:
- amplify_migration_tests_v6:
context:
- amplify-ecr-image-pull
- e2e-auth-credentials
Expand All @@ -778,7 +778,7 @@ workflows:
- build
# post-steps:
# - run: *clean_e2e_resources
- amplify_migration_tests_v4:
- amplify_migration_tests_v5:
context:
- amplify-ecr-image-pull
- e2e-auth-credentials
Expand Down Expand Up @@ -864,8 +864,8 @@ workflows:
requires:
- amplify_e2e_tests
- amplify_e2e_tests_pkg
- amplify_migration_tests_latest
- amplify_migration_tests_v4
- amplify_migration_tests_v6
- amplify_migration_tests_v5

- deploy:
context:
Expand All @@ -880,8 +880,8 @@ workflows:
- amplify_e2e_tests_pkg
- amplify_sudo_install_test
- amplify_console_integration_tests
- amplify_migration_tests_latest
- amplify_migration_tests_v4
- amplify_migration_tests_v6
- amplify_migration_tests_v5
- amplify_migration_tests_non_multi_env_layers
- amplify_migration_tests_multi_env_layers
- github_prerelease_install_sanity_check
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/categories/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export function apiGqlCompile(cwd: string, testingWithLatestCodebase: boolean =
});
}

interface AddApiOptions {
export interface AddApiOptions {
apiName: string;
testingWithLatestCodebase: boolean;
}

const defaultOptions: AddApiOptions = {
export const defaultOptions: AddApiOptions = {
apiName: '\r',
testingWithLatestCodebase: false,
};
Expand Down
5 changes: 3 additions & 2 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,16 @@ export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise<
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
.wait('Which redirect signin URIs do you want to edit?')
.send(' ')
.sendCtrlA()
.sendCarriageReturn()
.wait(`Update ${settings.signinUrl}`)
.sendCarriageReturn()
.send(settings.updatesigninUrl)
.sendCarriageReturn()
.wait('Do you want to add redirect signin URIs?')
.sendConfirmNo()
.wait('Which redirect signout URIs do you want to edit?')
.send(' ')
.sendCtrlA()
.sendCarriageReturn()
.wait(`Update ${settings.signoutUrl}`)
.send(settings.updatesignoutUrl)
Expand Down
34 changes: 33 additions & 1 deletion packages/amplify-e2e-core/src/categories/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,44 @@ export function addDDBWithTrigger(cwd: string, settings: { ddbResourceName?: str

export function updateDDBWithTrigger(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['update', 'storage'], { cwd, stripColors: true })
spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.sendKeyDown()
.sendCarriageReturn()
.wait('Specify the resource that you would want to update')
.sendCarriageReturn()
.wait('Would you like to add another column')
.sendConfirmNo()
.wait('Do you want to add global secondary indexes to your table')
.sendConfirmNo()
.wait('Do you want to add a Lambda Trigger for your Table')
.sendConfirmYes()
.wait('Select from the following options')
.sendKeyDown()
.sendCarriageReturn()
.wait('Do you want to edit the local')
.sendLine('n')
.sendEof()
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}

export function updateDDBWithTriggerMigration(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'storage'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services')
.sendKeyDown()
.sendCarriageReturn()
.wait('Specify the resource that you would want to update')
.sendCarriageReturn()
.wait('Do you want to migrate storage resource')
.sendConfirmYes()
.wait('Would you like to add another column')
.sendConfirmNo()
.wait('Do you want to add global secondary indexes to your table')
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/init/deleteProject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nspawn as spawn, retry, getCLIPath, describeCloudFormationStack } from '..';
import { getBackendAmplifyMeta } from '../utils';

export const deleteProject = async (cwd: string, profileConfig?: any): Promise<void> => {
export const deleteProject = async (cwd: string, profileConfig?: any, usingLatestCodebase = false): Promise<void> => {
// Read the meta from backend otherwise it could fail on non-pushed, just initialized projects
const { StackName: stackName, Region: region } = getBackendAmplifyMeta(cwd).providers.awscloudformation;
await retry(
Expand All @@ -10,7 +10,7 @@ export const deleteProject = async (cwd: string, profileConfig?: any): Promise<v
);
return new Promise((resolve, reject) => {
const noOutputTimeout = 1000 * 60 * 20; // 20 minutes;
spawn(getCLIPath(), ['delete'], { cwd, stripColors: true, noOutputTimeout })
spawn(getCLIPath(usingLatestCodebase), ['delete'], { cwd, stripColors: true, noOutputTimeout })
.wait('Are you sure you want to continue?')
.sendConfirmYes()
.wait('Project deleted locally.')
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/init/overrideStack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { nspawn as spawn, getCLIPath } from '..';

export function amplifyOverrideRoot(cwd: string, settings: {}) {
export function amplifyOverrideRoot(cwd: string, settings: { testingWithLatestCodebase? : boolean }) {
return new Promise((resolve, reject) => {
const args = ['override', 'project'];

spawn(getCLIPath(), args, { cwd, stripColors: true })
spawn(getCLIPath(settings.testingWithLatestCodebase), args, { cwd, stripColors: true })
.wait('Do you want to edit override.ts file now?')
.sendConfirmNo()
.sendEof()
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('amplify init', () => {
expect(DeploymentBucketName).toBeAS3Bucket(DeploymentBucketName);

// override new env
await amplifyOverrideRoot(projRoot, {});
await amplifyOverrideRoot(projRoot, { testingWithLatestCodebase: true});
const srcOverrideFilePath = path.join(__dirname, '..', '..', 'overrides', 'override-root.ts');
const destOverrideFilePath = path.join(projRoot, 'amplify', 'backend', 'awscloudformation', 'override.ts');
fs.copyFileSync(srcOverrideFilePath, destOverrideFilePath);
Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-migration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
"private": true,
"scripts": {
"build-tests": "tsc --build tsconfig.tests.json",
"migration_v4.0.0": "npm run setup-profile 4.0.0 && jest --testPathIgnorePatterns=auth.deployment.secrets\\|layer-migration\\|overrides --verbose --passWithNoTests",
"migration_v4.28.2_nonmultienv_layers": "npm run setup-profile 4.28.2 && jest src/__tests__/migration_tests/lambda-layer-migration/layer-migration.test.ts --verbose --passWithNoTests",
"migration_v4.52.0_multienv_layers": "npm run setup-profile 4.52.0 && jest src/__tests__/migration_tests/lambda-layer-migration/layer-migration.test.ts --verbose --passWithNoTests",
"migration_v6.0.1": "npm run setup-profile 6.0.1 && jest src/__tests__/migration_tests/overrides/auth-migration.test.ts --verbose --passWithNoTests",
"migration": "npm run setup-profile latest && jest --testPathIgnorePatterns=auth.deployment.secrets\\|layer-migration --verbose --passWithNoTests",
"migration_v5.2.0": "npm run setup-profile 5.2.0 && jest --testPathIgnorePatterns=auth.deployment.secrets\\|layer-migration\\|overrides --verbose --passWithNoTests",
"migration_v6.1.0": "npm run setup-profile 6.1.0 && jest --testPathIgnorePatterns=auth.deployment.secrets\\|layer-migration --verbose --passWithNoTests",
"setup-profile": "ts-node ./src/configure_tests.ts"
},
"dependencies": {
Expand All @@ -32,6 +31,7 @@
"esm": "^3.2.25",
"fs-extra": "^8.1.0",
"graphql-transformer-core": "7.2.2",
"lodash": "^4.17.21",
"rimraf": "^3.0.0",
"uuid": "^8.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,37 @@ import { UpdateAuthRequest } from 'amplify-headless-interface';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as _ from 'lodash';
import { versionCheck } from '../../../migration-helpers';
import { versionCheck, allowedVersionsToMigrateFrom } from '../../../migration-helpers';

const defaultSettings = {
name: 'authMigration',
};
describe('amplify auth migration', () => {
let projRoot: string;

beforeAll(async () => {
const migrateFromVersion = { v: 'unintialized' };
const migrateToVersion = { v: 'unintialized' };
await versionCheck(process.cwd(), false, migrateFromVersion);
await versionCheck(process.cwd(), true, migrateToVersion);
expect(migrateFromVersion.v).not.toEqual(migrateToVersion.v);
expect(allowedVersionsToMigrateFrom).toContain(migrateFromVersion.v);
});

beforeEach(async () => {
projRoot = await createNewProjectDir('auth_migration');
});

afterEach(async () => {
const metaFilePath = path.join(projRoot, 'amplify', '#current-cloud-backend', 'amplify-meta.json');
if (fs.existsSync(metaFilePath)) {
await deleteProject(projRoot);
await deleteProject(projRoot, undefined, true);
}
deleteProjectDir(projRoot);
});
it('...should init a project and add auth with a custom trigger, and then update to remove the custom js while leaving the other js', async () => {
// init, add and push auth with installed cli
await initJSProjectWithProfile(projRoot, defaultSettings);
await versionCheck(projRoot, false);
await versionCheck(projRoot, true);
await addAuthWithCustomTrigger(projRoot, {});
await amplifyPushAuth(projRoot);
const meta = getProjectMeta(projRoot);
Expand Down Expand Up @@ -89,8 +97,6 @@ describe('amplify auth migration', () => {
it('...should init a project and add auth with default, and then update with latest and push', async () => {
// init, add and push auth with installed cli
await initJSProjectWithProfile(projRoot, defaultSettings);
await versionCheck(projRoot, false);
await versionCheck(projRoot, true);
await addAuthWithDefault(projRoot, {});
await amplifyPushAuth(projRoot);
const meta = getProjectMeta(projRoot);
Expand All @@ -107,8 +113,6 @@ describe('amplify auth migration', () => {

it('...should init an android project and add customAuth flag, and remove flag when custom auth triggers are removed upon update ', async () => {
await initAndroidProjectWithProfile(projRoot, defaultSettings);
await versionCheck(projRoot, false);
await versionCheck(projRoot, true);
await addAuthWithRecaptchaTrigger(projRoot, {});
await amplifyPushAuth(projRoot);
let meta = getAwsAndroidConfig(projRoot);
Expand Down Expand Up @@ -138,8 +142,6 @@ describe('amplify auth migration', () => {
updatesignoutUrl: 'http://localhost:3004/',
};
await initAndroidProjectWithProfile(projRoot, defaultSettings);
await versionCheck(projRoot, false);
await versionCheck(projRoot, true);
await addAuthWithSignInSignOutUrl(projRoot, settings);
const amplifyMeta = getBackendAmplifyMeta(projRoot);
const authResourceName = Object.keys(amplifyMeta.auth).filter(resourceName => amplifyMeta.auth[resourceName].service === 'Cognito')[0];
Expand All @@ -149,7 +151,7 @@ describe('amplify auth migration', () => {
category: 'auth',
service: 'cognito',
};
await updateAuthSignInSignOutUrl(projRoot, { testingWithLatestCodebase: true, overrides: overridesObj });
await updateAuthSignInSignOutUrl(projRoot, { ...settings, testingWithLatestCodebase: true, overrides: overridesObj });
});

it('updates existing auth resource', async () => {
Expand All @@ -175,8 +177,6 @@ describe('amplify auth migration', () => {
};

await initJSProjectWithProfile(projRoot, defaultSettings);
await versionCheck(projRoot, false);
await versionCheck(projRoot, true);
await addAuthWithDefault(projRoot, {});
await updateHeadlessAuth(projRoot, updateAuthRequest, {});
await amplifyPushAuth(projRoot, true);
Expand Down
Loading

0 comments on commit a59cf94

Please sign in to comment.