Skip to content

Commit

Permalink
test(amplify-migration-tests): fix cci test failures, add version hel…
Browse files Browse the repository at this point in the history
…per (#6550)

* test: add some version debugging

* test: fix tests failures in cci, add version check helper

* chore: remove unused var

* fix: headless parameter usage

* fix: remove unnecessary call to loadConfiguration

* fix: revert await removal
  • Loading branch information
jhockett committed Feb 5, 2021
1 parent 8647486 commit a16e8b8
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
deleteProjectDir,
isDeploymentSecretForEnvExists,
} from 'amplify-e2e-core';
import { initJSProjectWithProfile } from '../../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../../migration-helpers';

describe('amplify auth add with social', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
deleteProjectDir,
updateApiSchema,
} from 'amplify-e2e-core';
import { initJSProjectWithProfile } from '../../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../../migration-helpers';

describe('amplify key force push', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
deleteProjectDir,
updateApiSchema,
} from 'amplify-e2e-core';
import { initJSProjectWithProfile } from '../../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../../migration-helpers';

describe('amplify searchable migration', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { existsSync } from 'fs';
import { TRANSFORM_CURRENT_VERSION } from 'graphql-transformer-core';
import { join } from 'path';
import { initJSProjectWithProfile } from '../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../migration-helpers';

describe('api migration update test', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'amplify-e2e-core';
import * as fs from 'fs-extra';
import { join } from 'path';
import { initJSProjectWithProfile } from '../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../migration-helpers';

describe('amplify auth migration', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
validateLayerMetadata,
} from 'amplify-e2e-core';
import { v4 as uuid } from 'uuid';
import { initJSProjectWithProfile } from '../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../migration-helpers';

describe('amplify function migration', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getProjectMeta,
updateDDBWithTrigger,
} from 'amplify-e2e-core';
import { initJSProjectWithProfile } from '../../migration-helpers/init';
import { initJSProjectWithProfile } from '../../migration-helpers';

describe('amplify add/update storage(DDB)', () => {
let projRoot: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getCLIPath, nspawn as spawn } from 'amplify-e2e-core';

export function versionCheck(cwd: string, testingWithLatestCodebase = false) {
return new Promise((resolve, reject) => {
spawn(getCLIPath(testingWithLatestCodebase), ['-v'], { cwd, stripColors: true }).run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './init';
export * from './check-version';
16 changes: 5 additions & 11 deletions packages/amplify-migration-tests/src/migration-helpers/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addCircleCITags, getCLIPath, isCI, nspawn as spawn } from 'amplify-e2e-core';
import { addCircleCITags, getCLIPath, nspawn as spawn } from 'amplify-e2e-core';

const defaultSettings = {
name: '\r',
Expand Down Expand Up @@ -30,7 +30,7 @@ export function initJSProjectWithProfile(cwd: string, settings: Object, testingW
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(testingWithLatestCodebase), ['init'], { cwd, stripColors: true, env })
spawn(getCLIPath(testingWithLatestCodebase), ['init'], { cwd, stripColors: true, env })
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Enter a name for the environment')
Expand All @@ -49,15 +49,9 @@ export function initJSProjectWithProfile(cwd: string, settings: Object, testingW
.sendLine(s.buildCmd)
.wait('Start Command:')
.sendCarriageReturn()
.wait('Using default provider awscloudformation');

if (testingWithLatestCodebase || !isCI()) {
chain.wait('Select the authentication method you want to use:').sendCarriageReturn();
} else {
chain.wait('Do you want to use an AWS profile?').sendLine('y');
}

chain
.wait('Using default provider awscloudformation')
.wait(/(Select the authentication method you want to use|Do you want to use an AWS profile)/)
.sendCarriageReturn()
.wait('Please choose the profile you want to use')
.sendLine(s.profileName)
.wait('Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,24 @@ export async function getAwsConfig(context: $TSContext): Promise<AwsConfig> {

async function determineAuthFlow(context: $TSContext, projectConfig?: ProjectConfig): Promise<AuthFlowConfig> {
// Check for headless parameters
let { accessKeyId, profileName, region, secretAccessKey, useProfile } = _.get(
context,
['exeInfo', 'inputParams', 'awscloudformation', 'config'],
{},
);
// TODO fix how input parameters are handled
let cfnParams = _.get(context, ['exeInfo', 'inputParams', 'awscloudformation'], undefined);
if (cfnParams?.config) {
cfnParams = cfnParams.config;
}
let {
accessKeyId,
profileName,
region,
secretAccessKey,
useProfile,
}: {
accessKeyId: string;
profileName: string;
region: string;
secretAccessKey: string;
useProfile: boolean;
} = cfnParams || {};

if (context?.exeInfo?.inputParams?.yes) {
if (process.env.AWS_SDK_LOAD_CONFIG) {
Expand Down
6 changes: 2 additions & 4 deletions packages/amplify-provider-awscloudformation/src/delete-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ const path = require('path');

const Cloudformation = require('./aws-utils/aws-cfn');
const { S3 } = require('./aws-utils/aws-s3');
const { loadConfigurationForEnv } = require('./configuration-manager');
const { deleteEnv } = require('./amplify-service-manager');
const { S3BackendZipFileName, ProviderName } = require('./constants');
const { downloadZip, extractZip } = require('./zip-util');

async function run(context, envName, deleteS3) {
const awsConfig = await loadConfigurationForEnv(context, envName);
const cfn = await new Cloudformation(context, null, awsConfig);
const cfn = await new Cloudformation(context, null);
const s3 = await S3.getInstance(context, {});
let removeBucket = false;
let deploymentBucketName;
Expand Down Expand Up @@ -45,7 +43,7 @@ async function run(context, envName, deleteS3) {
await s3.deleteS3Bucket(storageCategoryBucketName);
}

await deleteEnv(context, envName, awsConfig);
await deleteEnv(context, envName);

if (removeBucket && deploymentBucketName) {
await s3.deleteS3Bucket(deploymentBucketName);
Expand Down

0 comments on commit a16e8b8

Please sign in to comment.