Skip to content

Commit 9e39415

Browse files
sofislkweinmeister
authored andcommitted
feat: add tests and samples to library
1 parent 2a0523e commit 9e39415

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

org-policy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ __Usage:__
4747

4848
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
4949
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-org-policy&page=editor&open_in_editor=samples/README.md
50-
[product-docs]: null
50+
[product-docs]: https://cloud.google.com/resource-manager/docs/organization-policy/overview

org-policy/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "c8 mocha --timeout 600000 test/*.js"
1414
},
1515
"dependencies": {
16-
"": "^0.1.0"
16+
"@google-cloud/org-policy": "^0.1.0"
1717
},
1818
"devDependencies": {
1919
"c8": "^7.1.0",

org-policy/quickstart.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,29 @@
1313

1414
'use strict';
1515

16-
async function main() {
16+
async function main(projectId) {
1717
// [START nodejs_org_policy_quickstart]
1818
// Imports the Google Cloud client library
1919

2020
// remove this line after package is released
2121
// eslint-disable-next-line node/no-missing-require
22-
const {OrgPolicyClient} = require('');
22+
const {OrgPolicyClient} = require('@google-cloud/org-policy');
2323

2424
// TODO(developer): replace with your prefered project ID.
2525
// const projectId = 'my-project'
2626

2727
// Creates a client
2828
// eslint-disable-next-line no-unused-vars
29-
const client = new {OrgPolicyClient}();
29+
const client = new OrgPolicyClient();
3030

3131
//TODO(library generator): write the actual function you will be testing
32-
async function doSomething() {
33-
console.log(
34-
'DPE! Change this code so that it shows how to use the library! See comments below on structure.'
35-
);
36-
// const [thing] = await client.methodName({
37-
// });
38-
// console.info(thing);
32+
async function listConstraints() {
33+
const constraints = await client.listConstraints({
34+
parent: `projects/${projectId}`,
35+
});
36+
console.info(constraints);
3937
}
40-
doSomething();
38+
listConstraints();
4139
// [END nodejs_org_policy_quickstart]
4240
}
4341

org-policy/test/quickstart.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,24 @@
2020
const path = require('path');
2121
const cp = require('child_process');
2222
const {before, describe, it} = require('mocha');
23-
// eslint-disable-next-line node/no-missing-require
24-
const {OrgPolicyClient} = require('');
25-
// eslint-disable-next-line no-unused-vars, node/no-missing-require
23+
const {OrgPolicyClient} = require('@google-cloud/org-policy');
2624
const {assert} = require('chai');
2725

2826
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2927

3028
const cwd = path.join(__dirname, '..');
3129

32-
const client = new {OrgPolicyClient}();
30+
const client = new OrgPolicyClient();
3331

3432
describe('Quickstart', () => {
35-
//TODO: remove this if not using the projectId
36-
// eslint-disable-next-line no-unused-vars
3733
let projectId;
3834

3935
before(async () => {
40-
// eslint-disable-next-line no-unused-vars
4136
projectId = await client.getProjectId();
4237
});
4338

4439
it('should run quickstart', async () => {
45-
//TODO: remove this line
46-
// eslint-disable-next-line no-unused-vars
47-
const stdout = execSync('node ./quickstart.js', {cwd});
48-
//assert(stdout, stdout !== null);
40+
const stdout = execSync(`node ./quickstart.js ${projectId}`, {cwd});
41+
assert.match(stdout, /\[[\s\S]*\]/);
4942
});
5043
});

0 commit comments

Comments
 (0)