Skip to content

Commit

Permalink
test: add a sample test (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 19, 2018
1 parent 9198821 commit 7896db3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
7 changes: 5 additions & 2 deletions dataproc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
30 changes: 9 additions & 21 deletions dataproc/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to json key> node #{$0}'
);
}

// [START dataproc_quickstart]
async function quickstart() {
const dataproc = require('@google-cloud/dataproc');

const client = new dataproc.v1.ClusterControllerClient({
// optional auth parameters.
});
Expand All @@ -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;
Expand All @@ -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);
6 changes: 2 additions & 4 deletions dataproc/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
rules:
node/no-unpublished-require: off
node/no-unsupported-features: off
no-empty: off
env:
mocha: true
24 changes: 24 additions & 0 deletions dataproc/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -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:/);
});
});

0 comments on commit 7896db3

Please sign in to comment.