-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IAM Policy Management): re-gen service and add examples after rec…
…ent API changes
- Loading branch information
Showing
3 changed files
with
366 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,317 @@ | ||
/** | ||
* @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 IamPolicyManagementV1 = require('../dist/iam-policy-management/v1'); | ||
const { readExternalSources } = require('ibm-cloud-sdk-core'); | ||
const authHelper = require('../test/resources/auth-helper.js'); | ||
|
||
// Location of our config file. | ||
const configFile = 'iam_policy_management.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('IamPolicyManagementV1', () => { | ||
|
||
// begin-common | ||
|
||
const iamPolicyManagementService = IamPolicyManagementV1.newInstance({}); | ||
|
||
// end-common | ||
|
||
const config = readExternalSources(IamPolicyManagementV1.DEFAULT_SERVICE_NAME); | ||
|
||
test('listPolicies request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-list_policies | ||
|
||
const params = { | ||
accountId: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.listPolicies(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-list_policies | ||
}); | ||
test('createPolicy request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-create_policy | ||
|
||
const params = { | ||
type: 'testString', | ||
subjects: [{}], | ||
roles: [policyRoleModel], | ||
resources: [{}], | ||
}; | ||
|
||
iamPolicyManagementService.createPolicy(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-create_policy | ||
}); | ||
test('updatePolicy request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-update_policy | ||
|
||
const params = { | ||
policyId: 'testString', | ||
ifMatch: 'testString', | ||
type: 'testString', | ||
subjects: [{}], | ||
roles: [policyRoleModel], | ||
resources: [{}], | ||
}; | ||
|
||
iamPolicyManagementService.updatePolicy(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-update_policy | ||
}); | ||
test('getPolicy request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-get_policy | ||
|
||
const params = { | ||
policyId: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.getPolicy(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-get_policy | ||
}); | ||
test('listRoles request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-list_roles | ||
|
||
iamPolicyManagementService.listRoles({}) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-list_roles | ||
}); | ||
test('createRole request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-create_role | ||
|
||
const params = { | ||
displayName: 'testString', | ||
actions: ['testString'], | ||
name: 'testString', | ||
accountId: 'testString', | ||
serviceName: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.createRole(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-create_role | ||
}); | ||
test('updateRole request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-update_role | ||
|
||
const params = { | ||
roleId: 'testString', | ||
ifMatch: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.updateRole(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-update_role | ||
}); | ||
test('getRole request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-get_role | ||
|
||
const params = { | ||
roleId: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.getRole(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-get_role | ||
}); | ||
test('deleteRole request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-delete_role | ||
|
||
const params = { | ||
roleId: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.deleteRole(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-delete_role | ||
}); | ||
test('deletePolicy request example', done => { | ||
|
||
consoleLogMock.mockImplementation(output => { | ||
originalLog(output); | ||
done(); | ||
}); | ||
consoleWarnMock.mockImplementation(output => { | ||
done(output); | ||
}); | ||
|
||
// begin-delete_policy | ||
|
||
const params = { | ||
policyId: 'testString', | ||
}; | ||
|
||
iamPolicyManagementService.deletePolicy(params) | ||
.then(res => { | ||
console.log(JSON.stringify(res.result, null, 2)); | ||
}) | ||
.catch(err => { | ||
console.warn(err) | ||
}); | ||
|
||
// end-delete_policy | ||
}); | ||
}); |
Oops, something went wrong.