Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
feat: add samples (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored May 25, 2021
1 parent 1746468 commit 18b317a
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docker:
image: gcr.io/repo-automation-bots/owlbot-nodejs:latest
digest: sha256:b94b09fb24bf804090b8cc60ee726ca161d5e5915151e417f8ef5d8bcfe73cbc
digest: sha256:f556e6e7be625deb1b2429fe608df27be57185c3e6b7d39ee0059f1609f17530
3 changes: 3 additions & 0 deletions .github/generated-files-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ generatedFiles:
message: '`README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/master/.readme-partials.yaml'
- path: 'samples/README.md'
message: '`samples/README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/master/.readme-partials.yaml'
ignoreAuthors:
- 'gcf-owl-bot[bot]'
- 'yoshi-automation'
55 changes: 55 additions & 0 deletions .jsdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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
//
// 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.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

module.exports = {
opts: {
readme: './README.md',
package: './package.json',
template: './node_modules/jsdoc-fresh',
recurse: true,
verbose: true,
destination: './docs/'
},
plugins: [
'plugins/markdown',
'jsdoc-region-tag'
],
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'build/src',
'protos'
],
includePattern: '\\.js$'
},
templates: {
copyright: 'Copyright 2021 Google LLC',
includeDate: false,
sourceFiles: false,
systemName: '@google-cloud/secret-manager',
theme: 'lumen',
default: {
outputSourceFiles: false
}
},
markdown: {
idInHeadings: true
}
};
2 changes: 1 addition & 1 deletion .repo-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name_pretty": "Cloud Database Migration Service",
"product_documentation": "https://cloud.google.com/database-migration/",
"client_documentation": "https://googleapis.dev/nodejs/dms/latest",
"issue_tracker": "",
"issue_tracker": "https://github.com/googleapis/nodejs-dms/issues",
"release_level": "ga",
"language": "nodejs",
"repo": "googleapis/nodejs-dms",
Expand Down
34 changes: 32 additions & 2 deletions 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,36 @@ npm install @google-cloud/dms
```


### Using the client library

```javascript
// Imports the Google Cloud client library
const {DataMigrationServiceClient} = require('@google-cloud/dms');

// const parent = 'projects/my-project', // Project to list service usage for.

// Creates a client
const client = new DataMigrationServiceClient();
async function listMigrationJobs() {
for await (const migration of client.listMigrationJobsAsync({
parent: `projects/${projectId}/locations/${location}`,
})) {
console.info(`${migration.name} ${migration.state}`);
}
}
listMigrationJobs();

```



## Samples

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



Expand Down
50 changes: 50 additions & 0 deletions 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"/>

# [Cloud Database Migration Service: Node.js Samples](https://github.com/googleapis/nodejs-dms)

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

`cd samples`

`npm install`

`cd ..`

## Samples



### Quickstart

View the [source code](https://github.com/googleapis/nodejs-dms/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-dms&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-dms&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/database-migration/
23 changes: 23 additions & 0 deletions samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nodejs-dms",
"private": true,
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=10"
},
"files": [
"*.js"
],
"scripts": {
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/dms": "^0.1.0"
},
"devDependencies": {
"c8": "^7.1.0",
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
44 changes: 44 additions & 0 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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
//
// 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(projectId = 'my-project', location = 'us-central1') {
// [START dms_quickstart]
// Imports the Google Cloud client library
const {DataMigrationServiceClient} = require('@google-cloud/dms');

// const parent = 'projects/my-project', // Project to list service usage for.

// Creates a client
const client = new DataMigrationServiceClient();
async function listMigrationJobs() {
for await (const migration of client.listMigrationJobsAsync({
parent: `projects/${projectId}/locations/${location}`,
})) {
console.info(`${migration.name} ${migration.state}`);
}
}
listMigrationJobs();
// [END dms_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;
});
45 changes: 45 additions & 0 deletions samples/test/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// 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
//
// 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.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

const path = require('path');
const cp = require('child_process');
const {before, describe, it} = require('mocha');
const {DataMigrationServiceClient} = require('@google-cloud/dms');
const {assert} = require('chai');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

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

const client = new DataMigrationServiceClient();

describe('Quickstart', () => {
let projectId;
before(async () => {
// eslint-disable-next-line no-unused-vars
projectId = await client.getProjectId();
});

it('should run quickstart', async () => {
const stdout = execSync(`node ./quickstart.js ${projectId} us-central1`, {
cwd,
});
assert.match(stdout, /DRAFT/);
});
});
2 changes: 1 addition & 1 deletion system-test/fixtures/sample/src/index.js
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 clouddms = require('@google-cloud/clouddms');
const clouddms = require('@google-cloud/dms');

function main() {
const dataMigrationServiceClient = new clouddms.DataMigrationServiceClient();
Expand Down
2 changes: 1 addition & 1 deletion system-test/fixtures/sample/src/index.ts
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 {DataMigrationServiceClient} from '@google-cloud/clouddms';
import {DataMigrationServiceClient} from '@google-cloud/dms';

// check that the client class type name can be used
function doStuffWithDataMigrationServiceClient(
Expand Down

0 comments on commit 18b317a

Please sign in to comment.