Skip to content

Commit db124bc

Browse files
jmdobryAce Nassri
authored and
Ace Nassri
committed
New quickstarts. (GoogleCloudPlatform#226)
* New quickstarts. * Address comments.
1 parent 882cfb2 commit db124bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1432
-404
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ on Google Cloud Platform.
4848
* [Stackdriver Logging (Beta)](#stackdriver-logging-beta)
4949
* [Stackdriver Monitoring (Beta)](#stackdriver-monitoring-beta)
5050
* [Stackdriver Trace (Beta)](#stackdriver-trace-beta)
51+
* [**Networking**](#management-tools)
52+
* [Google Cloud DNS](#google-cloud-dns)
5153
* [Other sample applications](#other-sample-applications)
5254
* [Bookshelf tutorial app](#bookshelf-tutorial-app)
5355
* [LabelCat](#labelcat)
@@ -403,6 +405,22 @@ View the [Stackdriver Trace Node.js sample][trace_sample].
403405
[trace_docs]: https://cloud.google.com/trace/docs/
404406
[trace_sample]: trace
405407

408+
### Networking
409+
410+
#### Google Cloud DNS
411+
412+
Publish your domain names using Google's infrastructure for production-quality,
413+
high-volume DNS services. Google's global network of anycast name servers
414+
provide reliable, low-latency authoritative name lookups for your domains from
415+
anywhere in the world. Read more about [Google Cloud DNS][dns_docs].
416+
417+
[dns_docs]: https://cloud.google.com/dns/docs
418+
419+
View the [Google Cloud DNS Node.js sample][dns_sample].
420+
421+
[dns_docs]: https://cloud.google.com/dns/docs/
422+
[dns_sample]: dns
423+
406424
## Other sample applications
407425

408426
### Bookshelf tutorial app

bigquery/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"devDependencies": {
1919
"mocha": "^3.0.2",
2020
"node-uuid": "^1.4.7"
21+
},
22+
"engines": {
23+
"node": ">=4.3.2"
2124
}
2225
}

bigquery/quickstart.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -30,8 +32,11 @@ const datasetName = 'my_new_dataset';
3032

3133
// Creates the new dataset
3234
bigqueryClient.createDataset(datasetName, (err, dataset) => {
33-
if (!err) {
34-
// The dataset was created successfully
35+
if (err) {
36+
console.error(err);
37+
return;
3538
}
39+
40+
console.log(`Dataset ${dataset.name} created.`);
3641
});
3742
// [END bigquery_quickstart]

bigquery/system-test/quickstart.test.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -30,13 +32,17 @@ describe(`bigquery:quickstart`, () => {
3032

3133
it(`should create a dataset`, (done) => {
3234
bigqueryMock = {
33-
createDataset: (_datasetName) => {
35+
createDataset: (_datasetName, _callback) => {
3436
assert.equal(_datasetName, datasetName);
37+
assert.equal(typeof _callback, 'function');
3538

3639
bigquery.createDataset(datasetName, (err, dataset, apiResponse) => {
40+
_callback(err, dataset, apiResponse);
3741
assert.ifError(err);
3842
assert.notEqual(dataset, undefined);
3943
assert.notEqual(apiResponse, undefined);
44+
assert.equal(console.log.calledOnce, true);
45+
assert.deepEqual(console.log.firstCall.args, [`Dataset ${dataset.name} created.`]);
4046
done();
4147
});
4248
}

bigquery/test/quickstart.test.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
// Copyright 2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

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

1820
describe(`bigquery:quickstart`, () => {
1921
let bigqueryMock, BigqueryMock;
22+
const error = new Error(`error`);
2023

2124
before(() => {
2225
bigqueryMock = {
23-
createDataset: sinon.stub().yields(null, {}, {})
26+
createDataset: sinon.stub().yields(error)
2427
};
2528
BigqueryMock = sinon.stub().returns(bigqueryMock);
2629
});
2730

28-
it(`should create a dataset`, () => {
31+
it(`should handle error`, () => {
2932
proxyquire(`../quickstart`, {
3033
'@google-cloud/bigquery': BigqueryMock
3134
});
@@ -34,5 +37,7 @@ describe(`bigquery:quickstart`, () => {
3437
assert.deepEqual(BigqueryMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
3538
assert.equal(bigqueryMock.createDataset.calledOnce, true);
3639
assert.deepEqual(bigqueryMock.createDataset.firstCall.args.slice(0, -1), ['my_new_dataset']);
40+
assert.equal(console.error.calledOnce, true);
41+
assert.deepEqual(console.error.firstCall.args, [error]);
3742
});
3843
});

datastore/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
},
1616
"devDependencies": {
1717
"mocha": "^3.0.2"
18+
},
19+
"engines": {
20+
"node": ">=4.3.2"
1821
}
1922
}

datastore/quickstart.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -34,8 +36,11 @@ const taskKey = datastoreClient.key([kind, id]);
3436

3537
// Retrieves the entity
3638
datastoreClient.get(taskKey, (err, entity) => {
37-
if (!err) {
38-
// The entity was retrieved successfully
39+
if (err) {
40+
console.error(err);
41+
return;
3942
}
43+
44+
console.log(`Entity: ${entity.key.id}`);
4045
});
4146
// [END datastore_quickstart]

datastore/system-test/quickstart.test.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -47,15 +49,19 @@ describe(`datastore:quickstart`, () => {
4749
return key;
4850
},
4951

50-
get: (_key) => {
52+
get: (_key, _callback) => {
5153
assert.equal(_key, key);
54+
assert.equal(typeof _callback, 'function');
5255

5356
datastore.get(_key, (err, entity) => {
57+
_callback(err, entity);
5458
assert.ifError(err);
5559
assert.notEqual(entity, undefined);
5660
assert.notEqual(entity.key, undefined);
5761
assert.equal(entity.key.kind, kind);
5862
assert.deepEqual(entity.data, { message: message });
63+
assert.equal(console.log.calledOnce, true);
64+
assert.deepEqual(console.log.firstCall.args, [`Entity: ${entity.key.id}`]);
5965
done();
6066
});
6167
}

datastore/test/quickstart.test.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

1618
const proxyquire = require(`proxyquire`).noPreserveCache();
1719

1820
describe(`datastore:quickstart`, () => {
1921
let datastoreMock, DatastoreMock;
22+
const error = new Error(`error`);
23+
const mockKey = {};
2024

2125
before(() => {
2226
datastoreMock = {
23-
get: sinon.stub().yields(null, { key: 1234567890 }),
24-
key: sinon.stub.returns(`task/1234`)
27+
get: sinon.stub().yields(error),
28+
key: sinon.stub().returns(mockKey)
2529
};
2630
DatastoreMock = sinon.stub().returns(datastoreMock);
2731
});
2832

29-
it(`should get a task from Datastore`, () => {
33+
it(`should handle error`, () => {
3034
proxyquire(`../quickstart`, {
3135
'@google-cloud/datastore': DatastoreMock
3236
});
3337

3438
assert.equal(DatastoreMock.calledOnce, true);
3539
assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
3640
assert.equal(datastoreMock.get.calledOnce, true);
37-
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]);
41+
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [mockKey]);
42+
assert.equal(console.error.calledOnce, true);
43+
assert.deepEqual(console.error.firstCall.args, [error]);
3844
});
3945
});

0 commit comments

Comments
 (0)