From 607638cca6855b392723caf273c63356e116f38d Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 19 Feb 2015 15:08:50 -0500 Subject: [PATCH 1/3] fix regression tests. --- regression/pubsub.js | 47 +++++++++++++++++-------------------------- regression/storage.js | 2 +- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/regression/pubsub.js b/regression/pubsub.js index 9afcfe84c5b..2529f06a027 100644 --- a/regression/pubsub.js +++ b/regression/pubsub.js @@ -20,6 +20,7 @@ var assert = require('assert'); var async = require('async'); +var uuid = require('node-uuid'); var env = require('./env.js'); var gcloud = require('../lib')(env); @@ -28,8 +29,20 @@ var Subscription = require('../lib/pubsub/subscription.js'); var pubsub = gcloud.pubsub(); +function generateTopicName() { + return 'test-topic-' + uuid.v4(); +} + +function generateSubName() { + return 'test-subscription-' + uuid.v4(); +} + describe('pubsub', function() { - var topicNames = ['topic1', 'topic2', 'topic3']; + var topicNames = [ + generateTopicName(), + generateTopicName(), + generateTopicName() + ]; function deleteAllTopics(callback) { // TODO: Handle pagination. @@ -91,45 +104,21 @@ describe('pubsub', function() { }); describe('Subscription', function() { - var TOPIC_NAME = 'test-topic'; + var TOPIC_NAME = generateTopicName(); var subscriptions = [ { - name: 'sub1', + name: generateSubName(), options: { ackDeadlineSeconds: 30 } }, { - name: 'sub2', + name: generateSubName(), options: { ackDeadlineSeconds: 60 } } ]; var topic; - function deleteAllTopics(callback) { - pubsub.getTopics(function(err, topics) { - if (err) { - callback(err); - return; - } - async.parallel(topics.map(function(topic) { - return topic.delete.bind(topic); - }), callback); - }); - } - - function deleteAllSubscriptions(callback) { - pubsub.getSubscriptions(function(err, subs) { - if (err) { - callback(err); - return; - } - async.parallel(subs.map(function(sub) { - return sub.delete.bind(sub); - }), callback); - }); - } - before(function(done) { - async.parallel([deleteAllTopics, deleteAllSubscriptions], function(err) { + deleteAllTopics(function(err) { assert.ifError(err); // Create a new test topic. pubsub.createTopic(TOPIC_NAME, function(err, newTopic) { diff --git a/regression/storage.js b/regression/storage.js index dc8f7efc4d7..af5946380d4 100644 --- a/regression/storage.js +++ b/regression/storage.js @@ -370,7 +370,7 @@ describe('storage', function() { file.download(function(err, remoteContents) { assert.ifError(err); - assert.equal(fileContents, remoteContents); + assert.equal(String(fileContents), String(remoteContents)); done(); }); }); From 32b7c25bff56be57e2820604e2b537362ecd3545 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 19 Feb 2015 15:25:36 -0500 Subject: [PATCH 2/3] fix getSubscriptions --- lib/pubsub/topic.js | 6 ++++++ test/pubsub/topic.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/pubsub/topic.js b/lib/pubsub/topic.js index fcc6f323040..8d8a9c9b1fe 100644 --- a/lib/pubsub/topic.js +++ b/lib/pubsub/topic.js @@ -190,7 +190,13 @@ Topic.prototype.delete = function(callback) { * }, function(err, subscriptions, nextQuery) {}); */ Topic.prototype.getSubscriptions = function(query, callback) { + if (util.is(query, 'function')) { + callback = query; + query = {}; + } + query.query = 'pubsub.googleapis.com/topic in (' + this.name + ')'; + this.pubsub.getSubscriptions(query, callback); }; diff --git a/test/pubsub/topic.js b/test/pubsub/topic.js index b6ad21d2db3..06138672bd6 100644 --- a/test/pubsub/topic.js +++ b/test/pubsub/topic.js @@ -211,6 +211,15 @@ describe('Topic', function() { }; topic.getSubscriptions({}, assert.ifError); }); + + it('should attach scoped topic query without a query', function(done) { + topic.pubsub.getSubscriptions = function(q) { + assert.equal( + q.query, 'pubsub.googleapis.com/topic in (' + topic.name + ')'); + done(); + }; + topic.getSubscriptions(assert.ifError); + }); }); describe('subscribe', function() { From 871356683c8e12e0d2d443472e907d6c5ce12ab8 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 19 Feb 2015 15:41:40 -0500 Subject: [PATCH 3/3] explain deleting a topic will delete subscriptions --- lib/pubsub/topic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pubsub/topic.js b/lib/pubsub/topic.js index 8d8a9c9b1fe..179ff534888 100644 --- a/lib/pubsub/topic.js +++ b/lib/pubsub/topic.js @@ -152,7 +152,7 @@ Topic.prototype.publish = function(messages, callback) { }; /** - * Delete the topic. + * Delete the topic. This will also delete any subscriptions to this topic. * * @param {function=} callback - The callback function. *