From e89012709b857b5cc36c91481970550409da4dd6 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Wed, 7 Jul 2021 16:15:37 -0400 Subject: [PATCH 1/2] feat: add initial samples and tests --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .kokoro/common.cfg | 4 +- .kokoro/continuous/node10/common.cfg | 4 +- .kokoro/continuous/node10/docs.cfg | 2 +- .kokoro/continuous/node12/common.cfg | 4 +- .kokoro/continuous/node12/lint.cfg | 2 +- .kokoro/continuous/node12/samples-test.cfg | 2 +- .kokoro/continuous/node12/system-test.cfg | 2 +- .kokoro/presubmit/node10/common.cfg | 4 +- .kokoro/presubmit/node12/common.cfg | 4 +- .kokoro/presubmit/node12/samples-test.cfg | 2 +- .kokoro/presubmit/node12/system-test.cfg | 2 +- .kokoro/release/docs-devsite.cfg | 4 +- .kokoro/release/docs.cfg | 4 +- .kokoro/release/publish.cfg | 4 +- README.md | 40 ++++++++++++++++- linkinator.config.json | 11 ++++- package.json | 2 +- samples/README.md | 50 ++++++++++++++++++++++ samples/quickstart.js | 26 +++++------ samples/test/quickstart.js | 16 ++----- 21 files changed, 139 insertions(+), 52 deletions(-) create mode 100644 samples/README.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 0e7070e..a2c5944 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,7 +12,7 @@ Thanks for stopping by to let us know something could be better! This is the client library for . We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the [ Support page]() to reach the most relevant engineers. 2) Did someone already solve this? - - Search the issues already opened: https://github.com/googleapis/googleapis/issues + - Search the issues already opened: https://github.com/googleapis/nodejs-dataflow/issues - Search the issues on our "catch-all" repository: https://github.com/googleapis/google-cloud-node - Search or ask on StackOverflow (engineers monitor these tags): http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index 212302c..ed8c8b0 100644 --- a/.kokoro/common.cfg +++ b/.kokoro/common.cfg @@ -11,7 +11,7 @@ action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -20,5 +20,5 @@ env_vars: { } env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/test.sh" + value: "github/nodejs-dataflow/.kokoro/test.sh" } diff --git a/.kokoro/continuous/node10/common.cfg b/.kokoro/continuous/node10/common.cfg index fdeaf15..41cf79d 100644 --- a/.kokoro/continuous/node10/common.cfg +++ b/.kokoro/continuous/node10/common.cfg @@ -21,7 +21,7 @@ before_action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -30,5 +30,5 @@ env_vars: { } env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/test.sh" + value: "github/nodejs-dataflow/.kokoro/test.sh" } diff --git a/.kokoro/continuous/node10/docs.cfg b/.kokoro/continuous/node10/docs.cfg index f0f5b57..225f89d 100644 --- a/.kokoro/continuous/node10/docs.cfg +++ b/.kokoro/continuous/node10/docs.cfg @@ -1,4 +1,4 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/docs.sh" + value: "github/nodejs-dataflow/.kokoro/docs.sh" } diff --git a/.kokoro/continuous/node12/common.cfg b/.kokoro/continuous/node12/common.cfg index 3799d0f..f242519 100644 --- a/.kokoro/continuous/node12/common.cfg +++ b/.kokoro/continuous/node12/common.cfg @@ -11,7 +11,7 @@ action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -20,5 +20,5 @@ env_vars: { } env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/test.sh" + value: "github/nodejs-dataflow/.kokoro/test.sh" } diff --git a/.kokoro/continuous/node12/lint.cfg b/.kokoro/continuous/node12/lint.cfg index e20a4d6..8a410db 100644 --- a/.kokoro/continuous/node12/lint.cfg +++ b/.kokoro/continuous/node12/lint.cfg @@ -1,4 +1,4 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/lint.sh" + value: "github/nodejs-dataflow/.kokoro/lint.sh" } diff --git a/.kokoro/continuous/node12/samples-test.cfg b/.kokoro/continuous/node12/samples-test.cfg index 59ad98b..0c5513e 100644 --- a/.kokoro/continuous/node12/samples-test.cfg +++ b/.kokoro/continuous/node12/samples-test.cfg @@ -3,5 +3,5 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/samples-test.sh" + value: "github/nodejs-dataflow/.kokoro/samples-test.sh" } diff --git a/.kokoro/continuous/node12/system-test.cfg b/.kokoro/continuous/node12/system-test.cfg index 91827e7..e901118 100644 --- a/.kokoro/continuous/node12/system-test.cfg +++ b/.kokoro/continuous/node12/system-test.cfg @@ -3,5 +3,5 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/system-test.sh" + value: "github/nodejs-dataflow/.kokoro/system-test.sh" } diff --git a/.kokoro/presubmit/node10/common.cfg b/.kokoro/presubmit/node10/common.cfg index fdeaf15..41cf79d 100644 --- a/.kokoro/presubmit/node10/common.cfg +++ b/.kokoro/presubmit/node10/common.cfg @@ -21,7 +21,7 @@ before_action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -30,5 +30,5 @@ env_vars: { } env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/test.sh" + value: "github/nodejs-dataflow/.kokoro/test.sh" } diff --git a/.kokoro/presubmit/node12/common.cfg b/.kokoro/presubmit/node12/common.cfg index 3799d0f..f242519 100644 --- a/.kokoro/presubmit/node12/common.cfg +++ b/.kokoro/presubmit/node12/common.cfg @@ -11,7 +11,7 @@ action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -20,5 +20,5 @@ env_vars: { } env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/test.sh" + value: "github/nodejs-dataflow/.kokoro/test.sh" } diff --git a/.kokoro/presubmit/node12/samples-test.cfg b/.kokoro/presubmit/node12/samples-test.cfg index 59ad98b..0c5513e 100644 --- a/.kokoro/presubmit/node12/samples-test.cfg +++ b/.kokoro/presubmit/node12/samples-test.cfg @@ -3,5 +3,5 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/samples-test.sh" + value: "github/nodejs-dataflow/.kokoro/samples-test.sh" } diff --git a/.kokoro/presubmit/node12/system-test.cfg b/.kokoro/presubmit/node12/system-test.cfg index 91827e7..e901118 100644 --- a/.kokoro/presubmit/node12/system-test.cfg +++ b/.kokoro/presubmit/node12/system-test.cfg @@ -3,5 +3,5 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/system-test.sh" + value: "github/nodejs-dataflow/.kokoro/system-test.sh" } diff --git a/.kokoro/release/docs-devsite.cfg b/.kokoro/release/docs-devsite.cfg index d4438b5..7727441 100644 --- a/.kokoro/release/docs-devsite.cfg +++ b/.kokoro/release/docs-devsite.cfg @@ -18,9 +18,9 @@ env_vars: { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/release/docs-devsite.sh" + value: "github/nodejs-dataflow/.kokoro/release/docs-devsite.sh" } diff --git a/.kokoro/release/docs.cfg b/.kokoro/release/docs.cfg index c95fdfd..8a1ec15 100644 --- a/.kokoro/release/docs.cfg +++ b/.kokoro/release/docs.cfg @@ -18,9 +18,9 @@ env_vars: { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/release/docs.sh" + value: "github/nodejs-dataflow/.kokoro/release/docs.sh" } diff --git a/.kokoro/release/publish.cfg b/.kokoro/release/publish.cfg index c3df06b..92cbf80 100644 --- a/.kokoro/release/publish.cfg +++ b/.kokoro/release/publish.cfg @@ -16,7 +16,7 @@ env_vars: { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "googleapis/.kokoro/trampoline_v2.sh" +build_file: "nodejs-dataflow/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { @@ -26,5 +26,5 @@ env_vars: { env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/googleapis/.kokoro/publish.sh" + value: "github/nodejs-dataflow/.kokoro/publish.sh" } diff --git a/README.md b/README.md index a6f8167..ea2d5b2 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. * [Quickstart](#quickstart) * [Before you begin](#before-you-begin) * [Installing the client library](#installing-the-client-library) - - + * [Using the client library](#using-the-client-library) +* [Samples](#samples) * [Versioning](#versioning) * [Contributing](#contributing) * [License](#license) @@ -55,6 +55,42 @@ npm install @google-cloud/dataflow ``` +### Using the client library + +```javascript +// Imports the Google Cloud client library + +const {TemplatesServiceClient} = require('@google-cloud/dataflow'); + +// TODO(developer): replace with your prefered project ID. +// const projectId = 'my-project' +// TODO(developer): replace with your bucket path. +// const gcsPath = 'gs:///path' + +// Creates a client +const client = new TemplatesServiceClient(); + +//TODO(library generator): write the actual function you will be testing +async function getTemplate() { + const template = await client.getTemplate({ + projectId, + gcsPath, + }); + console.info(template); +} +getTemplate(); + +``` + + + +## Samples + +Samples are in the [`samples/`](https://github.com/googleapis/nodejs-dataflow/tree/master/samples) directory. Each sample's `README.md` has instructions for running its sample. + +| Sample | Source Code | Try it | +| --------------------------- | --------------------------------- | ------ | +| Quickstart | [source code](https://github.com/googleapis/nodejs-dataflow/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dataflow&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) | diff --git a/linkinator.config.json b/linkinator.config.json index 0947c2e..29a223b 100644 --- a/linkinator.config.json +++ b/linkinator.config.json @@ -1 +1,10 @@ -{"recurse":true,"skip":["https://codecov.io/gh/googleapis/","www.googleapis.com","img.shields.io"],"silent":true,"concurrency":10} \ No newline at end of file +{ + "recurse": true, + "skip": [ + "https://codecov.io/gh/googleapis/", + "www.googleapis.com", + "img.shields.io" + ], + "silent": true, + "concurrency": 10 +} diff --git a/package.json b/package.json index f2b3b8d..9da14a5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@google-cloud/dataflow", "version": "0.1.0", "description": "dataflow client for Node.js", - "repository": "googleapis/googleapis/nodejs-dataflow", + "repository": "googleapis/nodejs-dataflow", "license": "Apache-2.0", "author": "Google LLC", "main": "build/src/index.js", diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 0000000..33d049b --- /dev/null +++ b/samples/README.md @@ -0,0 +1,50 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `python -m synthtool`." +Google Cloud Platform logo + +# [Dataflow: Node.js Samples](https://github.com/googleapis/nodejs-dataflow) + +[![Open in Cloud Shell][shell_img]][shell_link] + + + +## Table of Contents + +* [Before you begin](#before-you-begin) +* [Samples](#samples) + * [Quickstart](#quickstart) + +## Before you begin + +Before running the samples, make sure you've followed the steps outlined in +[Using the client library](https://github.com/googleapis/nodejs-dataflow#using-the-client-library). + +`cd samples` + +`npm install` + +`cd ..` + +## Samples + + + +### Quickstart + +View the [source code](https://github.com/googleapis/nodejs-dataflow/blob/master/samples/quickstart.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dataflow&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) + +__Usage:__ + + +`node samples/quickstart.js` + + + + + + +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dataflow&page=editor&open_in_editor=samples/README.md +[product-docs]: https://cloud.google.com/dataflow/ diff --git a/samples/quickstart.js b/samples/quickstart.js index c9bd335..58a6681 100644 --- a/samples/quickstart.js +++ b/samples/quickstart.js @@ -13,30 +13,32 @@ 'use strict'; -async function main() { - +async function main( + projectId, + gcsPath = 'gs://dataflow-templates/latest/PubSub_Subscription_to_BigQuery' +) { // [START nodejs_dataflow_quickstart] // Imports the Google Cloud client library - // remove this line after package is released - // eslint-disable-next-line node/no-missing-require const {TemplatesServiceClient} = require('@google-cloud/dataflow'); // TODO(developer): replace with your prefered project ID. // const projectId = 'my-project' + // TODO(developer): replace with your bucket path. + // const gcsPath = 'gs:///path' // Creates a client - // eslint-disable-next-line no-unused-vars - const client = new {TemplatesServiceClient}(); + const client = new TemplatesServiceClient(); //TODO(library generator): write the actual function you will be testing - async function doSomething() { - console.log('DPE! Change this code so that it shows how to use the library! See comments below on structure.') - // const [thing] = await client.methodName({ - // }); - // console.info(thing); + async function getTemplate() { + const template = await client.getTemplate({ + projectId, + gcsPath, + }); + console.info(template); } - doSomething(); + getTemplate(); // [END nodejs_dataflow_quickstart] } diff --git a/samples/test/quickstart.js b/samples/test/quickstart.js index c39f1fe..9d8816c 100644 --- a/samples/test/quickstart.js +++ b/samples/test/quickstart.js @@ -20,34 +20,24 @@ const path = require('path'); const cp = require('child_process'); const {before, describe, it} = require('mocha'); -// eslint-disable-next-line node/no-missing-require const {TemplatesServiceClient} = require('@google-cloud/dataflow'); -// eslint-disable-next-line no-unused-vars, node/no-missing-require const {assert} = require('chai'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); -const client = new {TemplatesServiceClient}(); +const client = new TemplatesServiceClient(); describe('Quickstart', () => { - //TODO: remove this if not using the projectId - // eslint-disable-next-line no-unused-vars let projectId; before(async () => { - // eslint-disable-next-line no-unused-vars projectId = await client.getProjectId(); }); it('should run quickstart', async () => { - //TODO: remove this line - // eslint-disable-next-line no-unused-vars - const stdout = execSync( - `node ./quickstart.js`, - {cwd} - ); - //assert(stdout, stdout !== null); + const stdout = execSync(`node ./quickstart.js ${projectId}`, {cwd}); + assert.match(stdout, /status: null/); }); }); From 545edbb500c6038c78fdaa7f1184f22d241acfbc Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Wed, 7 Jul 2021 16:21:48 -0400 Subject: [PATCH 2/2] feat: add initial samples and tests --- .github/.OwlBot.lock.yaml | 2 +- linkinator.config.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 8413c14..0a507a0 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: - digest: sha256: + digest: sha256:41d5457ff79c3945782ab7e23bf4d617fd7bf3f2b03b6d84808010f7d2e10ca2 image: gcr.io/repo-automation-bots/owlbot-nodejs:latest diff --git a/linkinator.config.json b/linkinator.config.json index 29a223b..1fbcfb0 100644 --- a/linkinator.config.json +++ b/linkinator.config.json @@ -3,7 +3,8 @@ "skip": [ "https://codecov.io/gh/googleapis/", "www.googleapis.com", - "img.shields.io" + "img.shields.io", + "https://github.com/googleapis/nodejs-dataflow/blob/master/CHANGELOG.md" ], "silent": true, "concurrency": 10