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
1 parent 882cfb2 commit db124bc
Show file tree
Hide file tree
Showing 54 changed files with 1,432 additions and 404 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ on Google Cloud Platform.
* [Stackdriver Logging (Beta)](#stackdriver-logging-beta)
* [Stackdriver Monitoring (Beta)](#stackdriver-monitoring-beta)
* [Stackdriver Trace (Beta)](#stackdriver-trace-beta)
* [**Networking**](#management-tools)
* [Google Cloud DNS](#google-cloud-dns)
* [Other sample applications](#other-sample-applications)
* [Bookshelf tutorial app](#bookshelf-tutorial-app)
* [LabelCat](#labelcat)
Expand Down Expand Up @@ -403,6 +405,22 @@ View the [Stackdriver Trace Node.js sample][trace_sample].
[trace_docs]: https://cloud.google.com/trace/docs/
[trace_sample]: trace

### Networking

#### Google Cloud DNS

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

View the [Google Cloud DNS Node.js sample][dns_sample].

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

## Other sample applications

### Bookshelf tutorial app
Expand Down
3 changes: 3 additions & 0 deletions bigquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"devDependencies": {
"mocha": "^3.0.2",
"node-uuid": "^1.4.7"
},
"engines": {
"node": ">=4.3.2"
}
}
33 changes: 19 additions & 14 deletions bigquery/quickstart.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// 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.
/**
* 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';

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

// Creates the new dataset
bigqueryClient.createDataset(datasetName, (err, dataset) => {
if (!err) {
// The dataset was created successfully
if (err) {
console.error(err);
return;
}

console.log(`Dataset ${dataset.name} created.`);
});
// [END bigquery_quickstart]
32 changes: 19 additions & 13 deletions bigquery/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright 2015-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.
/**
* 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';

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

it(`should create a dataset`, (done) => {
bigqueryMock = {
createDataset: (_datasetName) => {
createDataset: (_datasetName, _callback) => {
assert.equal(_datasetName, datasetName);
assert.equal(typeof _callback, 'function');

bigquery.createDataset(datasetName, (err, dataset, apiResponse) => {
_callback(err, dataset, apiResponse);
assert.ifError(err);
assert.notEqual(dataset, undefined);
assert.notEqual(apiResponse, undefined);
assert.equal(console.log.calledOnce, true);
assert.deepEqual(console.log.firstCall.args, [`Dataset ${dataset.name} created.`]);
done();
});
}
Expand Down
33 changes: 19 additions & 14 deletions bigquery/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
// 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.
/**
* 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(`bigquery:quickstart`, () => {
let bigqueryMock, BigqueryMock;
const error = new Error(`error`);

before(() => {
bigqueryMock = {
createDataset: sinon.stub().yields(null, {}, {})
createDataset: sinon.stub().yields(error)
};
BigqueryMock = sinon.stub().returns(bigqueryMock);
});

it(`should create a dataset`, () => {
it(`should handle error`, () => {
proxyquire(`../quickstart`, {
'@google-cloud/bigquery': BigqueryMock
});
Expand All @@ -34,5 +37,7 @@ describe(`bigquery:quickstart`, () => {
assert.deepEqual(BigqueryMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(bigqueryMock.createDataset.calledOnce, true);
assert.deepEqual(bigqueryMock.createDataset.firstCall.args.slice(0, -1), ['my_new_dataset']);
assert.equal(console.error.calledOnce, true);
assert.deepEqual(console.error.firstCall.args, [error]);
});
});
3 changes: 3 additions & 0 deletions datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
},
"devDependencies": {
"mocha": "^3.0.2"
},
"engines": {
"node": ">=4.3.2"
}
}
33 changes: 19 additions & 14 deletions datastore/quickstart.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// 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.
/**
* 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';

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

// Retrieves the entity
datastoreClient.get(taskKey, (err, entity) => {
if (!err) {
// The entity was retrieved successfully
if (err) {
console.error(err);
return;
}

console.log(`Entity: ${entity.key.id}`);
});
// [END datastore_quickstart]
32 changes: 19 additions & 13 deletions datastore/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright 2015-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.
/**
* 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';

Expand Down Expand Up @@ -47,15 +49,19 @@ describe(`datastore:quickstart`, () => {
return key;
},

get: (_key) => {
get: (_key, _callback) => {
assert.equal(_key, key);
assert.equal(typeof _callback, 'function');

datastore.get(_key, (err, entity) => {
_callback(err, entity);
assert.ifError(err);
assert.notEqual(entity, undefined);
assert.notEqual(entity.key, undefined);
assert.equal(entity.key.kind, kind);
assert.deepEqual(entity.data, { message: message });
assert.equal(console.log.calledOnce, true);
assert.deepEqual(console.log.firstCall.args, [`Entity: ${entity.key.id}`]);
done();
});
}
Expand Down
38 changes: 22 additions & 16 deletions datastore/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
// Copyright 2015-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.
/**
* 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`).noPreserveCache();

describe(`datastore:quickstart`, () => {
let datastoreMock, DatastoreMock;
const error = new Error(`error`);
const mockKey = {};

before(() => {
datastoreMock = {
get: sinon.stub().yields(null, { key: 1234567890 }),
key: sinon.stub.returns(`task/1234`)
get: sinon.stub().yields(error),
key: sinon.stub().returns(mockKey)
};
DatastoreMock = sinon.stub().returns(datastoreMock);
});

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

assert.equal(DatastoreMock.calledOnce, true);
assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(datastoreMock.get.calledOnce, true);
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]);
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [mockKey]);
assert.equal(console.error.calledOnce, true);
assert.deepEqual(console.error.firstCall.args, [error]);
});
});
Loading

0 comments on commit db124bc

Please sign in to comment.