From d216b5961866f867159edb5813d93bc657cd77ef Mon Sep 17 00:00:00 2001 From: Norbert Biczo Date: Wed, 3 Mar 2021 18:53:54 +0100 Subject: [PATCH 1/9] fix(Resource Manager): re-gen service and add examples --- examples/resource-manager.v2.test.js | 230 ++++++++++++++++++++++++++ resource-manager/v2.ts | 32 ++-- test/unit/resource-manager.v2.test.js | 11 +- 3 files changed, 262 insertions(+), 11 deletions(-) create mode 100644 examples/resource-manager.v2.test.js diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js new file mode 100644 index 00000000..c627974a --- /dev/null +++ b/examples/resource-manager.v2.test.js @@ -0,0 +1,230 @@ +/** +* @jest-environment node +*/ +/** + * (C) Copyright IBM Corp. 2021. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +const ResourceManagerV2 = require('../dist/resource-manager/v2'); +const { readExternalSources } = require('ibm-cloud-sdk-core'); +const authHelper = require('../test/resources/auth-helper.js'); + +// +// This file provides an example of how to use the Resource Manager service. +// +// The following configuration properties are assumed to be defined: +// RESOURCE_MANAGER_URL= +// RESOURCE_MANAGER_AUTH_TYPE=iam +// RESOURCE_MANAGER_APIKEY= +// RESOURCE_MANAGER_AUTH_URL= +// +// These configuration properties can be exported as environment variables, or stored +// in a configuration file and then: +// export IBM_CREDENTIALS_FILE= +// +const configFile = 'resource_manager_v2.env'; + +const describe = authHelper.prepareTests(configFile); + +// Save original console.log and console.warn +const originalLog = console.log; +const originalWarn = console.warn; + +// Mocks for console.log and console.warn +const consoleLogMock = jest.spyOn(console, 'log'); +const consoleWarnMock = jest.spyOn(console, 'warn'); + +describe('ResourceManagerV2', () => { + + // begin-common + + const resourceManagerService = ResourceManagerV2.newInstance({}); + + // end-common + + const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); + + test('listResourceGroups request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-list_resource_groups + + resourceManagerService.listResourceGroups({}) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-list_resource_groups + }); + test('createResourceGroup request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-create_resource_group + + resourceManagerService.createResourceGroup({}) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-create_resource_group + }); + test('getResourceGroup request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-get_resource_group + + const params = { + id: 'testString', + }; + + resourceManagerService.getResourceGroup(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_resource_group + }); + test('updateResourceGroup request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-update_resource_group + + const params = { + id: 'testString', + }; + + resourceManagerService.updateResourceGroup(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-update_resource_group + }); + test('listQuotaDefinitions request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-list_quota_definitions + + resourceManagerService.listQuotaDefinitions({}) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-list_quota_definitions + }); + test('getQuotaDefinition request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-get_quota_definition + + const params = { + id: 'testString', + }; + + resourceManagerService.getQuotaDefinition(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_quota_definition + }); + test('deleteResourceGroup request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-delete_resource_group + + const params = { + id: 'testString', + }; + + resourceManagerService.deleteResourceGroup(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-delete_resource_group + }); +}); diff --git a/resource-manager/v2.ts b/resource-manager/v2.ts index 7d31b9a4..06ef0a22 100644 --- a/resource-manager/v2.ts +++ b/resource-manager/v2.ts @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011 + * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-4883cbcd-20210301-143711 */ @@ -97,8 +97,11 @@ class ResourceManagerV2 extends BaseService { * * @param {Object} [params] - The parameters to send to the service. * @param {string} [params.accountId] - The ID of the account that contains the resource groups that you want to get. - * @param {string} [params.date] - The date would be in a format of YYYY-MM which returns resource groups exclude the - * deleted ones before this month. + * @param {string} [params.date] - The date in the format of YYYY-MM which returns resource groups. Deleted resource + * groups will be excluded before this month. + * @param {string} [params.name] - The name of the resource group. + * @param {boolean} [params._default] - Boolean value to specify whether or not to list default resource groups. + * @param {boolean} [params.includeDeleted] - Boolean value to specify whether or not to list default resource groups. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -107,7 +110,10 @@ class ResourceManagerV2 extends BaseService { const query = { 'account_id': _params.accountId, - 'date': _params.date + 'date': _params.date, + 'name': _params.name, + 'default': _params._default, + 'include_deleted': _params.includeDeleted }; const sdkHeaders = getSdkHeaders(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'listResourceGroups'); @@ -406,10 +412,16 @@ namespace ResourceManagerV2 { export interface ListResourceGroupsParams { /** The ID of the account that contains the resource groups that you want to get. */ accountId?: string; - /** The date would be in a format of YYYY-MM which returns resource groups exclude the deleted ones before this - * month. + /** The date in the format of YYYY-MM which returns resource groups. Deleted resource groups will be excluded + * before this month. */ date?: string; + /** The name of the resource group. */ + name?: string; + /** Boolean value to specify whether or not to list default resource groups. */ + _default?: boolean; + /** Boolean value to specify whether or not to list default resource groups. */ + includeDeleted?: boolean; headers?: OutgoingHttpHeaders; } @@ -504,7 +516,7 @@ namespace ResourceManagerV2 { /** An alpha-numeric value identifying the resource group. */ id?: string; /** The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud - * Resource Names](https://cloud.ibm.com/docs/resources?topic=resources-crn). + * Resource Names](https://cloud.ibm.com/docs/account?topic=account-crn). */ crn?: string; } @@ -514,7 +526,7 @@ namespace ResourceManagerV2 { /** An alpha-numeric value identifying the resource group. */ id?: string; /** The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud - * Resource Names](https://cloud.ibm.com/docs/resources?topic=resources-crn). + * Resource Names](https://cloud.ibm.com/docs/account?topic=account-crn). */ crn?: string; /** An alpha-numeric value identifying the account ID. */ @@ -554,7 +566,7 @@ namespace ResourceManagerV2 { /** The human-readable name of the quota. */ resource_id?: string; /** The full CRN (cloud resource name) associated with the quota. For more on this format, see - * https://cloud.ibm.com/docs/resources?topic=resources-crn#crn. + * https://cloud.ibm.com/docs/account?topic=account-crn. */ crn?: string; /** The limit number of this resource. */ diff --git a/test/unit/resource-manager.v2.test.js b/test/unit/resource-manager.v2.test.js index c5441c2b..c422de84 100644 --- a/test/unit/resource-manager.v2.test.js +++ b/test/unit/resource-manager.v2.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,9 +105,15 @@ describe('ResourceManagerV2', () => { // Construct the params object for operation listResourceGroups const accountId = 'testString'; const date = 'testString'; + const name = 'testString'; + const _default = true; + const includeDeleted = true; const params = { accountId: accountId, date: date, + name: name, + _default: _default, + includeDeleted: includeDeleted, }; const listResourceGroupsResult = resourceManagerService.listResourceGroups(params); @@ -126,6 +132,9 @@ describe('ResourceManagerV2', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(options.qs['account_id']).toEqual(accountId); expect(options.qs['date']).toEqual(date); + expect(options.qs['name']).toEqual(name); + expect(options.qs['default']).toEqual(_default); + expect(options.qs['include_deleted']).toEqual(includeDeleted); }); test('should prioritize user-given headers', () => { From 6550044317a75c400400096351a3242650ca0106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Mon, 8 Mar 2021 14:22:17 +0100 Subject: [PATCH 2/9] fix(Resource Manager): update of Resource Manager's integration tests after re-generation --- test/integration/resource-manager.v2.test.js | 110 +++++++++++-------- 1 file changed, 66 insertions(+), 44 deletions(-) diff --git a/test/integration/resource-manager.v2.test.js b/test/integration/resource-manager.v2.test.js index 51a7d399..e4b3cec4 100644 --- a/test/integration/resource-manager.v2.test.js +++ b/test/integration/resource-manager.v2.test.js @@ -18,6 +18,7 @@ 'use strict'; const ResourceManagerV2 = require('../../dist/resource-manager/v2'); const authHelper = require('../resources/auth-helper.js'); +const { readExternalSources } = require('ibm-cloud-sdk-core'); // testcase timeout value (200s). const timeout = 200000; @@ -30,28 +31,54 @@ const describe = authHelper.prepareTests(configFile); describe('ResourceManagerV2_integration', () => { jest.setTimeout(timeout); - let service1; - let service2; + let canCreateRetrieveAndUpdateResourceGroupService; + let usersService; let new_resource_group_id; - const test_quota_id = '7ce89f4a-4381-4600-b814-3cd9a4f4bdf4'; - const test_user_account_id = '60ce10d1d94749bf8dceff12065db1b0'; + let url; + let authType; + let apiKey; + let authUrl; + let testQuotaId; + let testUserAccountId; it('should successfully complete initialization', done => { - service1 = ResourceManagerV2.newInstance({ serviceName: 'RMGR1' }); - expect(service1).not.toBeNull(); + canCreateRetrieveAndUpdateResourceGroupService = ResourceManagerV2.newInstance({ serviceName: 'RMGR1' }); + expect(canCreateRetrieveAndUpdateResourceGroupService).not.toBeNull(); - service2 = ResourceManagerV2.newInstance({ serviceName: 'RMGR2' }); - expect(service2).not.toBeNull(); + usersService = ResourceManagerV2.newInstance({ serviceName: 'RMGR2' }); + expect(usersService).not.toBeNull(); + + const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); + expect(config).not.toBeNull(); + + url = config.URL; + authType = config.AUTH_TYPE; + apiKey = config.APIKEY; + authUrl = config.AUTH_URL; + testQuotaId = config.TEST_QUOTA_ID; + testUserAccountId = config.TEST_USER_ACCOUNT_ID; + + expect(url).not.toBeNull(); + expect(authType).not.toBeNull(); + expect(apiKey).not.toBeNull(); + expect(authUrl).not.toBeNull(); + expect(testQuotaId).not.toBeNull(); + expect(testUserAccountId).not.toBeNull(); done(); }); - it('should get a list of all quota definitions', done => { - service1 - .listQuotaDefinitions() + it('should create a new resource group in an account', done => { + const params = { + accountId: testUserAccountId, + name: 'TestGroup', + }; + canCreateRetrieveAndUpdateResourceGroupService + .createResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(200); + expect(response.status).toBe(201); + new_resource_group_id = response.result.id; done(); }) .catch(err => { @@ -59,12 +86,12 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should get a quota definition by quota id', done => { + it('should get a list of all resource groups in an account', done => { const params = { - id: test_quota_id, + accountId: testUserAccountId, }; - service1 - .getQuotaDefinition(params) + canCreateRetrieveAndUpdateResourceGroupService + .listResourceGroups(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); expect(response.status).toBe(200); @@ -75,12 +102,14 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should get a list of all resource groups in an account', done => { + it('should update a resource group by id', done => { const params = { - accountId: test_user_account_id, + id: new_resource_group_id, + name: 'TestGroup2', + state: 'ACTIVE', }; - service1 - .listResourceGroups(params) + canCreateRetrieveAndUpdateResourceGroupService + .updateResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); expect(response.status).toBe(200); @@ -91,17 +120,15 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should create a new resource group in an account', done => { + it('should retrieve a resource group by id', done => { const params = { - accountId: test_user_account_id, - name: 'TestGroup', + id: new_resource_group_id, }; - service1 - .createResourceGroup(params) + canCreateRetrieveAndUpdateResourceGroupService + .getResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(201); - new_resource_group_id = response.result.id; + expect(response.status).toBe(200); done(); }) .catch(err => { @@ -109,15 +136,15 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should retrieve a resource group by id', done => { + it('should delete a resource group by id', done => { const params = { id: new_resource_group_id, }; - service1 - .getResourceGroup(params) + usersService + .deleteResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(200); + expect(response.status).toBe(204); done(); }) .catch(err => { @@ -125,14 +152,9 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should update a resource group by id', done => { - const params = { - id: new_resource_group_id, - name: 'TestGroup2', - state: 'ACTIVE', - }; - service1 - .updateResourceGroup(params) + it('should get a list of all quota definitions', done => { + canCreateRetrieveAndUpdateResourceGroupService + .listQuotaDefinitions() .then(response => { expect(response.hasOwnProperty('status')).toBe(true); expect(response.status).toBe(200); @@ -143,15 +165,15 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should delete a resource group by id', done => { + it('should get a quota definition by quota id', done => { const params = { - id: new_resource_group_id, + id: testQuotaId, }; - service2 - .deleteResourceGroup(params) + canCreateRetrieveAndUpdateResourceGroupService + .getQuotaDefinition(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(204); + expect(response.status).toBe(200); done(); }) .catch(err => { From 2751d716ab490b9c56bd1e7042542a698e813d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Mon, 8 Mar 2021 14:23:02 +0100 Subject: [PATCH 3/9] fix(Resource Manager): update of Resource Manager's usage examples after re-generation --- examples/resource-manager.v2.test.js | 163 +++++++++++++++------------ 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js index c627974a..c7c5f990 100644 --- a/examples/resource-manager.v2.test.js +++ b/examples/resource-manager.v2.test.js @@ -1,6 +1,6 @@ /** -* @jest-environment node -*/ + * @jest-environment node + */ /** * (C) Copyright IBM Corp. 2021. * @@ -48,39 +48,19 @@ const consoleLogMock = jest.spyOn(console, 'log'); const consoleWarnMock = jest.spyOn(console, 'warn'); describe('ResourceManagerV2', () => { - + // begin-common - + const resourceManagerService = ResourceManagerV2.newInstance({}); - + // end-common - + const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); - - test('listResourceGroups request example', done => { - - consoleLogMock.mockImplementation(output => { - originalLog(output); - done(); - }); - consoleWarnMock.mockImplementation(output => { - done(output); - }); - - // begin-list_resource_groups - - resourceManagerService.listResourceGroups({}) - .then(res => { - console.log(JSON.stringify(res.result, null, 2)); - }) - .catch(err => { - console.warn(err) - }); - - // end-list_resource_groups - }); + const testUserAccountId = config.TEST_USER_ACCOUNT_ID; + let resourceGroupId; + test('createResourceGroup request example', done => { - + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -88,21 +68,26 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - + // begin-create_resource_group - - resourceManagerService.createResourceGroup({}) + const params = { + accountId: testUserAccountId, + name: "ExampleGroup" + }; + + resourceManagerService.createResourceGroup(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); + resourceGroupId = res.result.id; }) .catch(err => { console.warn(err) }); - + // end-create_resource_group }); test('getResourceGroup request example', done => { - + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -110,13 +95,13 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - + // begin-get_resource_group - + const params = { - id: 'testString', + id: resourceGroupId, }; - + resourceManagerService.getResourceGroup(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); @@ -124,11 +109,11 @@ describe('ResourceManagerV2', () => { .catch(err => { console.warn(err) }); - + // end-get_resource_group }); test('updateResourceGroup request example', done => { - + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -136,13 +121,15 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - + // begin-update_resource_group - + const params = { - id: 'testString', + id: resourceGroupId, + state: 'ACTIVE', + name: 'RenamedResourceGroup' }; - + resourceManagerService.updateResourceGroup(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); @@ -150,11 +137,12 @@ describe('ResourceManagerV2', () => { .catch(err => { console.warn(err) }); - + // end-update_resource_group }); - test('listQuotaDefinitions request example', done => { - + + test('listResourceGroups request example', done => { + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -162,21 +150,24 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - - // begin-list_quota_definitions - - resourceManagerService.listQuotaDefinitions({}) + + // begin-list_resource_groups + const params = { + accountId: testUserAccountId + } + + resourceManagerService.listResourceGroups(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); }) .catch(err => { console.warn(err) }); - - // end-list_quota_definitions + + // end-list_resource_groups }); - test('getQuotaDefinition request example', done => { - + test('deleteResourceGroup request example', done => { + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -184,25 +175,26 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - - // begin-get_quota_definition - + + // begin-delete_resource_group + const params = { - id: 'testString', + id: resourceGroupId, }; - - resourceManagerService.getQuotaDefinition(params) + + resourceManagerService.deleteResourceGroup(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); }) .catch(err => { console.warn(err) }); - - // end-get_quota_definition + + // end-delete_resource_group }); - test('deleteResourceGroup request example', done => { - + + test('listQuotaDefinitions request example', done => { + consoleLogMock.mockImplementation(output => { originalLog(output); done(); @@ -210,21 +202,44 @@ describe('ResourceManagerV2', () => { consoleWarnMock.mockImplementation(output => { done(output); }); - - // begin-delete_resource_group - + + // begin-list_quota_definitions + + resourceManagerService.listQuotaDefinitions({}) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-list_quota_definitions + }); + test('getQuotaDefinition request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-get_quota_definition + const params = { - id: 'testString', + id: resourceGroupId, }; - - resourceManagerService.deleteResourceGroup(params) + + resourceManagerService.getQuotaDefinition(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); }) .catch(err => { console.warn(err) }); - - // end-delete_resource_group + + // end-get_quota_definition }); + }); From b14731c54913447dfd099d6fd935557f83166cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Tue, 16 Mar 2021 10:59:41 +0100 Subject: [PATCH 4/9] feat(resource manager): small fixes - add beforeAll block - change in order of tests - service renames --- test/integration/resource-manager.v2.test.js | 80 ++++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/test/integration/resource-manager.v2.test.js b/test/integration/resource-manager.v2.test.js index e4b3cec4..6a726988 100644 --- a/test/integration/resource-manager.v2.test.js +++ b/test/integration/resource-manager.v2.test.js @@ -31,32 +31,30 @@ const describe = authHelper.prepareTests(configFile); describe('ResourceManagerV2_integration', () => { jest.setTimeout(timeout); - let canCreateRetrieveAndUpdateResourceGroupService; - let usersService; - let new_resource_group_id; - let url; - let authType; - let apiKey; - let authUrl; - let testQuotaId; - let testUserAccountId; - - it('should successfully complete initialization', done => { - canCreateRetrieveAndUpdateResourceGroupService = ResourceManagerV2.newInstance({ serviceName: 'RMGR1' }); - expect(canCreateRetrieveAndUpdateResourceGroupService).not.toBeNull(); - - usersService = ResourceManagerV2.newInstance({ serviceName: 'RMGR2' }); - expect(usersService).not.toBeNull(); + let resourceManagerService = null; + let resourceManagerUsersService = null; + let newResourceGroupId = null; + let url = null; + let authType = null; + let apiKey = null; + let authUrl = null; + let testQuotaId = null; + let testUserAccountId = null; + + beforeAll('should successfully complete initialization', done => { + resourceManagerService = ResourceManagerV2.newInstance({ serviceName: 'RMGR1' }); + expect(resourceManagerService).not.toBeNull(); + resourceManagerUsersService = ResourceManagerV2.newInstance({ serviceName: 'RMGR2' }); + expect(resourceManagerUsersService).not.toBeNull(); const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); expect(config).not.toBeNull(); - - url = config.URL; - authType = config.AUTH_TYPE; - apiKey = config.APIKEY; - authUrl = config.AUTH_URL; - testQuotaId = config.TEST_QUOTA_ID; - testUserAccountId = config.TEST_USER_ACCOUNT_ID; + url = config.url; + authType = config.authType; + apiKey = config.apiKey; + authUrl = config.AuthUrl; + testQuotaId = config.testQuotaId; + testUserAccountId = config.testUserAccountId; expect(url).not.toBeNull(); expect(authType).not.toBeNull(); @@ -68,17 +66,15 @@ describe('ResourceManagerV2_integration', () => { done(); }); - it('should create a new resource group in an account', done => { + it('should get a list of all resource groups in an account', done => { const params = { accountId: testUserAccountId, - name: 'TestGroup', }; - canCreateRetrieveAndUpdateResourceGroupService - .createResourceGroup(params) + resourceManagerService + .listResourceGroups(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(201); - new_resource_group_id = response.result.id; + expect(response.status).toBe(200); done(); }) .catch(err => { @@ -86,15 +82,17 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should get a list of all resource groups in an account', done => { + it('should create a new resource group in an account', done => { const params = { accountId: testUserAccountId, + name: 'TestGroup', }; - canCreateRetrieveAndUpdateResourceGroupService - .listResourceGroups(params) + resourceManagerService + .createResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(200); + expect(response.status).toBe(201); + newResourceGroupId = response.result.id; done(); }) .catch(err => { @@ -104,11 +102,11 @@ describe('ResourceManagerV2_integration', () => { it('should update a resource group by id', done => { const params = { - id: new_resource_group_id, + id: newResourceGroupId, name: 'TestGroup2', state: 'ACTIVE', }; - canCreateRetrieveAndUpdateResourceGroupService + resourceManagerService .updateResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); @@ -122,9 +120,9 @@ describe('ResourceManagerV2_integration', () => { it('should retrieve a resource group by id', done => { const params = { - id: new_resource_group_id, + id: newResourceGroupId, }; - canCreateRetrieveAndUpdateResourceGroupService + resourceManagerService .getResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); @@ -138,9 +136,9 @@ describe('ResourceManagerV2_integration', () => { it('should delete a resource group by id', done => { const params = { - id: new_resource_group_id, + id: newResourceGroupId, }; - usersService + resourceManagerUsersService .deleteResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); @@ -153,7 +151,7 @@ describe('ResourceManagerV2_integration', () => { }); it('should get a list of all quota definitions', done => { - canCreateRetrieveAndUpdateResourceGroupService + resourceManagerService .listQuotaDefinitions() .then(response => { expect(response.hasOwnProperty('status')).toBe(true); @@ -169,7 +167,7 @@ describe('ResourceManagerV2_integration', () => { const params = { id: testQuotaId, }; - canCreateRetrieveAndUpdateResourceGroupService + resourceManagerService .getQuotaDefinition(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); From cfe8cebd61eed569b8095860bef4b2e5cb6800d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Tue, 16 Mar 2021 11:09:05 +0100 Subject: [PATCH 5/9] feat(resource manager): fix example --- examples/resource-manager.v2.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js index c7c5f990..c51fc584 100644 --- a/examples/resource-manager.v2.test.js +++ b/examples/resource-manager.v2.test.js @@ -30,6 +30,7 @@ const authHelper = require('../test/resources/auth-helper.js'); // RESOURCE_MANAGER_AUTH_TYPE=iam // RESOURCE_MANAGER_APIKEY= // RESOURCE_MANAGER_AUTH_URL= +// RESOURCE_MANAGER_TEST_USER_ACCOUNT_ID // // These configuration properties can be exported as environment variables, or stored // in a configuration file and then: @@ -56,7 +57,8 @@ describe('ResourceManagerV2', () => { // end-common const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); - const testUserAccountId = config.TEST_USER_ACCOUNT_ID; + const testUserAccountId = config.testUserAccountId; + const testQuotaId = config.testQuotaId; let resourceGroupId; test('createResourceGroup request example', done => { @@ -228,7 +230,7 @@ describe('ResourceManagerV2', () => { // begin-get_quota_definition const params = { - id: resourceGroupId, + id: testQuotaId, }; resourceManagerService.getQuotaDefinition(params) From 709732b3a6148c0877a1bb41adcb447d56531fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Tue, 16 Mar 2021 11:11:18 +0100 Subject: [PATCH 6/9] feat(resource manager): add the correct config file example to usage examples --- examples/resource-manager.v2.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js index c51fc584..64fb0bc0 100644 --- a/examples/resource-manager.v2.test.js +++ b/examples/resource-manager.v2.test.js @@ -30,7 +30,8 @@ const authHelper = require('../test/resources/auth-helper.js'); // RESOURCE_MANAGER_AUTH_TYPE=iam // RESOURCE_MANAGER_APIKEY= // RESOURCE_MANAGER_AUTH_URL= -// RESOURCE_MANAGER_TEST_USER_ACCOUNT_ID +// RESOURCE_MANAGER_TEST_QUOTA_ID= +// RESOURCE_MANAGER_TEST_USER_ACCOUNT_ID= // // These configuration properties can be exported as environment variables, or stored // in a configuration file and then: From b0249ed7a7aabbd289e538c471c23e33c29e9021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Tue, 16 Mar 2021 16:48:17 +0100 Subject: [PATCH 7/9] feat(resource manager): fix examples --- examples/resource-manager.v2.test.js | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js index 64fb0bc0..77d17800 100644 --- a/examples/resource-manager.v2.test.js +++ b/examples/resource-manager.v2.test.js @@ -26,18 +26,24 @@ const authHelper = require('../test/resources/auth-helper.js'); // This file provides an example of how to use the Resource Manager service. // // The following configuration properties are assumed to be defined: +// The following configuration properties are assumed to be defined: // RESOURCE_MANAGER_URL= // RESOURCE_MANAGER_AUTH_TYPE=iam -// RESOURCE_MANAGER_APIKEY= +// RESOURCE_MANAGER_APIKEY= // RESOURCE_MANAGER_AUTH_URL= -// RESOURCE_MANAGER_TEST_QUOTA_ID= -// RESOURCE_MANAGER_TEST_USER_ACCOUNT_ID= +// RESOURCE_MANAGER_QUOTA_ID= +// RESOURCE_MANAGER_USER_ACCOUNT_ID= +// +// ALT_RESOURCE_MANAGER_URL= +// ALT_RESOURCE_MANAGER_AUTH_TYPE=iam +// ALT_RESOURCE_MANAGER_AUTH_URL= +// ALT_RESOURCE_MANAGER_APIKEY= // // These configuration properties can be exported as environment variables, or stored // in a configuration file and then: // export IBM_CREDENTIALS_FILE= // -const configFile = 'resource_manager_v2.env'; +const configFile = 'resource_manager.env'; const describe = authHelper.prepareTests(configFile); @@ -53,14 +59,17 @@ describe('ResourceManagerV2', () => { // begin-common - const resourceManagerService = ResourceManagerV2.newInstance({}); + const resourceManagerService = ResourceManagerV2.newInstance({ serviceName: ResourceManagerV2.DEFAULT_SERVICE_NAME}); + const deleteResourceManagerService = ResourceManagerV2.newInstance( + {serviceName: 'ALT_RESOURCE_MANAGER'} + ); // end-common const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); - const testUserAccountId = config.testUserAccountId; - const testQuotaId = config.testQuotaId; - let resourceGroupId; + const userAccountId = config.userAccountId; + const quotaId = config.quotaId; + let resourceGroupId = null; test('createResourceGroup request example', done => { @@ -74,7 +83,7 @@ describe('ResourceManagerV2', () => { // begin-create_resource_group const params = { - accountId: testUserAccountId, + accountId: userAccountId, name: "ExampleGroup" }; @@ -156,7 +165,7 @@ describe('ResourceManagerV2', () => { // begin-list_resource_groups const params = { - accountId: testUserAccountId + accountId: userAccountId } resourceManagerService.listResourceGroups(params) @@ -185,7 +194,7 @@ describe('ResourceManagerV2', () => { id: resourceGroupId, }; - resourceManagerService.deleteResourceGroup(params) + deleteResourceManagerService.deleteResourceGroup(params) .then(res => { console.log(JSON.stringify(res.result, null, 2)); }) @@ -231,7 +240,7 @@ describe('ResourceManagerV2', () => { // begin-get_quota_definition const params = { - id: testQuotaId, + id: quotaId, }; resourceManagerService.getQuotaDefinition(params) From 6ff810fbb775dd8dd7a010c21496af32a74c1f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Tue, 16 Mar 2021 16:51:01 +0100 Subject: [PATCH 8/9] feat(resource manager): fix integration tests --- test/integration/resource-manager.v2.test.js | 48 ++++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/integration/resource-manager.v2.test.js b/test/integration/resource-manager.v2.test.js index 6a726988..633a1459 100644 --- a/test/integration/resource-manager.v2.test.js +++ b/test/integration/resource-manager.v2.test.js @@ -32,49 +32,51 @@ describe('ResourceManagerV2_integration', () => { jest.setTimeout(timeout); let resourceManagerService = null; - let resourceManagerUsersService = null; + let deleteResourceManagerService = null; let newResourceGroupId = null; let url = null; let authType = null; let apiKey = null; let authUrl = null; - let testQuotaId = null; - let testUserAccountId = null; + let quotaId = null; + let userAccountId = null; - beforeAll('should successfully complete initialization', done => { - resourceManagerService = ResourceManagerV2.newInstance({ serviceName: 'RMGR1' }); + beforeAll(done => { + resourceManagerService = ResourceManagerV2.newInstance({ serviceName: ResourceManagerV2.DEFAULT_SERVICE_NAME }); expect(resourceManagerService).not.toBeNull(); - resourceManagerUsersService = ResourceManagerV2.newInstance({ serviceName: 'RMGR2' }); - expect(resourceManagerUsersService).not.toBeNull(); + deleteResourceManagerService = ResourceManagerV2.newInstance({ serviceName: 'ALT_RESOURCE_MANAGER' }); + expect(deleteResourceManagerService).not.toBeNull(); const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); expect(config).not.toBeNull(); url = config.url; authType = config.authType; apiKey = config.apiKey; - authUrl = config.AuthUrl; - testQuotaId = config.testQuotaId; - testUserAccountId = config.testUserAccountId; + authUrl = config.authUrl; + quotaId = config.quotaId; + userAccountId = config.userAccountId; expect(url).not.toBeNull(); expect(authType).not.toBeNull(); expect(apiKey).not.toBeNull(); expect(authUrl).not.toBeNull(); - expect(testQuotaId).not.toBeNull(); - expect(testUserAccountId).not.toBeNull(); + expect(quotaId).not.toBeNull(); + expect(userAccountId).not.toBeNull(); done(); }); - it('should get a list of all resource groups in an account', done => { + it('should create a new resource group in an account', done => { const params = { - accountId: testUserAccountId, + accountId: userAccountId, + name: 'TestGroup', }; resourceManagerService - .listResourceGroups(params) + .createResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(200); + expect(response.status).toBe(201); + newResourceGroupId = response.result.id; done(); }) .catch(err => { @@ -82,17 +84,15 @@ describe('ResourceManagerV2_integration', () => { }); }); - it('should create a new resource group in an account', done => { + it('should get a list of all resource groups in an account', done => { const params = { - accountId: testUserAccountId, - name: 'TestGroup', + accountId: userAccountId, }; resourceManagerService - .createResourceGroup(params) + .listResourceGroups(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); - expect(response.status).toBe(201); - newResourceGroupId = response.result.id; + expect(response.status).toBe(200); done(); }) .catch(err => { @@ -138,7 +138,7 @@ describe('ResourceManagerV2_integration', () => { const params = { id: newResourceGroupId, }; - resourceManagerUsersService + deleteResourceManagerService .deleteResourceGroup(params) .then(response => { expect(response.hasOwnProperty('status')).toBe(true); @@ -165,7 +165,7 @@ describe('ResourceManagerV2_integration', () => { it('should get a quota definition by quota id', done => { const params = { - id: testQuotaId, + id: quotaId, }; resourceManagerService .getQuotaDefinition(params) From 3a7707cbdf3aded7dbd3063731d83248f790edbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Cs=C3=A1nyi?= Date: Wed, 17 Mar 2021 11:03:43 +0100 Subject: [PATCH 9/9] fix(resource manager): fix examples --- examples/resource-manager.v2.test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/resource-manager.v2.test.js b/examples/resource-manager.v2.test.js index 77d17800..a3d74d84 100644 --- a/examples/resource-manager.v2.test.js +++ b/examples/resource-manager.v2.test.js @@ -67,8 +67,8 @@ describe('ResourceManagerV2', () => { // end-common const config = readExternalSources(ResourceManagerV2.DEFAULT_SERVICE_NAME); - const userAccountId = config.userAccountId; - const quotaId = config.quotaId; + const exampleUserAccountId = config.userAccountId; + const exampleQuotaId = config.quotaId; let resourceGroupId = null; test('createResourceGroup request example', done => { @@ -83,14 +83,14 @@ describe('ResourceManagerV2', () => { // begin-create_resource_group const params = { - accountId: userAccountId, + accountId: exampleUserAccountId, name: "ExampleGroup" }; resourceManagerService.createResourceGroup(params) .then(res => { - console.log(JSON.stringify(res.result, null, 2)); resourceGroupId = res.result.id; + console.log(JSON.stringify(res.result, null, 2)); }) .catch(err => { console.warn(err) @@ -139,7 +139,7 @@ describe('ResourceManagerV2', () => { const params = { id: resourceGroupId, state: 'ACTIVE', - name: 'RenamedResourceGroup' + name: 'RenamedExampleGroup' }; resourceManagerService.updateResourceGroup(params) @@ -165,7 +165,8 @@ describe('ResourceManagerV2', () => { // begin-list_resource_groups const params = { - accountId: userAccountId + accountId: exampleUserAccountId, + includeDeleted: true, } resourceManagerService.listResourceGroups(params) @@ -240,7 +241,7 @@ describe('ResourceManagerV2', () => { // begin-get_quota_definition const params = { - id: quotaId, + id: exampleQuotaId, }; resourceManagerService.getQuotaDefinition(params)