Skip to content

Commit

Permalink
feat: write initial tests and samples (#2)
Browse files Browse the repository at this point in the history
* feat: write initial tests and samples

* 🦉 Updates from OwlBot

* fix: update docker image

* 🦉 Updates from OwlBot

* fix: publishing name

* fix: getting client

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sofisl and gcf-owl-bot[bot] committed Jun 9, 2021
1 parent 4c15a54 commit 693cf4d
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-vpc-access/.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
copyright: 'Copyright 2021 Google LLC',
includeDate: false,
sourceFiles: false,
systemName: '@google-cloud/vpcaccess',
systemName: '@google-cloud/vpc-access',
theme: 'lumen',
default: {
outputSourceFiles: false
Expand Down
39 changes: 37 additions & 2 deletions packages/google-cloud-vpc-access/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -55,6 +55,41 @@ npm install @google-cloud/vpc-access
```


### Using the client library

```javascript
// Imports the Google Cloud client library

// remove this line after package is released
// eslint-disable-next-line node/no-missing-require
const {VpcAccessServiceClient} = require('@google-cloud/vpc-access');

// TODO(developer): replace with your prefered project ID.
// const projectId = 'my-project'

// Creates a client
// eslint-disable-next-line no-unused-vars
const client = new VpcAccessServiceClient();

async function listConnectors() {
const connectors = await client.listConnectors({
parent: `projects/${projectId}/locations/${location}`,
});
console.info(connectors);
}
listConnectors();

```



## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-vpc-access/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-vpc-access/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-vpc-access&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |



Expand Down
12 changes: 11 additions & 1 deletion packages/google-cloud-vpc-access/linkinator.config.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"recurse":true,"skip":["https://codecov.io/gh/googleapis/","www.googleapis.com","img.shields.io"],"silent":true,"concurrency":10}
{
"recurse": true,
"skip": [
"https://github.com/googleapis/nodejs-vpc-access/blob/master/CHANGELOG.md",
"https://codecov.io/gh/googleapis/",
"www.googleapis.com",
"img.shields.io"
],
"silent": true,
"concurrency": 10
}
2 changes: 1 addition & 1 deletion packages/google-cloud-vpc-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@google-cloud/vpc-access",
"version": "0.1.0",
"description": "vpcaccess client for Node.js",
"repository": "googleapis/googleapis/nodejs-vpc-access",
"repository": "googleapis/nodejs-vpc-access",
"license": "Apache-2.0",
"author": "Google LLC",
"main": "build/src/index.js",
Expand Down
50 changes: 50 additions & 0 deletions packages/google-cloud-vpc-access/samples/README.md
Original file line number Diff line number Diff line change
@@ -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`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Virtual Private Cloud: Node.js Samples](https://github.com/googleapis/nodejs-vpc-access)

[![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-vpc-access#using-the-client-library).

`cd samples`

`npm install`

`cd ..`

## Samples



### Quickstart

View the [source code](https://github.com/googleapis/nodejs-vpc-access/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-vpc-access&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-vpc-access&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/vpc/
18 changes: 8 additions & 10 deletions packages/google-cloud-vpc-access/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

'use strict';

async function main() {

async function main(projectId, location) {
// [START nodejs_vpc_access_quickstart]
// Imports the Google Cloud client library

Expand All @@ -27,16 +26,15 @@ async function main() {

// Creates a client
// eslint-disable-next-line no-unused-vars
const client = new {VpcAccessServiceClient}();
const client = new VpcAccessServiceClient();

//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 listConnectors() {
const connectors = await client.listConnectors({
parent: `projects/${projectId}/locations/${location}`,
});
console.info(connectors);
}
doSomething();
listConnectors();
// [END nodejs_vpc_access_quickstart]
}

Expand Down
15 changes: 6 additions & 9 deletions packages/google-cloud-vpc-access/samples/test/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');

const client = new {VpcAccessServiceClient}();
const client = new VpcAccessServiceClient();

describe('Quickstart', () => {
//TODO: remove this if not using the projectId
//TODO: remove this if not using the projectId
// eslint-disable-next-line no-unused-vars
let projectId;

Expand All @@ -42,12 +42,9 @@ describe('Quickstart', () => {
});

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} us-central1`, {
cwd,
});
assert.match(stdout, /\[\]/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// ** All changes to this file may be overwritten. **

/* eslint-disable node/no-missing-require, no-unused-vars */
const vpcaccess = require('@google-cloud/vpcaccess');
const vpcaccess = require('@google-cloud/vpc-access');

function main() {
const vpcAccessServiceClient = new vpcaccess.VpcAccessServiceClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import {VpcAccessServiceClient} from '@google-cloud/vpcaccess';
import {VpcAccessServiceClient} from '@google-cloud/vpc-access';

// check that the client class type name can be used
function doStuffWithVpcAccessServiceClient(client: VpcAccessServiceClient) {
Expand Down

0 comments on commit 693cf4d

Please sign in to comment.