From 7896db3256039dddd930a36f76e5c957054a55fb Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 18 Dec 2018 16:05:37 -0800 Subject: [PATCH] test: add a sample test (#143) --- dataproc/package.json | 7 ++++-- dataproc/quickstart.js | 30 ++++++++----------------- dataproc/system-test/.eslintrc.yml | 6 ++--- dataproc/system-test/quickstart.test.js | 24 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 dataproc/system-test/quickstart.test.js diff --git a/dataproc/package.json b/dataproc/package.json index 1d501bb22f..f118b5d507 100644 --- a/dataproc/package.json +++ b/dataproc/package.json @@ -2,18 +2,21 @@ "name": "nodejs-docs-samples-dataproc", "license": "Apache-2.0", "author": "Google Inc.", + "files": ["*.js"], "engines": { "node": ">=8" }, "repository": "googleapis/nodejs-dataproc", "private": true, "scripts": { - "test": "echo no tests 👻" + "test": "mocha system-test --timeout 60000" }, "dependencies": { "@google-cloud/dataproc": "^0.3.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.0.0" + "chai": "^4.2.0", + "execa": "^1.0.0", + "mocha": "^5.2.0" } } diff --git a/dataproc/quickstart.js b/dataproc/quickstart.js index f2a3098a41..1df42267f8 100644 --- a/dataproc/quickstart.js +++ b/dataproc/quickstart.js @@ -14,19 +14,10 @@ */ 'use strict'; -async function main() { - // [START dataproc_quickstart] - if ( - !process.env.GCLOUD_PROJECT || - !process.env.GOOGLE_APPLICATION_CREDENTIALS - ) { - throw new Error( - 'Usage: GCLOUD_PROJECT= GOOGLE_APPLICATION_CREDENTIALS= node #{$0}' - ); - } +// [START dataproc_quickstart] +async function quickstart() { const dataproc = require('@google-cloud/dataproc'); - const client = new dataproc.v1.ClusterControllerClient({ // optional auth parameters. }); @@ -35,15 +26,12 @@ async function main() { // Iterate over all elements. const region = 'global'; - const request = { - projectId: projectId, - region: region, - }; + const request = {projectId, region}; const [resources] = await client.listClusters(request); console.log('Total resources:', resources.length); - for (let i = 0; i < resources.length; i += 1) { - console.log(resources[i]); + for (const resource of resources) { + console.log(resource); } let nextRequest = request; @@ -57,15 +45,15 @@ async function main() { nextRequest = responses[1]; // The actual response object, if necessary. // const rawResponse = responses[2]; - for (let i = 0; i < resources.length; i += 1) { - console.log(resources[i]); + for (const resource of resources) { + console.log(resource); } } while (nextRequest); client.listClustersStream(request).on('data', element => { console.log(element); }); - // [END dataproc_quickstart] } +// [END dataproc_quickstart] -main().catch(console.error); +quickstart().catch(console.error); diff --git a/dataproc/system-test/.eslintrc.yml b/dataproc/system-test/.eslintrc.yml index c0289282a6..6db2a46c53 100644 --- a/dataproc/system-test/.eslintrc.yml +++ b/dataproc/system-test/.eslintrc.yml @@ -1,5 +1,3 @@ --- -rules: - node/no-unpublished-require: off - node/no-unsupported-features: off - no-empty: off +env: + mocha: true diff --git a/dataproc/system-test/quickstart.test.js b/dataproc/system-test/quickstart.test.js new file mode 100644 index 0000000000..4c7fdbe18a --- /dev/null +++ b/dataproc/system-test/quickstart.test.js @@ -0,0 +1,24 @@ +/** + * Copyright 2017, Google, Inc. + * 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. + */ + +const {assert} = require('chai'); +const execa = require('execa'); + +describe('dataproc samples', () => { + it('should run the quickstart', async () => { + const {stdout} = await execa.shell('node quickstart'); + assert.match(stdout, /Total resources:/); + }); +});