Skip to content

Commit

Permalink
New quickstarts. (#226)
Browse files Browse the repository at this point in the history
* New quickstarts.

* Address comments.
  • Loading branch information
jmdobry authored and Ace Nassri committed Oct 3, 2016
0 parents commit cb9857d
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/google-cloud-dns/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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"/>

# Google Cloud DNS Node.js Samples

Publish your domain names using Google's infrastructure for production-quality,
high-volume DNS services. Google's global network of anycast name servers
provide reliable, low-latency authoritative name lookups for your domains from
anywhere in the world. Read more about [Google Cloud DNS][dns_docs].

[dns_docs]: https://cloud.google.com/dns/docs

## Table of Contents

* [Setup](#setup)
* [Samples](#samples)
* [Zones](#zones)

## Setup

1. Read [Prerequisites][prereq] and [How to run a sample][run] first.
1. Install dependencies:

npm install

[prereq]: ../README.md#prerequisities
[run]: ../README.md#how-to-run-a-sample

## Samples

### Zones

View the [documentation][zones_docs] or the [source code][zones_code].

__Usage:__ `node zones --help`

```
Commands:
list Lists all zones in the current project.
Options:
--help Show help [boolean]
Examples:
node zones list Lists all zones in the current project.
For more information, see https://cloud.google.com/dns/docs
```

[zones_docs]: https://cloud.google.com/dns/docs
[zones_code]: zones.js
22 changes: 22 additions & 0 deletions packages/google-cloud-dns/samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "nodejs-docs-samples-dns",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"scripts": {
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"@google-cloud/dns": "^0.2.0",
"yargs": "^6.0.0"
},
"devDependencies": {
"mocha": "^3.1.0",
"uuid": "^2.0.3"
},
"engines": {
"node": ">=4.3.2"
}
}
40 changes: 40 additions & 0 deletions packages/google-cloud-dns/samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2016, Google, Inc.
* 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
*
* 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';

// [START dns_quickstart]
// Imports the Google Cloud client library
const DNS = require('@google-cloud/dns');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Instantiates a client
const dnsClient = DNS({
projectId: projectId
});

// Lists all zones in the current project
dnsClient.getZones((err, zones) => {
if (err) {
console.error(err);
return;
}

console.log('Zones:');
zones.forEach((zone) => console.log(zone.name));
});
// [END dns_quickstart]
43 changes: 43 additions & 0 deletions packages/google-cloud-dns/samples/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2016, Google, Inc.
* 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
*
* 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';

const proxyquire = require(`proxyquire`).noCallThru();

describe(`dns:quickstart`, () => {
let dnsMock, DNSMock;
const error = new Error(`error`);

before(() => {
dnsMock = {
getZones: sinon.stub().yields(error)
};
DNSMock = sinon.stub().returns(dnsMock);
});

it(`should handle error`, () => {
proxyquire(`../quickstart`, {
'@google-cloud/dns': DNSMock
});

assert.equal(DNSMock.calledOnce, true);
assert.deepEqual(DNSMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(dnsMock.getZones.calledOnce, true);
assert.deepEqual(dnsMock.getZones.firstCall.args.slice(0, -1), []);
assert.equal(console.error.calledOnce, true);
assert.deepEqual(console.error.firstCall.args, [error]);
});
});

0 comments on commit cb9857d

Please sign in to comment.