Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic e2e integration test flow for migration tool #13946

Merged
merged 6 commits into from
Oct 1, 2024

Conversation

Sanayshah2
Copy link
Contributor

@Sanayshah2 Sanayshah2 commented Sep 27, 2024

Description of changes

  1. Added basic e2e integration test flow which does the following steps -
  • Create an app with gen 1 backend
  • Amplify push
  • Assert completion
  • Running codegen using npx @aws-amplify/migrate to-gen-2 generate-code
  • Deploy the generated gen2 code using npx ampx sandbox
  • Assert the deployed gen2 resource is identical to the one deployed in gen 1
  1. Isolated migration-codegen-e2e related tests which can be run locally using yarn e2e-migration from the root

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Sanayshah2 Sanayshah2 requested a review from hoangnbn September 28, 2024 01:04
@Sanayshah2 Sanayshah2 marked this pull request as ready for review September 28, 2024 01:04
@Sanayshah2 Sanayshah2 requested a review from a team as a code owner September 28, 2024 01:04
Copy link

@hoangnbn hoangnbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! leave some minor comments

@Sanayshah2 Sanayshah2 requested a review from hoangnbn September 30, 2024 20:00
void it('performs full migration codegen flow with Auth backend', async () => {
await setupGen1Project(projRoot, 'CodegenTest');
const { gen1UserPoolId, gen1Region } = await assertGen1Setup(projRoot);
await migrateCodegen(projRoot);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls rename migrateCodegen to generateGen2Code in the next PR.

@Sanayshah2 Sanayshah2 requested a review from sobolk September 30, 2024 21:32
Copy link
Member

@sobolk sobolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it's looking good. Please see comments.

@@ -0,0 +1,23 @@
import path from 'node:path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this file migration_codegen_e2e.test.ts.

We have tests related other "codegen" in the repo.

Comment on lines 29 to 32
} catch (error) {
console.error('Error fetching resource details:', error);
throw error;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all these catch-log-throw blocks, here and below.

As long as something catches this error at the top and prints it somewhere we can infer details from stack trace.

See https://www.google.com/search?q=catch+log+throw .

.runAsync();
}

export async function setupGen1Project(projRoot: string, projectName: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function setupGen1Project(projRoot: string, projectName: string) {
export async function setupAndPushGen1Project(projRoot: string, projectName: string) {

push is heavy long running operation. please be explicit in function name.

Comment on lines 118 to 136
function removeNestedJsonKeys<T extends Record<string, unknown>>(obj: T, keysToRemove: string[]): T {
const result = { ...obj };
keysToRemove.forEach((path) => {
const parts = path.split('.');
let current: Record<string, unknown> = result;
for (let i = 0; i < parts.length - 1; i++) {
const part = parts[i];
if (current[part] === undefined || current[part] === null) {
return; // Path doesn't exist, nothing to delete
}
current = current[part] as Record<string, unknown>;
}
const lastPart = parts[parts.length - 1];
if (current && lastPart in current) {
delete current[lastPart];
}
});
return result;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have lodash in the node_modules.
if we do, consider using https://lodash.com/docs/4.17.15#unset instead.

Comment on lines 145 to 151
export async function migrateCodegen(projRoot: string) {
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed');
}

export async function deployGen2Sandbox(projRoot: string) {
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function migrateCodegen(projRoot: string) {
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed');
}
export async function deployGen2Sandbox(projRoot: string) {
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed');
}
export async function assertMigrateCodegen(projRoot: string) {
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed');
}
export async function assertDeploysGen2Sandbox(projRoot: string) {
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed');
}

Or just get rid of these functions and have run.. and assertions inline in relevant tests. (I'd just inline this, these functions seem too small).

@Sanayshah2 Sanayshah2 requested a review from sobolk October 1, 2024 21:29
@Sanayshah2 Sanayshah2 merged commit 25f8677 into aws-amplify:migrations Oct 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants