Skip to content

Commit f44ef33

Browse files
JustinBeckwithNimJay
authored andcommitted
test: add a sample test (#143)
1 parent 8844503 commit f44ef33

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

dataproc/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
"name": "nodejs-docs-samples-dataproc",
33
"license": "Apache-2.0",
44
"author": "Google Inc.",
5+
"files": ["*.js"],
56
"engines": {
67
"node": ">=8"
78
},
89
"repository": "googleapis/nodejs-dataproc",
910
"private": true,
1011
"scripts": {
11-
"test": "echo no tests 👻"
12+
"test": "mocha system-test --timeout 60000"
1213
},
1314
"dependencies": {
1415
"@google-cloud/dataproc": "^0.3.0"
1516
},
1617
"devDependencies": {
17-
"@google-cloud/nodejs-repo-tools": "^3.0.0"
18+
"chai": "^4.2.0",
19+
"execa": "^1.0.0",
20+
"mocha": "^5.2.0"
1821
}
1922
}

dataproc/quickstart.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@
1414
*/
1515

1616
'use strict';
17-
async function main() {
18-
// [START dataproc_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 json key> node #{$0}'
25-
);
26-
}
2717

18+
// [START dataproc_quickstart]
19+
async function quickstart() {
2820
const dataproc = require('@google-cloud/dataproc');
29-
3021
const client = new dataproc.v1.ClusterControllerClient({
3122
// optional auth parameters.
3223
});
@@ -35,15 +26,12 @@ async function main() {
3526

3627
// Iterate over all elements.
3728
const region = 'global';
38-
const request = {
39-
projectId: projectId,
40-
region: region,
41-
};
29+
const request = {projectId, region};
4230

4331
const [resources] = await client.listClusters(request);
4432
console.log('Total resources:', resources.length);
45-
for (let i = 0; i < resources.length; i += 1) {
46-
console.log(resources[i]);
33+
for (const resource of resources) {
34+
console.log(resource);
4735
}
4836

4937
let nextRequest = request;
@@ -57,15 +45,15 @@ async function main() {
5745
nextRequest = responses[1];
5846
// The actual response object, if necessary.
5947
// const rawResponse = responses[2];
60-
for (let i = 0; i < resources.length; i += 1) {
61-
console.log(resources[i]);
48+
for (const resource of resources) {
49+
console.log(resource);
6250
}
6351
} while (nextRequest);
6452

6553
client.listClustersStream(request).on('data', element => {
6654
console.log(element);
6755
});
68-
// [END dataproc_quickstart]
6956
}
57+
// [END dataproc_quickstart]
7058

71-
main().catch(console.error);
59+
quickstart().catch(console.error);

dataproc/system-test/.eslintrc.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
---
2-
rules:
3-
node/no-unpublished-require: off
4-
node/no-unsupported-features: off
5-
no-empty: off
2+
env:
3+
mocha: true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2017, Google, Inc.
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+
16+
const {assert} = require('chai');
17+
const execa = require('execa');
18+
19+
describe('dataproc samples', () => {
20+
it('should run the quickstart', async () => {
21+
const {stdout} = await execa.shell('node quickstart');
22+
assert.match(stdout, /Total resources:/);
23+
});
24+
});

0 commit comments

Comments
 (0)