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

test(api): use beta layer for e2e tests #2102

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ describe('transformGraphQLSchemaV2', () => {
resourcesToBeUpdated: [],
allResources: [],
})),
getProjectMeta: jest.fn(() => ({
providers: {
awscloudformation: {
Region: 'us-east-1',
},
},
})),
},
parameters: {
options: { resourcesDir: 'resourceDir', projectDirectory: __dirname },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const PARAMETERS_FILENAME = 'parameters.json';
const SCHEMA_FILENAME = 'schema.graphql';
const SCHEMA_DIR_NAME = 'schema';
const PROVIDER_NAME = 'awscloudformation';
const LAYER_MAPPING_URL = 'https://amplify-rds-layer-resources.s3.amazonaws.com/rds-layer-mapping.json';
const USE_BETA_SQL_LAYER = 'use-beta-sql-layer';

/**
* Transform GraphQL Schema
Expand Down Expand Up @@ -339,8 +339,8 @@ const buildAPIProject = async (context: $TSContext, opts: TransformerProjectOpti

checkForUnsupportedDirectives(schema, { dataSourceStrategies });

const rdsLayerMapping = await getRDSLayerMapping();

const useBetaSqlLayer = context?.input?.options?.[USE_BETA_SQL_LAYER] ?? false;
const rdsLayerMapping = await getRDSLayerMapping(context, useBetaSqlLayer);
const transformManager = new TransformManager(
opts.overrideConfig,
hasIamAuth(opts.authConfig),
Expand Down Expand Up @@ -394,13 +394,21 @@ export const getUserOverridenSlots = (userDefinedSlots: Record<string, UserDefin
.flat()
.filter((slotName) => slotName !== undefined);

const getRDSLayerMapping = async (): Promise<RDSLayerMapping> => {
const response = await fetch(LAYER_MAPPING_URL);
const getRDSLayerMapping = async (context: $TSContext, useBetaSqlLayer = false): Promise<RDSLayerMapping> => {
const bucket = `${ResourceConstants.RESOURCES.SQLLayerVersionManifestBucket}${useBetaSqlLayer ? '-beta' : ''}`;
const region = context.amplify.getProjectMeta().providers.awscloudformation.Region;
const url = `https://${bucket}.s3.amazonaws.com/${ResourceConstants.RESOURCES.SQLLayerVersionManifestKeyPrefix}${region}`;
const response = await fetch(url);
if (response.status === 200) {
const result = await response.json();
return result as RDSLayerMapping;
const result = await response.text();
const mapping = {
[region]: {
layerRegion: result,
},
};
return mapping as RDSLayerMapping;
} else {
throw new Error(`Unable to retrieve layer mapping from ${LAYER_MAPPING_URL} with status code ${response.status}.`);
throw new Error(`Unable to retrieve layer mapping from ${url} with status code ${response.status}.`);
}
};

Expand Down
11 changes: 10 additions & 1 deletion packages/amplify-e2e-core/src/init/amplifyPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function amplifyPush(
testingWithLatestCodebase = false,
settings?: {
skipCodegen?: boolean;
useBetaSqlLayer?: boolean;
},
): Promise<void> {
return new Promise((resolve, reject) => {
Expand All @@ -49,7 +50,15 @@ export function amplifyPush(
}
});
// Test amplify push
const pushCommands = spawn(getCLIPath(testingWithLatestCodebase), ['push'], { cwd, stripColors: true, noOutputTimeout: pushTimeoutMS })
const pushOptions = ['push'];
if (settings?.useBetaSqlLayer) {
pushOptions.push('--use-beta-sql-layer');
sundersc marked this conversation as resolved.
Show resolved Hide resolved
}
const pushCommands = spawn(getCLIPath(testingWithLatestCodebase), pushOptions, {
cwd,
stripColors: true,
noOutputTimeout: pushTimeoutMS,
})
.wait('Are you sure you want to continue?')
.sendConfirmYes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
import { ResourceConstants } from 'graphql-transformer-common';
import { getDefaultStrategyNameForDbType, getResourceNamesForStrategyName, normalizeDbType } from '@aws-amplify/graphql-transformer-core';
import { ModelDataSourceStrategySqlDbType } from '@aws-amplify/graphql-transformer-interfaces';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -198,7 +199,9 @@ describe('RDS Tests', () => {
expect(rdsPatchingSubscription.Properties.FilterPolicy).toBeDefined();
expect(rdsPatchingSubscription.Properties.FilterPolicy.Region).toBeDefined();

await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

// Get the AppSync API details after deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { setupUser, getUserPoolId, signInUser, configureAmplify } from '../schema-api-directives';
import { GQLQueryHelper } from '../query-utils/gql-helper';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -123,7 +124,9 @@ describe('RDS Cognito userpool provider Auth tests', () => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, ImportedRDSType.MYSQL), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName, moderatorGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const userPoolId = getUserPoolId(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
setupRDSInstanceAndData,
sleep,
updateAuthAddUserGroups,
amplifyPushWithoutCodegen,
getProjectMeta,
} from 'amplify-category-api-e2e-core';
import { existsSync, writeFileSync, removeSync } from 'fs-extra';
Expand All @@ -38,6 +37,7 @@ import {
} from '../schema-api-directives';
import { gql } from 'graphql-tag';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -125,7 +125,10 @@ describe('RDS OIDC provider Auth tests', () => {

await addAuthWithPreTokenGenerationTrigger(projRoot);
updatePreAuthTrigger(projRoot, 'user_id');
await amplifyPushWithoutCodegen(projRoot);
await amplifyPush(projRoot, false, {
skipCodegen: true,
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});

await addApi(projRoot, {
'OpenID Connect': {
Expand Down Expand Up @@ -156,7 +159,9 @@ describe('RDS OIDC provider Auth tests', () => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, ImportedRDSType.MYSQL), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const userPoolId = getUserPoolId(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { setupUser, getUserPoolId, signInUser, configureAmplify, getConfiguredAppsyncClientCognitoAuth } from '../schema-api-directives';
import { gql } from 'graphql-tag';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -135,7 +136,9 @@ describe('RDS Cognito userpool provider Auth tests', () => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, ImportedRDSType.MYSQL), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const userPoolId = getUserPoolId(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
import gql from 'graphql-tag';
import { getDefaultStrategyNameForDbType, getResourceNamesForStrategyName, normalizeDbType } from '@aws-amplify/graphql-transformer-core';
import { ModelDataSourceStrategySqlDbType } from '@aws-amplify/graphql-transformer-interfaces';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -54,7 +55,9 @@ describe('RDS Model Directive', () => {
projRoot = await createNewProjectDir('rdsmodelapi');
await initProjectAndImportSchema();
modifySchema();
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

await verifyApiEndpointAndCreateClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
import { gql } from 'graphql-tag';
import { ObjectTypeDefinitionNode, parse } from 'graphql';
import { GQLQueryHelper } from '../query-utils/gql-helper';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand All @@ -43,7 +44,9 @@ describe('RDS Relational Directives', () => {
beforeAll(async () => {
projRoot = await createNewProjectDir('rdsmodelapi');
await initProjectAndImportSchema();
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const meta = getProjectMeta(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
import { GQLQueryHelper } from '../query-utils/gql-helper';
import { gql } from 'graphql-transformer-core';
import { ObjectTypeDefinitionNode, parse } from 'graphql';
import { SQL_TESTS_USE_BETA } from '../rds-v2-tests-common/sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand All @@ -43,7 +44,9 @@ describe('RDS Relational Directives', () => {
beforeAll(async () => {
projRoot = await createNewProjectDir('rdsmodelapi');
await initProjectAndImportSchema();
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const meta = getProjectMeta(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Auth, API } from 'aws-amplify';
import { getUserPoolId } from '../schema-api-directives/authHelper';
import { reconfigureAmplifyAPI, withTimeOut } from '../utils/api';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -70,13 +71,16 @@ export const testApiKeyLambdaIamAuthSubscription = (engine: ImportedRDSType, que
beforeAll(async () => {
projRoot = await createNewProjectDir(projName);
await initProjectAndImportSchema();
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});

await apiGqlCompile(projRoot, false, {
forceCompile: true,
});
await amplifyPush(projRoot, false, {
skipCodegen: true,
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for a minute for the VPC endpoints to be live.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import path from 'path';
import { GQLQueryHelper } from '../query-utils/gql-helper';
import { getConfiguredAppsyncClientAPIKeyAuth, getConfiguredAppsyncClientLambdaAuth } from '../schema-api-directives';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -46,7 +47,9 @@ export const testRdsApiKeyAndLambdaAuth = (engine: ImportedRDSType, queries: str
beforeAll(async () => {
projRoot = await createNewProjectDir(projName);
await initProjectAndImportSchema();
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const meta = getProjectMeta(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../rds-v2-test-utils';
import { setupUser, getUserPoolId, signInUser, configureAmplify } from '../schema-api-directives';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -129,7 +130,9 @@ export const testCustomClaimsRefersTo = (engine: ImportedRDSType): void => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, engine), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(2 * 60 * 1000); // Wait for 2 minutes for the VPC endpoints to be live.

const userPoolId = getUserPoolId(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getConfiguredAppsyncClientLambdaAuth,
} from '../schema-api-directives';
import { getUserPoolId } from '../schema-api-directives/authHelper';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -158,7 +159,9 @@ export const testRdsIamAuth = (engine: ImportedRDSType, queries: string[]): void
useVpc: true,
apiExists: true,
});
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});

const schema = /* GraphQL */ `
input AMPLIFY {
Expand Down Expand Up @@ -194,6 +197,7 @@ export const testRdsIamAuth = (engine: ImportedRDSType, queries: string[]): void
await enableUserPoolUnauthenticatedAccess(projRoot);
await amplifyPush(projRoot, false, {
skipCodegen: true,
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
setupRDSInstanceAndData,
sleep,
updateAuthAddUserGroups,
amplifyPushWithoutCodegen,
getProjectMeta,
} from 'amplify-category-api-e2e-core';
import { existsSync, writeFileSync, removeSync } from 'fs-extra';
Expand Down Expand Up @@ -39,6 +38,7 @@ import {
} from '../schema-api-directives';
import { gql } from 'graphql-tag';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -129,7 +129,10 @@ export const testOIDCAuth = (engine: ImportedRDSType): void => {

await addAuthWithPreTokenGenerationTrigger(projRoot);
updatePreAuthTrigger(projRoot, 'user_id');
await amplifyPushWithoutCodegen(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
skipCodegen: true,
});

await addApi(projRoot, {
'OpenID Connect': {
Expand Down Expand Up @@ -161,7 +164,9 @@ export const testOIDCAuth = (engine: ImportedRDSType): void => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, engine), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(1 * 60 * 1000); // Wait for a minute for the VPC endpoints to be live.
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { setupUser, getUserPoolId, signInUser, configureAmplify, getConfiguredAppsyncClientCognitoAuth } from '../schema-api-directives';
import { gql } from 'graphql-tag';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { SQL_TESTS_USE_BETA } from './sql-e2e-config';

// to deal with bug in cognito-identity-js
(global as any).fetch = require('node-fetch');
Expand Down Expand Up @@ -139,7 +140,9 @@ export const testUserPoolAuth = (engine: ImportedRDSType): void => {
writeFileSync(rdsSchemaFilePath, appendAmplifyInput(schema, engine), 'utf8');

await updateAuthAddUserGroups(projRoot, [adminGroupName, devGroupName]);
await amplifyPush(projRoot);
await amplifyPush(projRoot, false, {
useBetaSqlLayer: SQL_TESTS_USE_BETA,
});
await sleep(30 * 1000); // Wait for 30 seconds for the VPC endpoints to be live.

const userPoolId = getUserPoolId(projRoot);
Expand Down
Loading