Skip to content

Commit

Permalink
geo category check for unsupported regions (#8255)
Browse files Browse the repository at this point in the history
* fix(amplify-category-geo): check unsupported regions

* fix(amplify-category-geo): add unit test for unsupported region check

* fix(amplify-category-geo): rename method name

* fix(amplify-category-geo): abstract region check into a function
  • Loading branch information
phani-srikar authored Sep 23, 2021
1 parent 1d6af97 commit cf2a56d
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 51 deletions.
84 changes: 42 additions & 42 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1018,23 +1018,23 @@ jobs:
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/geo-remove.test.ts
CLI_REGION: eu-west-2
CLI_REGION: eu-central-1
geo-update-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/geo-update.test.ts
CLI_REGION: eu-central-1
CLI_REGION: ap-northeast-1
geo-add-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/geo-add.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
hostingPROD-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
Expand Down Expand Up @@ -1755,7 +1755,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/geo-remove.test.ts
CLI_REGION: eu-west-2
CLI_REGION: eu-central-1
steps: *ref_6
geo-update-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand All @@ -1765,7 +1765,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/geo-update.test.ts
CLI_REGION: eu-central-1
CLI_REGION: ap-northeast-1
steps: *ref_6
geo-add-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand All @@ -1775,7 +1775,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/geo-add.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
steps: *ref_6
hostingPROD-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand Down Expand Up @@ -2612,36 +2612,30 @@ workflows:
filters: *ref_10
requires:
- migration-api-connection-migration-amplify_e2e_tests
- geo-remove-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- schema-auth-11-amplify_e2e_tests
- feature-flags-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- import_s3_1-amplify_e2e_tests
- schema-auth-11-amplify_e2e_tests
- schema-versioned-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- schema-auth-7-amplify_e2e_tests
- import_s3_1-amplify_e2e_tests
- plugin-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- schema-auth-3-amplify_e2e_tests
- schema-auth-7-amplify_e2e_tests
- hooks-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- geo-remove-amplify_e2e_tests
- schema-auth-3-amplify_e2e_tests
- auth_6-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
Expand Down Expand Up @@ -2684,7 +2678,7 @@ workflows:
filters: *ref_10
requires:
- schema-model-amplify_e2e_tests
- geo-update-amplify_e2e_tests:
- geo-remove-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2713,7 +2707,7 @@ workflows:
post-steps: *ref_9
filters: *ref_10
requires:
- geo-update-amplify_e2e_tests
- geo-remove-amplify_e2e_tests
- api_4-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
Expand Down Expand Up @@ -2756,7 +2750,7 @@ workflows:
filters: *ref_10
requires:
- schema-function-amplify_e2e_tests
- geo-add-amplify_e2e_tests:
- geo-update-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2785,7 +2779,7 @@ workflows:
post-steps: *ref_9
filters: *ref_10
requires:
- geo-add-amplify_e2e_tests
- geo-update-amplify_e2e_tests
- schema-auth-2-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
Expand Down Expand Up @@ -2822,30 +2816,36 @@ workflows:
filters: *ref_10
requires:
- function_4-amplify_e2e_tests
- hostingPROD-amplify_e2e_tests:
- geo-add-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- env-amplify_e2e_tests
- amplify-app-amplify_e2e_tests:
- hostingPROD-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- api_3-amplify_e2e_tests
- init-amplify_e2e_tests:
- amplify-app-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- layer-amplify_e2e_tests
- pull-amplify_e2e_tests:
- init-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- auth_5-amplify_e2e_tests
- pull-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- geo-add-amplify_e2e_tests
- function_5-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
Expand Down Expand Up @@ -3120,36 +3120,30 @@ workflows:
filters: *ref_13
requires:
- migration-api-connection-migration-amplify_e2e_tests_pkg_linux
- geo-remove-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- schema-auth-11-amplify_e2e_tests_pkg_linux
- feature-flags-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- import_s3_1-amplify_e2e_tests_pkg_linux
- schema-auth-11-amplify_e2e_tests_pkg_linux
- schema-versioned-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- schema-auth-7-amplify_e2e_tests_pkg_linux
- import_s3_1-amplify_e2e_tests_pkg_linux
- plugin-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- schema-auth-3-amplify_e2e_tests_pkg_linux
- schema-auth-7-amplify_e2e_tests_pkg_linux
- hooks-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- geo-remove-amplify_e2e_tests_pkg_linux
- schema-auth-3-amplify_e2e_tests_pkg_linux
- auth_6-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
Expand Down Expand Up @@ -3196,7 +3190,7 @@ workflows:
filters: *ref_13
requires:
- schema-model-amplify_e2e_tests_pkg_linux
- geo-update-amplify_e2e_tests_pkg_linux:
- geo-remove-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3225,7 +3219,7 @@ workflows:
post-steps: *ref_12
filters: *ref_13
requires:
- geo-update-amplify_e2e_tests_pkg_linux
- geo-remove-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
Expand Down Expand Up @@ -3272,7 +3266,7 @@ workflows:
filters: *ref_13
requires:
- schema-function-amplify_e2e_tests_pkg_linux
- geo-add-amplify_e2e_tests_pkg_linux:
- geo-update-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3301,7 +3295,7 @@ workflows:
post-steps: *ref_12
filters: *ref_13
requires:
- geo-add-amplify_e2e_tests_pkg_linux
- geo-update-amplify_e2e_tests_pkg_linux
- schema-auth-2-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
Expand Down Expand Up @@ -3342,30 +3336,36 @@ workflows:
filters: *ref_13
requires:
- function_4-amplify_e2e_tests_pkg_linux
- hostingPROD-amplify_e2e_tests_pkg_linux:
- geo-add-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- env-amplify_e2e_tests_pkg_linux
- amplify-app-amplify_e2e_tests_pkg_linux:
- hostingPROD-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- api_3-amplify_e2e_tests_pkg_linux
- init-amplify_e2e_tests_pkg_linux:
- amplify-app-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- layer-amplify_e2e_tests_pkg_linux
- pull-amplify_e2e_tests_pkg_linux:
- init-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- auth_5-amplify_e2e_tests_pkg_linux
- pull-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- geo-add-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $TSContext } from 'amplify-cli-core';
import { $TSContext, stateManager, $TSObject } from 'amplify-cli-core';
import { addResource } from '../../../provider-controllers/index';
import { ServiceName } from '../../../service-utils/constants';
import { run } from '../../../commands/geo/add';
Expand All @@ -13,6 +13,10 @@ jest.mock('../../../provider-controllers/index');
describe('add command tests', () => {
const provider = 'awscloudformation';
let mockContext: $TSContext;
// construct mock amplify meta
const mockAmplifyMeta: $TSObject = {
providers: {}
};

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -23,6 +27,10 @@ describe('add command tests', () => {
},
amplify: {}
} as unknown) as $TSContext;
mockAmplifyMeta.providers[provider] = {
Region: 'us-west-2'
};
stateManager.getMeta = jest.fn().mockReturnValue(mockAmplifyMeta);
});

