Skip to content

Commit

Permalink
docs: improve the quickstart sample (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Apr 24, 2019
1 parent d14e5b9 commit acc1a48
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
14 changes: 6 additions & 8 deletions packages/google-cloud-oslogin/samples/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"name": "nodejs-docs-samples-os-login",
"version": "0.0.1",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
"node": ">=8"
},
"files": [
"*.js"
],
"repository": "googleapis/nodejs-os-login",
"private": true,
"semistandard": {
"ignore": [
"node_modules"
]
},
"scripts": {
"test": "node -e 'console.log(`no tests`)'"
"test": "mocha"
},
"dependencies": {
"@google-cloud/os-login": "^0.3.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0"
"chai": "^4.2.0",
"mocha": "^6.1.4"
}
}
33 changes: 11 additions & 22 deletions packages/google-cloud-oslogin/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,19 @@

async function main() {
// [START oslogin_quickstart]
if (
!process.env.GCLOUD_PROJECT ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
throw new Error(
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
);
const {OsLoginServiceClient} = require('@google-cloud/os-login');
const client = new OsLoginServiceClient();

async function quickstart() {
const [loginProfile] = await client.getLoginProfile({
name: 'users/[email protected]',
});
console.log('Login Profile:');
console.log(loginProfile);
}

const oslogin = require('@google-cloud/os-login');

const projectId = process.env.GCLOUD_PROJECT;

const client = new oslogin.OsLoginServiceClient({
projectId: projectId,
});

const request = {
name: 'users/1234abcd',
};

const [loginProfile] = await client.getLoginProfile(request);
console.log(loginProfile);
quickstart();
// [END oslogin_quickstart]
}

main().catch(console.error);
main();
29 changes: 29 additions & 0 deletions packages/google-cloud-oslogin/samples/test/sample.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019, Google LLC All rights reserved.
//
// 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 {assert} = require('chai');
const {execSync} = require('child_process');

const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe('sample tests', () => {
// This test current fails because it requires setup in the google-cloud-node
// project, running VMs, and a fair amount of infrastructure.
it.skip('should run the quickstart', () => {
const output = exec('node quickstart');
assert.include(output, 'Login Profile:');
});
});

0 comments on commit acc1a48

Please sign in to comment.