From c0331f377d877976cfd37be2c10fb3865d3cfb91 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 3 Apr 2018 13:52:48 -0700 Subject: [PATCH 1/2] Fix bug in quickstart --- kms/quickstart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kms/quickstart.js b/kms/quickstart.js index cdd0eb5f47..71448d50a3 100644 --- a/kms/quickstart.js +++ b/kms/quickstart.js @@ -54,11 +54,11 @@ google.auth.getApplicationDefault((err, authClient) => { return; } - const keyRings = result.keyRings || []; + const keyRings = result.data.keyRings || []; if (keyRings.length) { console.log('Key rings:'); - result.keyRings.forEach((keyRing) => console.log(keyRing.name)); + keyRings.forEach((keyRing) => console.log(keyRing.name)); } else { console.log(`No key rings found.`); } From ae71991ce576a31a5c5daf7f40705821d2063990 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 4 Apr 2018 10:27:05 -0700 Subject: [PATCH 2/2] Fix quickstart sample + convert test to system-test --- kms/quickstart.js | 2 +- kms/system-test/quickstart.test.js | 74 ++---------------------------- 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/kms/quickstart.js b/kms/quickstart.js index 71448d50a3..b385713bd5 100644 --- a/kms/quickstart.js +++ b/kms/quickstart.js @@ -20,7 +20,7 @@ const google = require('googleapis').google; // Your Google Cloud Platform project ID -const projectId = 'YOUR_PROJECT_ID'; +const projectId = process.env.GCLOUD_PROJECT; // Lists keys in the "global" location. const location = 'global'; diff --git a/kms/system-test/quickstart.test.js b/kms/system-test/quickstart.test.js index 7f55cd4549..9a138d71c4 100644 --- a/kms/system-test/quickstart.test.js +++ b/kms/system-test/quickstart.test.js @@ -15,77 +15,11 @@ 'use strict'; -const proxyquire = require(`proxyquire`).noPreserveCache(); -const google = proxyquire(`googleapis`, {}); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); -function list (callback) { - google.auth.getApplicationDefault((err, authClient) => { - if (err) { - callback(err); - return; - } - - if (authClient.createScopedRequired && authClient.createScopedRequired()) { - authClient = authClient.createScoped([ - 'https://www.googleapis.com/auth/cloud-platform' - ]); - } - - const cloudkms = google.cloudkms({ - version: 'v1', - auth: authClient - }); - const params = { - parent: `projects/${process.env.GCLOUD_PROJECT}/locations/global` - }; - - cloudkms.projects.locations.keyRings.list(params, callback); - }); -} - -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test.cb(`should list key rings`, (t) => { - const googleapisMock = { - cloudkms () { - return { - projects: { - locations: { - keyRings: { - list (params, callback) { - list((err, result) => { - if (err) { - t.end(err); - return; - } - callback(err, result); - - setTimeout(() => { - try { - t.true(console.log.called); - if (result && result.keyRings && result.keyRings.length) { - t.deepEqual(console.log.getCall(0).args, [`Key rings:`]); - } else { - t.deepEqual(console.log.getCall(0).args, [`No key rings found.`]); - } - t.end(); - } catch (err) { - t.end(err); - } - }, 200); - }); - } - } - } - } - }; - } - }; - - proxyquire(`../quickstart`, { - 'googleapis': googleapisMock - }); +test(`should list key rings`, async t => { + const output = await tools.runAsync(`node quickstart.js`); + t.regex(output, /Key rings:/); + t.true(output.includes(`/locations/global/keyRings/`)); });