Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Dec 4, 2023
1 parent ad080c5 commit e5eaff4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"rimraf": "^5.0.0",
"tsx": "^3.12.6",
"typedoc": "^0.25.3",
"typescript": "~5.2.0",
"typescript": "~5.3.2",
"verdaccio": "^5.24.1"
},
"workspaces": [
Expand Down
32 changes: 22 additions & 10 deletions packages/integration-tests/src/define_backend_template_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Construct } from 'constructs';
/**
* Asserts that the provided template has resources of 'resourceType' with the expected logical IDs
*/
export const assertStableLogicalIds = (
export const assertExpectedLogicalIds = (
template: Template,
resourceType: string,
expectedLogicalIds: string[]
Expand All @@ -22,21 +22,33 @@ export const assertStableLogicalIds = (
};

/**
* Wrapper around `defineBackend` that returns CDK Template objects for each backend resource
* Synthesizes deterministic `defineBackend` CDK templates for each backend resource
*
* Supplies stable CDK context values to the synth process for deterministic synth output
*/
export const defineBackendTemplateHarness: DefineBackendTemplateHarness = <
export const synthesizeBackendTemplates: SynthesizeBackendTemplates = <
T extends Record<string, ConstructFactory<Construct>>
>(
constructFactories: T
) => {
try {
process.env.CDK_CONTEXT_JSON = JSON.stringify({
[CDKContextKey.BACKEND_NAMESPACE]: 'testAppId',
[CDKContextKey.BACKEND_NAME]: 'testBranchName',
[CDKContextKey.DEPLOYMENT_TYPE]: 'branch',
secretLastUpdated: 123456789,
});
return backendTemplatesCollector(constructFactories);
} finally {
delete process.env.CDK_CONTEXT_JSON;
}
};

const backendTemplatesCollector: SynthesizeBackendTemplates = <
T extends Record<string, ConstructFactory<Construct>>
>(
constructFactories: T
) => {
process.env.CDK_CONTEXT_JSON = JSON.stringify({
[CDKContextKey.BACKEND_NAMESPACE]: 'testAppId',
[CDKContextKey.BACKEND_NAME]: 'testBranchName',
[CDKContextKey.DEPLOYMENT_TYPE]: 'branch',
secretLastUpdated: 123456789,
});
if (Object.keys(constructFactories).length === 0) {
throw new Error('constructFactories must have at least one entry');
}
Expand All @@ -55,7 +67,7 @@ export const defineBackendTemplateHarness: DefineBackendTemplateHarness = <
return result as { [K in keyof T]: Template } & { root: Template };
};

type DefineBackendTemplateHarness = <
type SynthesizeBackendTemplates = <
T extends Record<string, ConstructFactory<Construct>>
>(
constructFactories: T
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dataStorageAuthWithTriggers } from '../test-projects/data-storage-auth-with-triggers-ts/amplify/test_factories.js';
import {
assertStableLogicalIds,
defineBackendTemplateHarness,
assertExpectedLogicalIds,
synthesizeBackendTemplates,
} from '../define_backend_template_harness.js';
import { it } from 'node:test';
import { dataWithoutAuth } from '../test-projects/standalone-data-auth-modes/amplify/test_factories.js';
Expand All @@ -15,60 +15,60 @@ import { dataWithoutAuthNoAuthMode } from '../test-projects/standalone-data-sand
*/

void it('data storage auth with triggers', () => {
const templates = defineBackendTemplateHarness(dataStorageAuthWithTriggers);
const templates = synthesizeBackendTemplates(dataStorageAuthWithTriggers);

assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
'auth179371D7',
'data7552DF31',
'function1351588B',
'storage0EC3F24A',
]);

assertStableLogicalIds(templates.auth, 'AWS::Cognito::UserPool', [
assertExpectedLogicalIds(templates.auth, 'AWS::Cognito::UserPool', [
'amplifyAuthUserPool4BA7F805',
]);

assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
'amplifyDataGraphQLAPI42A6FA33',
]);
assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833',
'amplifyDataFunctionDirectiveStackNestedStackFunctionDirectiveStackNestedStackResource1246A302',
'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56',
]);

assertStableLogicalIds(templates.storage, 'AWS::S3::Bucket', [
assertExpectedLogicalIds(templates.storage, 'AWS::S3::Bucket', [
// eslint-disable-next-line spellcheck/spell-checker
'amplifyStorageamplifyStorageBucketC2F702CD',
]);
});

void it('data without auth with lambda auth mode', () => {
const templates = defineBackendTemplateHarness(dataWithoutAuth);
const templates = synthesizeBackendTemplates(dataWithoutAuth);

assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
'data7552DF31',
'function1351588B',
]);
assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
'amplifyDataGraphQLAPI42A6FA33',
]);
assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833',
'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56',
]);
});

void it('data without auth with default auth mode', () => {
const templates = defineBackendTemplateHarness(dataWithoutAuthNoAuthMode);
const templates = synthesizeBackendTemplates(dataWithoutAuthNoAuthMode);

assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
'data7552DF31',
]);
assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [
'amplifyDataGraphQLAPI42A6FA33',
]);
assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [
'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833',
'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56',
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
{ "path": "../client-config" },
{ "path": "../platform-core" }
],
"exclude": ["**/node_modules", "**/lib"]
"exclude": ["**/node_modules", "**/lib", "src/e2e-tests"]
}

0 comments on commit e5eaff4

Please sign in to comment.