Skip to content

Commit

Permalink
docs: add sample test (#552)
Browse files Browse the repository at this point in the history
* docs: add sample test 

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sofisl and gcf-owl-bot[bot] authored Sep 16, 2022
1 parent 06a0f0a commit c1d8ea9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 30 deletions.
42 changes: 32 additions & 10 deletions packages/google-cloud-oslogin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,40 @@ npm install @google-cloud/os-login
### Using the client library

```javascript
const {OsLoginServiceClient} = require('@google-cloud/os-login');
const client = new OsLoginServiceClient();

async function quickstart() {
const [loginProfile] = await client.getLoginProfile({
name: 'users/beckwith@google.com',
});
console.log('Login Profile:');
console.log(loginProfile);
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. The unique ID for the user in format `users/{user}`.
*/
// const name = 'abc123'
/**
* The project ID of the Google Cloud Platform project.
*/
// const projectId = 'abc123'
/**
* A system ID for filtering the results of the request.
*/
// const systemId = 'abc123'

// Imports the Oslogin library
const {OsLoginServiceClient} = require('@google-cloud/os-login').v1;

// Instantiates a client
const osloginClient = new OsLoginServiceClient();

async function callGetLoginProfile() {
// Construct request
const request = {
name,
};

// Run request
const response = await osloginClient.getLoginProfile(request);
console.log(response[0]);
}

quickstart();
callGetLoginProfile();

```

Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-oslogin/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
}
58 changes: 44 additions & 14 deletions packages/google-cloud-oslogin/samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,64 @@
// Copyright 2017 Google LLC
// Copyright 2022 Google LLC
//
// 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
// https://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.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

async function main() {
function main(name) {
// [START oslogin_quickstart]
const {OsLoginServiceClient} = require('@google-cloud/os-login');
const client = new OsLoginServiceClient();

async function quickstart() {
const [loginProfile] = await client.getLoginProfile({
name: 'users/beckwith@google.com',
});
console.log('Login Profile:');
console.log(loginProfile);
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. The unique ID for the user in format `users/{user}`.
*/
// const name = 'abc123'
/**
* The project ID of the Google Cloud Platform project.
*/
// const projectId = 'abc123'
/**
* A system ID for filtering the results of the request.
*/
// const systemId = 'abc123'

// Imports the Oslogin library
const {OsLoginServiceClient} = require('@google-cloud/os-login').v1;

// Instantiates a client
const osloginClient = new OsLoginServiceClient();

async function callGetLoginProfile() {
// Construct request
const request = {
name,
};

// Run request
const response = await osloginClient.getLoginProfile(request);
console.log(response[0]);
}

quickstart();
callGetLoginProfile();
// [END oslogin_quickstart]
}

main();
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
10 changes: 5 additions & 5 deletions packages/google-cloud-oslogin/samples/test/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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:');
it('should run the quickstart', () => {
const output = exec(
'node quickstart users/kokoro-system-test@long-door-651.iam.gserviceaccount.com'
);
assert(output !== null);
});
});

0 comments on commit c1d8ea9

Please sign in to comment.