Skip to content

Commit

Permalink
Merge pull request #402 from stephenplusplus/spp--regression-test-fixes
Browse files Browse the repository at this point in the history
fix regression tests.
  • Loading branch information
ryanseys committed Feb 19, 2015
2 parents c5ecbf7 + 8713566 commit b8dff43
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
8 changes: 7 additions & 1 deletion lib/pubsub/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
};

Expand Down
47 changes: 18 additions & 29 deletions regression/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion regression/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
9 changes: 9 additions & 0 deletions test/pubsub/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b8dff43

Please sign in to comment.