Skip to content

Commit dd7d2d2

Browse files
docs: improve the quickstart sample (#172)
1 parent aa8840e commit dd7d2d2

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
{
22
"name": "nodejs-docs-samples-os-login",
3-
"version": "0.0.1",
43
"license": "Apache-2.0",
54
"author": "Google Inc.",
65
"engines": {
76
"node": ">=8"
87
},
8+
"files": [
9+
"*.js"
10+
],
911
"repository": "googleapis/nodejs-os-login",
1012
"private": true,
11-
"semistandard": {
12-
"ignore": [
13-
"node_modules"
14-
]
15-
},
1613
"scripts": {
17-
"test": "node -e 'console.log(`no tests`)'"
14+
"test": "mocha"
1815
},
1916
"dependencies": {
2017
"@google-cloud/os-login": "^0.3.2"
2118
},
2219
"devDependencies": {
23-
"@google-cloud/nodejs-repo-tools": "^3.0.0"
20+
"chai": "^4.2.0",
21+
"mocha": "^6.1.4"
2422
}
2523
}

packages/google-cloud-oslogin/samples/quickstart.js

+11-22
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,19 @@
1616

1717
async function main() {
1818
// [START oslogin_quickstart]
19-
if (
20-
!process.env.GCLOUD_PROJECT ||
21-
!process.env.GOOGLE_APPLICATION_CREDENTIALS
22-
) {
23-
throw new Error(
24-
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
25-
);
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);
2628
}
2729

28-
const oslogin = require('@google-cloud/os-login');
29-
30-
const projectId = process.env.GCLOUD_PROJECT;
31-
32-
const client = new oslogin.OsLoginServiceClient({
33-
projectId: projectId,
34-
});
35-
36-
const request = {
37-
name: 'users/1234abcd',
38-
};
39-
40-
const [loginProfile] = await client.getLoginProfile(request);
41-
console.log(loginProfile);
30+
quickstart();
4231
// [END oslogin_quickstart]
4332
}
4433

45-
main().catch(console.error);
34+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2019, Google LLC All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {execSync} = require('child_process');
19+
20+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
21+
22+
describe('sample tests', () => {
23+
// This test current fails because it requires setup in the google-cloud-node
24+
// project, running VMs, and a fair amount of infrastructure.
25+
it.skip('should run the quickstart', () => {
26+
const output = exec('node quickstart');
27+
assert.include(output, 'Login Profile:');
28+
});
29+
});

0 commit comments

Comments
 (0)