Skip to content

Commit b9e298c

Browse files
committed
test: wait for policy propagation
1 parent a7856c9 commit b9e298c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/amplify-e2e-core/src/utils/sdk-calls.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,26 @@ export const getAppSyncApi = async (appSyncApiId: string, region: string) => {
364364
return await service.getGraphqlApi({ apiId: appSyncApiId }).promise();
365365
};
366366

367+
export const waitForAllDataSourceRolesToExist = async (appSyncApiId: string, region: string) => {
368+
const service = new AppSync({ region });
369+
370+
const roles: string[] = [];
371+
let token = undefined;
372+
do {
373+
const result = await service.listDataSources({ apiId: appSyncApiId, nextToken: token }).promise();
374+
token = result.nextToken;
375+
const sources = result.dataSources ?? [];
376+
for (const dataSource of sources.values()) {
377+
if (dataSource.serviceRoleArn) {
378+
roles.push(dataSource.serviceRoleArn);
379+
}
380+
}
381+
} while (token);
382+
383+
const allRolesExist = roles.map((role) => waitForRoleToExist(role, region));
384+
return Promise.all(allRolesExist);
385+
};
386+
367387
export const getCloudWatchLogs = async (region: string, logGroupName: string, logStreamName: string | undefined = undefined) => {
368388
const cloudWatchLogsClient = new CloudWatchLogs({ region, retryDelayOptions: { base: 500 } });
369389

@@ -480,6 +500,11 @@ export const listAttachedRolePolicies = async (roleName: string, region: string)
480500
return (await service.listAttachedRolePolicies({ RoleName: roleName }).promise()).AttachedPolicies;
481501
};
482502

503+
export const waitForRoleToExist = async (roleName: string, region: string) => {
504+
const service = new IAM({ region });
505+
return await service.waitFor('roleExists', { RoleName: roleName }).promise();
506+
};
507+
483508
export const getPermissionsBoundary = async (roleName: string, region) => {
484509
const iamClient = new IAM({ region });
485510
return (await iamClient.getRole({ RoleName: roleName }).promise())?.Role?.PermissionsBoundary?.PermissionsBoundaryArn;

packages/amplify-e2e-tests/src/__tests__/transformer-migrations/model-migration.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getProjectMeta,
1212
createNewProjectDir,
1313
deleteProjectDir,
14+
waitForAllDataSourceRolesToExist,
1415
} from '@aws-amplify/amplify-e2e-core';
1516
import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync';
1617
import gql from 'graphql-tag';
@@ -113,6 +114,10 @@ describe('transformer model migration test', () => {
113114
await updateApiSchema(projRoot, projectName, modelSchemaV2);
114115
await amplifyPushUpdate(projRoot);
115116

117+
const apiId = getApiIdFromProj(projRoot);
118+
const region = getRegionFromProj(projRoot);
119+
await waitForAllDataSourceRolesToExist(apiId, region);
120+
116121
appSyncClient = getAppSyncClientFromProj(projRoot);
117122

118123
createPostMutation = /* GraphQL */ `
@@ -256,6 +261,18 @@ describe('transformer model migration test', () => {
256261
expect(queryResult.data).toBeDefined();
257262
});
258263

264+
const getRegionFromProj = (projRoot: string) => {
265+
const meta = getProjectMeta(projRoot);
266+
const region = meta.providers.awscloudformation.Region as string;
267+
return region;
268+
};
269+
270+
const getApiIdFromProj = (projRoot: string) => {
271+
const meta = getProjectMeta(projRoot);
272+
const apiId = meta.api[projectName].output.GraphQLAPIIdOutput as string;
273+
return apiId;
274+
};
275+
259276
const getAppSyncClientFromProj = (projRoot: string) => {
260277
const meta = getProjectMeta(projRoot);
261278
const region = meta.providers.awscloudformation.Region as string;

0 commit comments

Comments
 (0)