File tree 3 files changed +46
-30
lines changed
packages/google-cloud-oslogin/samples
3 files changed +46
-30
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " nodejs-docs-samples-os-login" ,
3
- "version" : " 0.0.1" ,
4
3
"license" : " Apache-2.0" ,
5
4
"author" : " Google Inc." ,
6
5
"engines" : {
7
6
"node" : " >=8"
8
7
},
8
+ "files" : [
9
+ " *.js"
10
+ ],
9
11
"repository" : " googleapis/nodejs-os-login" ,
10
12
"private" : true ,
11
- "semistandard" : {
12
- "ignore" : [
13
- " node_modules"
14
- ]
15
- },
16
13
"scripts" : {
17
- "test" : " node -e 'console.log(`no tests`)' "
14
+ "test" : " mocha "
18
15
},
19
16
"dependencies" : {
20
17
"@google-cloud/os-login" : " ^0.3.2"
21
18
},
22
19
"devDependencies" : {
23
- "@google-cloud/nodejs-repo-tools" : " ^3.0.0"
20
+ "chai" : " ^4.2.0" ,
21
+ "mocha" : " ^6.1.4"
24
22
}
25
23
}
Original file line number Diff line number Diff line change 16
16
17
17
async function main ( ) {
18
18
// [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
+
25
+ } ) ;
26
+ console . log ( 'Login Profile:' ) ;
27
+ console . log ( loginProfile ) ;
26
28
}
27
29
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 ( ) ;
42
31
// [END oslogin_quickstart]
43
32
}
44
33
45
- main ( ) . catch ( console . error ) ;
34
+ main ( ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments