Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quickstart tests #215

Merged
merged 3 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bigquery/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();
var bigquery = proxyquire('@google-cloud/bigquery', {})();

var datasetName = 'my_new_dataset';

describe('bigquery:quickstart', function () {
var bigqueryMock, BigqueryMock;

after(function (done) {
bigquery.dataset(datasetName).delete(function () {
// Ignore any error, the dataset might not have been created
done();
});
});

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

bigquery.createDataset(datasetName, function (err, dataset, apiResponse) {
assert.ifError(err);
assert.notEqual(dataset, undefined);
assert.notEqual(apiResponse, undefined);
done();
});
}
};
BigqueryMock = sinon.stub().returns(bigqueryMock);

proxyquire('../quickstart', {
'@google-cloud/bigquery': BigqueryMock
});
});
});
38 changes: 38 additions & 0 deletions bigquery/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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';

var proxyquire = require('proxyquire').noCallThru();

describe('bigquery:quickstart', function () {
var bigqueryMock, BigqueryMock;

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

it('should create a dataset', function () {
proxyquire('../quickstart', {
'@google-cloud/bigquery': BigqueryMock
});

assert.equal(BigqueryMock.calledOnce, true);
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']);
});
});
69 changes: 69 additions & 0 deletions datastore/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();
var datastore = proxyquire('@google-cloud/datastore', {})();
var kind = 'Task';
var message = 'Buy milk';
var key = datastore.key(kind);

describe('datastore:quickstart', function () {
var datastoreMock, DatastoreMock;

before(function (done) {
datastore.save({
key: key,
data: {
message: message
}
}, function () {
// Datastore is eventually consistent
setTimeout(done, 5000);
});
});

after(function (done) {
datastore.delete(key, function () {
// Ignore any error, the Datastore might not have been created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Datastore might => the entity might

done();
});
});

it('should get a task from Datastore', function (done) {
datastoreMock = {
key: function () {
return key;
},

get: function (_key) {
assert.equal(_key, key);

datastore.get(_key, function (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 });
done();
});
}
};
DatastoreMock = sinon.stub().returns(datastoreMock);

proxyquire('../quickstart', {
'@google-cloud/datastore': DatastoreMock
});
});
});
39 changes: 39 additions & 0 deletions datastore/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();

describe('datastore:quickstart', function () {
var datastoreMock, DatastoreMock;

before(function () {
datastoreMock = {
get: sinon.stub().yields(null, {key: 1234}),
key: sinon.stub.returns('task/1234')
};
DatastoreMock = sinon.stub().returns(datastoreMock);
});

it('should get a task from Datastore', function () {
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', 1234])]);
});
});
2 changes: 1 addition & 1 deletion logging/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('logging:quickstart', function () {
});

assert.equal(LoggingMock.calledOnce, true);
assert.deepEqual(LoggingMock.firstCall.args, []);
assert.deepEqual(LoggingMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(loggingMock.log.calledOnce, true);
assert.deepEqual(loggingMock.log.firstCall.args, [expectedLogName]);
assert.equal(logMock.entry.calledOnce, true);
Expand Down
2 changes: 1 addition & 1 deletion pubsub/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('pubsub:quickstart', function () {
});

assert.equal(PubSubMock.calledOnce, true);
assert.deepEqual(PubSubMock.firstCall.args, []);
assert.deepEqual(PubSubMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(pubsubMock.createTopic.calledOnce, true);
assert.deepEqual(pubsubMock.createTopic.firstCall.args.slice(0, -1), [expectedTopicName]);
});
Expand Down
2 changes: 1 addition & 1 deletion storage/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('storage:quickstart', function () {
});

assert.equal(StorageMock.calledOnce, true);
assert.deepEqual(StorageMock.firstCall.args, []);
assert.deepEqual(StorageMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
assert.equal(storageMock.createBucket.calledOnce, true);
assert.deepEqual(storageMock.createBucket.firstCall.args.slice(0, -1), [expectedBucketName]);
});
Expand Down
46 changes: 46 additions & 0 deletions translate/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

'use strict';

var proxyquire = require('proxyquire').noPreserveCache();
var translate = proxyquire('@google-cloud/translate', {})({
key: process.env.TRANSLATE_API_KEY
});
var string = 'Hello, world!';
var targetLanguage = 'ru';

describe('translate:quickstart', function () {
var translateMock, TranslateMock;

it('should translate a string', function (done) {
translateMock = {
translate: function (_string, _targetLanguage) {
assert.equal(_string, string);
assert.equal(_targetLanguage, targetLanguage);

translate.translate(_string, _targetLanguage, function (err, translation, apiResponse) {
assert.ifError(err);
assert.equal(translation, 'Привет мир!');
assert.notEqual(apiResponse, undefined);
done();
});
}
};
TranslateMock = sinon.stub().returns(translateMock);

proxyquire('../quickstart', {
'@google-cloud/translate': TranslateMock
});
});
});
38 changes: 38 additions & 0 deletions translate/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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';

var proxyquire = require('proxyquire').noCallThru();

describe('translate:quickstart', function () {
var translateMock, TranslateMock;

before(function () {
translateMock = {
translate: sinon.stub().yields(null, 'Привет мир!', {})
};
TranslateMock = sinon.stub().returns(translateMock);
});

it('should translate a string', function () {
proxyquire('../quickstart', {
'@google-cloud/translate': TranslateMock
});

assert.equal(TranslateMock.calledOnce, true);
assert.deepEqual(TranslateMock.firstCall.args, [{ key: 'YOUR_API_KEY' }]);
assert.equal(translateMock.translate.calledOnce, true);
assert.deepEqual(translateMock.translate.firstCall.args.slice(0, -1), ['Hello, world!', 'ru']);
});
});