Skip to content

Commit

Permalink
feat: add tests and samples to library (#5)
Browse files Browse the repository at this point in the history
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sofisl and gcf-owl-bot[bot] authored Jan 10, 2022
1 parent b612610 commit 58dffce
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 41 deletions.
9 changes: 5 additions & 4 deletions packages/google-cloud-ids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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`)
Expand All @@ -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/
Expand Down
13 changes: 12 additions & 1 deletion packages/google-cloud-ids/linkinator.config.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{"recurse":true,"skip":["https://codecov.io/gh/googleapis/","www.googleapis.com","img.shields.io"],"silent":true,"concurrency":5}
{
"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
}
2 changes: 1 addition & 1 deletion packages/google-cloud-ids/protos/protos.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/google-cloud-ids/protos/protos.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 52 additions & 26 deletions packages/google-cloud-ids/samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -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));
11 changes: 3 additions & 8 deletions packages/google-cloud-ids/samples/test/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
});
});

0 comments on commit 58dffce

Please sign in to comment.