Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Aug 28, 2016
1 parent 6195244 commit b78c605
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 61 deletions.
18 changes: 9 additions & 9 deletions pubsub/system-test/subscriptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('pubsub:subscriptions', function () {
pubsub.topic(topicName).delete(done);
});

describe('create', function () {
describe('createSubscription', function () {
it('should create a subscription', function (done) {
program.create(topicName, subscriptionName, function (err, subscription) {
program.createSubscription(topicName, subscriptionName, function (err, subscription) {
assert.ifError(err);
assert.equal(subscription.name, name);
assert(console.log.calledWith('Created subscription %s to topic %s', subscriptionName, topicName));
Expand All @@ -45,9 +45,9 @@ describe('pubsub:subscriptions', function () {
});
});

describe('list', function () {
describe('listSubscriptions', function () {
it('should list subscriptions', function (done) {
program.list(topicName, function (err, subscriptions) {
program.listSubscriptions(topicName, function (err, subscriptions) {
assert.ifError(err);
assert(Array.isArray(subscriptions));
assert(subscriptions.length > 0);
Expand All @@ -57,7 +57,7 @@ describe('pubsub:subscriptions', function () {
assert.equal(recentlyCreatedSubscriptions.length, 1, 'list has newly created subscription');
assert(console.log.calledWith('Found %d subscriptions!', subscriptions.length));

program.list(undefined, function (err, allSubscriptions) {
program.listSubscriptions(undefined, function (err, allSubscriptions) {
assert.ifError(err);
assert(Array.isArray(allSubscriptions));
assert(allSubscriptions.length > 0);
Expand All @@ -72,15 +72,15 @@ describe('pubsub:subscriptions', function () {
});
});

describe('pull', function () {
describe('pullMessages', function () {
var expected = 'Hello World!';

before(function (done) {
pubsub.topic(topicName).publish({ data: expected }, done);
});

it('should pull messages', function (done) {
program.pull(subscriptionName, function (err, messages) {
program.pullMessages(subscriptionName, function (err, messages) {
assert.ifError(err);
assert(Array.isArray(messages));
assert(messages.length > 0);
Expand All @@ -92,9 +92,9 @@ describe('pubsub:subscriptions', function () {
});
});

describe('delete', function () {
describe('deleteSubscription', function () {
it('should delete a subscription', function (done) {
program.delete(subscriptionName, function (err) {
program.deleteSubscription(subscriptionName, function (err) {
assert.ifError(err);
assert(console.log.calledWith('Deleted subscription: %s', subscriptionName));
done();
Expand Down
16 changes: 8 additions & 8 deletions pubsub/system-test/topics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var projectId = process.env.GCLOUD_PROJECT;
var name = 'projects/' + projectId + '/topics/' + topicName;

describe('pubsub:topics', function () {
describe('create', function () {
describe('createTopic', function () {
it('should create a topic', function (done) {
program.create(topicName, function (err, topic) {
program.createTopic(topicName, function (err, topic) {
assert.ifError(err);
assert.equal(topic.name, name);
assert(console.log.calledWith('Created topic: %s', topicName));
Expand All @@ -31,9 +31,9 @@ describe('pubsub:topics', function () {
});
});

describe('list', function () {
describe('listTopics', function () {
it('should list topics', function (done) {
program.list(function (err, topics) {
program.listTopics(function (err, topics) {
assert.ifError(err);
assert(Array.isArray(topics));
assert(topics.length > 0);
Expand All @@ -47,10 +47,10 @@ describe('pubsub:topics', function () {
});
});

describe('publish', function () {
describe('publishMessage', function () {
it('should publish a message', function (done) {
var json = '{"data":"Hello World!"}';
program.publish(topicName, json, function (err, messageIds) {
program.publishMessage(topicName, json, function (err, messageIds) {
assert.ifError(err);
assert(Array.isArray(messageIds));
assert(messageIds.length > 0);
Expand All @@ -60,9 +60,9 @@ describe('pubsub:topics', function () {
});
});

describe('delete', function () {
describe('deleteTopic', function () {
it('should delete a topic', function (done) {
program.delete(topicName, function (err) {
program.deleteTopic(topicName, function (err) {
assert.ifError(err);
assert(console.log.calledWith('Deleted topic: %s', topicName));
done();
Expand Down
79 changes: 40 additions & 39 deletions storage/test/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

var proxyquire = require('proxyquire').noCallThru();
var bucketName = 'foo';
var fileName = 'test1.txt';
var movedFileName = 'test2.txt';
var copiedFileName = 'test3.txt';
var srcFileName = 'test1.txt';
var destFileName = 'test2.txt';
var movedFileName = 'test3.txt';
var copiedFileName = 'test4.txt';

function getSample () {
var filesMock = [
Expand Down Expand Up @@ -168,14 +169,14 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName
srcFile: srcFileName
};

sample.program.uploadFile(options, callback);

assert(sample.mocks.bucket.upload.calledOnce, 'upload called once');
assert.equal(sample.mocks.bucket.upload.firstCall.args.length, 2, 'upload received 2 arguments');
assert.deepEqual(sample.mocks.bucket.upload.firstCall.args[0], fileName, 'upload received file name');
assert.deepEqual(sample.mocks.bucket.upload.firstCall.args[0], srcFileName, 'upload received file name');
assert(callback.calledOnce, 'callback called once');
assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments');
assert.ifError(callback.firstCall.args[0], 'callback did not receive error');
Expand All @@ -189,7 +190,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName
srcFile: srcFileName
};
sample.mocks.bucket.upload = sinon.stub().callsArgWith(1, error);

Expand All @@ -208,8 +209,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName,
destFile: fileName
srcFile: srcFileName,
destFile: destFileName
};

sample.program.downloadFile(options, callback);
Expand All @@ -231,8 +232,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName,
destFile: fileName
srcFile: srcFileName,
destFile: destFileName
};
sample.mocks.file.download = sinon.stub().callsArgWith(1, error);

Expand All @@ -251,7 +252,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};

sample.program.deleteFile(options, callback);
Expand All @@ -270,7 +271,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};
sample.mocks.file.delete = sinon.stub().callsArgWith(0, error);

Expand All @@ -289,7 +290,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};

sample.program.getMetadata(options, callback);
Expand All @@ -309,7 +310,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};
sample.mocks.file.getMetadata = sinon.stub().callsArgWith(0, error);

Expand All @@ -328,7 +329,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};

sample.program.makePublic(options, callback);
Expand All @@ -347,7 +348,7 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
file: fileName
file: srcFileName
};
sample.mocks.file.makePublic = sinon.stub().callsArgWith(0, error);

Expand All @@ -366,8 +367,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName,
destFile: fileName
srcFile: srcFileName,
destFile: movedFileName
};

sample.program.moveFile(options, callback);
Expand All @@ -388,8 +389,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
bucket: bucketName,
srcFile: fileName,
destFile: fileName
srcFile: srcFileName,
destFile: movedFileName
};
sample.mocks.file.move = sinon.stub().callsArgWith(1, error);

Expand All @@ -408,8 +409,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
srcBucket: bucketName,
srcFile: fileName,
destFile: fileName,
srcFile: srcFileName,
destFile: copiedFileName,
destBucket: bucketName
};

Expand All @@ -430,8 +431,8 @@ describe('storage:files', function () {
var callback = sinon.stub();
var options = {
srcBucket: bucketName,
srcFile: fileName,
destFile: fileName,
srcFile: srcFileName,
destFile: copiedFileName,
destBucket: bucketName
};
sample.mocks.file.copy = sinon.stub().callsArgWith(1, error);
Expand Down Expand Up @@ -472,72 +473,72 @@ describe('storage:files', function () {
var program = getSample().program;

sinon.stub(program, 'uploadFile');
program.main(['upload', bucketName, fileName]);
program.main(['upload', bucketName, srcFileName]);
assert.equal(program.uploadFile.calledOnce, true);
assert.deepEqual(program.uploadFile.firstCall.args.slice(0, -1), [{
bucket: bucketName,
srcFile: fileName
srcFile: srcFileName
}]);
});

it('should call downloadFile', function () {
var program = getSample().program;

sinon.stub(program, 'downloadFile');
program.main(['download', bucketName, fileName, fileName]);
program.main(['download', bucketName, srcFileName, destFileName]);
assert.equal(program.downloadFile.calledOnce, true);
assert.deepEqual(program.downloadFile.firstCall.args.slice(0, -1), [{
bucket: bucketName,
srcFile: fileName,
destFile: fileName
srcFile: srcFileName,
destFile: destFileName
}]);
});

it('should call deleteFile', function () {
var program = getSample().program;

sinon.stub(program, 'deleteFile');
program.main(['delete', bucketName, fileName]);
program.main(['delete', bucketName, srcFileName]);
assert.equal(program.deleteFile.calledOnce, true);
assert.deepEqual(program.deleteFile.firstCall.args.slice(0, -1), [{
bucket: bucketName,
file: fileName
file: srcFileName
}]);
});

it('should call getMetadata', function () {
var program = getSample().program;

sinon.stub(program, 'getMetadata');
program.main(['getMetadata', bucketName, fileName]);
program.main(['getMetadata', bucketName, srcFileName]);
assert.equal(program.getMetadata.calledOnce, true);
assert.deepEqual(program.getMetadata.firstCall.args.slice(0, -1), [{
bucket: bucketName,
file: fileName
file: srcFileName
}]);
});

it('should call makePublic', function () {
var program = getSample().program;

sinon.stub(program, 'makePublic');
program.main(['makePublic', bucketName, fileName]);
program.main(['makePublic', bucketName, srcFileName]);
assert.equal(program.makePublic.calledOnce, true);
assert.deepEqual(program.makePublic.firstCall.args.slice(0, -1), [{
bucket: bucketName,
file: fileName
file: srcFileName
}]);
});

it('should call moveFile', function () {
var program = getSample().program;

sinon.stub(program, 'moveFile');
program.main(['move', bucketName, fileName, movedFileName]);
program.main(['move', bucketName, srcFileName, movedFileName]);
assert.equal(program.moveFile.calledOnce, true);
assert.deepEqual(program.moveFile.firstCall.args.slice(0, -1), [{
bucket: bucketName,
srcFile: fileName,
srcFile: srcFileName,
destFile: movedFileName
}]);
});
Expand All @@ -546,11 +547,11 @@ describe('storage:files', function () {
var program = getSample().program;

sinon.stub(program, 'copyFile');
program.main(['copy', bucketName, fileName, bucketName, copiedFileName]);
program.main(['copy', bucketName, srcFileName, bucketName, copiedFileName]);
assert.equal(program.copyFile.calledOnce, true);
assert.deepEqual(program.copyFile.firstCall.args.slice(0, -1), [{
srcBucket: bucketName,
srcFile: fileName,
srcFile: srcFileName,
destBucket: bucketName,
destFile: copiedFileName
}]);
Expand Down
Loading

0 comments on commit b78c605

Please sign in to comment.