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

fix regression tests. #402

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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.

This comment was marked as spam.

*
* @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);

This comment was marked as spam.

};

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();
}

This comment was marked as spam.


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 }
}
];

This comment was marked as spam.

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) {

This comment was marked as spam.

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));

This comment was marked as spam.

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