Skip to content

Commit c1d8ea9

Browse files
docs: add sample test (#552)
* docs: add sample test Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 06a0f0a commit c1d8ea9

File tree

4 files changed

+82
-30
lines changed

4 files changed

+82
-30
lines changed

packages/google-cloud-oslogin/README.md

+32-10
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,40 @@ npm install @google-cloud/os-login
5757
### Using the client library
5858

5959
```javascript
60-
const {OsLoginServiceClient} = require('@google-cloud/os-login');
61-
const client = new OsLoginServiceClient();
62-
63-
async function quickstart() {
64-
const [loginProfile] = await client.getLoginProfile({
65-
name: 'users/[email protected]',
66-
});
67-
console.log('Login Profile:');
68-
console.log(loginProfile);
60+
/**
61+
* TODO(developer): Uncomment these variables before running the sample.
62+
*/
63+
/**
64+
* Required. The unique ID for the user in format `users/{user}`.
65+
*/
66+
// const name = 'abc123'
67+
/**
68+
* The project ID of the Google Cloud Platform project.
69+
*/
70+
// const projectId = 'abc123'
71+
/**
72+
* A system ID for filtering the results of the request.
73+
*/
74+
// const systemId = 'abc123'
75+
76+
// Imports the Oslogin library
77+
const {OsLoginServiceClient} = require('@google-cloud/os-login').v1;
78+
79+
// Instantiates a client
80+
const osloginClient = new OsLoginServiceClient();
81+
82+
async function callGetLoginProfile() {
83+
// Construct request
84+
const request = {
85+
name,
86+
};
87+
88+
// Run request
89+
const response = await osloginClient.getLoginProfile(request);
90+
console.log(response[0]);
6991
}
7092

71-
quickstart();
93+
callGetLoginProfile();
7294

7395
```
7496

packages/google-cloud-oslogin/samples/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
"chai": "^4.2.0",
2121
"mocha": "^8.0.0"
2222
}
23-
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,64 @@
1-
// Copyright 2017 Google LLC
1+
// Copyright 2022 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
66
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
7+
// https://www.apache.org/licenses/LICENSE-2.0
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
//
15+
// ** This file is automatically generated by gapic-generator-typescript. **
16+
// ** https://github.com/googleapis/gapic-generator-typescript **
17+
// ** All changes to this file may be overwritten. **
1418

1519
'use strict';
1620

17-
async function main() {
21+
function main(name) {
1822
// [START oslogin_quickstart]
19-
const {OsLoginServiceClient} = require('@google-cloud/os-login');
20-
const client = new OsLoginServiceClient();
21-
22-
async function quickstart() {
23-
const [loginProfile] = await client.getLoginProfile({
24-
name: 'users/[email protected]',
25-
});
26-
console.log('Login Profile:');
27-
console.log(loginProfile);
23+
/**
24+
* TODO(developer): Uncomment these variables before running the sample.
25+
*/
26+
/**
27+
* Required. The unique ID for the user in format `users/{user}`.
28+
*/
29+
// const name = 'abc123'
30+
/**
31+
* The project ID of the Google Cloud Platform project.
32+
*/
33+
// const projectId = 'abc123'
34+
/**
35+
* A system ID for filtering the results of the request.
36+
*/
37+
// const systemId = 'abc123'
38+
39+
// Imports the Oslogin library
40+
const {OsLoginServiceClient} = require('@google-cloud/os-login').v1;
41+
42+
// Instantiates a client
43+
const osloginClient = new OsLoginServiceClient();
44+
45+
async function callGetLoginProfile() {
46+
// Construct request
47+
const request = {
48+
name,
49+
};
50+
51+
// Run request
52+
const response = await osloginClient.getLoginProfile(request);
53+
console.log(response[0]);
2854
}
2955

30-
quickstart();
56+
callGetLoginProfile();
3157
// [END oslogin_quickstart]
3258
}
3359

34-
main();
60+
process.on('unhandledRejection', err => {
61+
console.error(err.message);
62+
process.exitCode = 1;
63+
});
64+
main(...process.argv.slice(2));

packages/google-cloud-oslogin/samples/test/sample.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const {execSync} = require('child_process');
2121
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
2222

2323
describe('sample tests', () => {
24-
// This test current fails because it requires setup in the google-cloud-node
25-
// project, running VMs, and a fair amount of infrastructure.
26-
it.skip('should run the quickstart', () => {
27-
const output = exec('node quickstart');
28-
assert.include(output, 'Login Profile:');
24+
it('should run the quickstart', () => {
25+
const output = exec(
26+
'node quickstart users/[email protected]'
27+
);
28+
assert(output !== null);
2929
});
3030
});

0 commit comments

Comments
 (0)