From 58dffce8a496e17457b9851819228f7a68223430 Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Mon, 10 Jan 2022 14:01:20 -0800 Subject: [PATCH] feat: add tests and samples to library (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add tests and samples to library * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- packages/google-cloud-ids/README.md | 9 ++- .../google-cloud-ids/linkinator.config.json | 13 +++- packages/google-cloud-ids/protos/protos.d.ts | 2 +- packages/google-cloud-ids/protos/protos.js | 2 +- .../google-cloud-ids/samples/quickstart.js | 78 ++++++++++++------- .../samples/test/quickstart.js | 11 +-- 6 files changed, 74 insertions(+), 41 deletions(-) diff --git a/packages/google-cloud-ids/README.md b/packages/google-cloud-ids/README.md index b671a7a08b0..ff859222d6e 100644 --- a/packages/google-cloud-ids/README.md +++ b/packages/google-cloud-ids/README.md @@ -6,7 +6,6 @@ [![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages) [![npm version](https://img.shields.io/npm/v/@google-cloud/ids.svg)](https://www.npmjs.org/package/@google-cloud/ids) -[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-ids/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-ids) @@ -15,7 +14,7 @@ ids client for Node.js A comprehensive list of changes in each version may be found in -[the CHANGELOG](https://github.com/googleapis/nodejs-ids/blob/master/CHANGELOG.md). +[the CHANGELOG](https://github.com/googleapis/nodejs-ids/blob/main/CHANGELOG.md). * [Cloud IDS Node.js Client API Reference][client-docs] * [Cloud IDS Documentation][product-docs] @@ -88,6 +87,7 @@ This library follows [Semantic Versioning](http://semver.org/). + This library is considered to be in **beta**. This means it is expected to be mostly stable while we work toward a general availability release; however, complete stability is not guaranteed. We will address issues and requests @@ -96,13 +96,14 @@ against beta libraries with a high priority. + More Information: [Google Cloud Platform Launch Stages][launch_stages] [launch_stages]: https://cloud.google.com/terms/launch-stages ## Contributing -Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-ids/blob/master/CONTRIBUTING.md). +Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-ids/blob/main/CONTRIBUTING.md). Please note that this `README.md`, the `samples/README.md`, and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) @@ -114,7 +115,7 @@ to its templates in Apache Version 2.0 -See [LICENSE](https://github.com/googleapis/nodejs-ids/blob/master/LICENSE) +See [LICENSE](https://github.com/googleapis/nodejs-ids/blob/main/LICENSE) [client-docs]: https://cloud.google.com/intrusion-detection-system [product-docs]: https://cloud.google.com/intrusion-detection-system/ diff --git a/packages/google-cloud-ids/linkinator.config.json b/packages/google-cloud-ids/linkinator.config.json index ecf12523e83..320128d151a 100644 --- a/packages/google-cloud-ids/linkinator.config.json +++ b/packages/google-cloud-ids/linkinator.config.json @@ -1 +1,12 @@ -{"recurse":true,"skip":["https://codecov.io/gh/googleapis/","www.googleapis.com","img.shields.io"],"silent":true,"concurrency":5} \ No newline at end of file +{ + "recurse": true, + "skip": [ + "https://codecov.io/gh/googleapis/", + "www.googleapis.com", + "img.shields.io", + "https://github.com/googleapis/nodejs-ids/blob/master/CHANGELOG.md", + "https://github.com/googleapis/nodejs-ids/blob/addSamples/CHANGELOG.md" + ], + "silent": true, + "concurrency": 5 +} diff --git a/packages/google-cloud-ids/protos/protos.d.ts b/packages/google-cloud-ids/protos/protos.d.ts index 28881b79dda..29753673485 100644 --- a/packages/google-cloud-ids/protos/protos.d.ts +++ b/packages/google-cloud-ids/protos/protos.d.ts @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-ids/protos/protos.js b/packages/google-cloud-ids/protos/protos.js index a411e4ce938..b94104c173c 100644 --- a/packages/google-cloud-ids/protos/protos.js +++ b/packages/google-cloud-ids/protos/protos.js @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-ids/samples/quickstart.js b/packages/google-cloud-ids/samples/quickstart.js index 9798932a00a..c05639c37e3 100644 --- a/packages/google-cloud-ids/samples/quickstart.js +++ b/packages/google-cloud-ids/samples/quickstart.js @@ -1,50 +1,76 @@ +// Copyright 2021 Google LLC +// // 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 // -// https://www.apache.org/licenses/LICENSE-2.0 +// 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. -// 'use strict'; -async function main() { +function main(parent) { + // [START nodejs-ids-quickstart] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The parent, which owns this collection of endpoints. + */ + // const parent = 'abc123' + /** + * Optional. The maximum number of endpoints to return. The service may return fewer + * than this value. + */ + // const pageSize = 1234 + /** + * Optional. A page token, received from a previous `ListEndpoints` call. + * Provide this to retrieve the subsequent page. + * When paginating, all other parameters provided to `ListEndpoints` must + * match the call that provided the page token. + */ + // const pageToken = 'abc123' + /** + * Optional. The filter expression, following the syntax outlined in + * https://google.aip.dev/160. + */ + // const filter = 'abc123' + /** + * Optional. One or more fields to compare and use to sort the output. + * See https://google.aip.dev/132#ordering. + */ + // const orderBy = 'abc123' - // [START nodejs_ids_quickstart] - // Imports the Google Cloud client library + // Imports the Ids library + const {IDSClient} = require('@google-cloud/ids').v1; - // remove this line after package is released - // eslint-disable-next-line node/no-missing-require - const {IDSClient} = require('@google-cloud/ids'); + // Instantiates a client + const idsClient = new IDSClient(); - // TODO(developer): replace with your prefered project ID. - // const projectId = 'my-project' + async function callListEndpoints() { + // Construct request + const request = { + parent, + }; - // Creates a client - // eslint-disable-next-line no-unused-vars - const client = new {IDSClient}(); - - //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); + // Run request + const iterable = await idsClient.listEndpointsAsync(request); + for await (const response of iterable) { + console.log(response); + } } - doSomething(); - // [END nodejs_ids_quickstart] + + callListEndpoints(); + // [END nodejs-ids-quickstart] } -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); process.on('unhandledRejection', err => { console.error(err.message); process.exitCode = 1; }); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-ids/samples/test/quickstart.js b/packages/google-cloud-ids/samples/test/quickstart.js index 4dada247b43..1ff8bc05312 100644 --- a/packages/google-cloud-ids/samples/test/quickstart.js +++ b/packages/google-cloud-ids/samples/test/quickstart.js @@ -29,25 +29,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); -const client = new {IDSClient}(); +const client = new IDSClient(); 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`, + `node ./quickstart.js projects/${projectId}/locations/us-east1-b`, {cwd} ); - //assert(stdout, stdout !== null); + assert.strictEqual(stdout, ''); }); });