it('add resource workflow is invoked for map service', async() => {
Expand All @@ -46,4 +54,15 @@ describe('add command tests', () => {

expect(mockAddResource).toHaveBeenCalledWith(mockContext, service);
});

it('add resource workflow is not invoked for unsupported region', async() => {
mockAmplifyMeta.providers[provider] = {
Region: 'eu-west-2'
};
stateManager.getMeta = jest.fn().mockReturnValue(mockAmplifyMeta);

await run(mockContext);

expect(mockAddResource).toBeCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $TSContext } from 'amplify-cli-core';
import { $TSContext, stateManager, $TSObject } from 'amplify-cli-core';
import { removeResource } from '../../../provider-controllers';
import { ServiceName } from '../../../service-utils/constants';
import { run } from '../../../commands/geo/remove';
Expand All @@ -18,6 +18,10 @@ jest.mock('../../../provider-controllers');
describe('remove command tests', () => {
const provider = 'awscloudformation';
let mockContext: $TSContext;
// construct mock amplify meta
const mockAmplifyMeta: $TSObject = {
providers: {}
};

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -28,6 +32,10 @@ describe('remove command tests', () => {
},
amplify: {}
} as unknown) as $TSContext;
mockAmplifyMeta.providers[provider] = {
Region: 'us-west-2'
};
stateManager.getMeta = jest.fn().mockReturnValue(mockAmplifyMeta);
});

it('remove resource workflow is invoked for map service', async() => {
Expand All @@ -51,4 +59,15 @@ describe('remove command tests', () => {

expect(mockRemoveResource).toHaveBeenCalledWith(mockContext, service);
});

it('remove resource workflow is not invoked for unsupported region', async() => {
mockAmplifyMeta.providers[provider] = {
Region: 'eu-west-2'
};
stateManager.getMeta = jest.fn().mockReturnValue(mockAmplifyMeta);

await run(mockContext);

expect(mockRemoveResource).toBeCalledTimes(0);
});
});
Loading

0 comments on commit cf2a56d

Please sign in to comment.