Skip to content

Commit

Permalink
fix(samples): fix the sample and add a system test (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 29, 2018
1 parent a331501 commit 5c5c3d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
12 changes: 4 additions & 8 deletions packages/google-cloud-bigquery-datatransfer/samples/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{
"name": "nodejs-docs-samples-bigquery-data-transfer",
"version": "0.0.1",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
"node": ">=8"
},
"files": ["*.js"],
"repository": "googleapis/nodejs-bigquery-data-transfer",
"private": true,
"semistandard": {
"ignore": [
"node_modules"
]
},
"scripts": {
"test": "node -e 'console.log(`no tests`)'"
"test": "mocha system-test --timeout 60000"
},
"dependencies": {
"@google-cloud/bigquery-data-transfer": "^0.4.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0"
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"mocha": "^5.2.0"
}
}
20 changes: 9 additions & 11 deletions packages/google-cloud-bigquery-datatransfer/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ async function main() {
const projectId = process.env.GCLOUD_PROJECT;

// Iterate over all elements.
const formattedParent = client.locationPath(projectId, 'us-central1');

const [resources] = await client.listDataSources({parent: formattedParent});
for (let i = 0; i < resources.length; i += 1) {
console.log(resources[i]);
}

const formattedParent = client.projectPath(projectId, 'us-central1');
let nextRequest = {parent: formattedParent};
const options = {autoPaginate: false};
console.log('Data sources:');
do {
// Fetch the next page.
const responses = await client.listDataSources(nextRequest, options);
Expand All @@ -51,15 +46,18 @@ 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]);
}
resources.forEach(resource => {
console.log(` ${resource.name}`);
});
} while (nextRequest);

console.log('\n\n');
console.log('Sources via stream:');

client
.listDataSourcesStream({parent: formattedParent})
.on('data', element => {
console.log(element);
console.log(` ${element.name}`);
});
// [END bigquerydatatransfer_quickstart]
}
Expand Down

0 comments on commit 5c5c3d0

Please sign in to comment.