Skip to content

Commit

Permalink
fix: Return error if subscription name already exists. (#226)
Browse files Browse the repository at this point in the history
* fix: Return error if subscription name already exists.

* Remove old system test.
  • Loading branch information
stephenplusplus authored and jkwlui committed Aug 31, 2018
1 parent 4cf8b9b commit 8d6c1c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class PubSub {
gaxOpts: options.gaxOpts,
},
function(err, resp) {
if (err && err.code !== 6) {
if (err) {
callback(err, null, resp);
return;
}
Expand Down
24 changes: 20 additions & 4 deletions system-test/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@ describe('pubsub', function() {
);
});

it('should return error if creating an existing subscription', function(done) {
// Use a new topic name...
const topic = pubsub.topic(generateTopicName());

// ...but with the same subscription name that we already created...
const subscription = topic.subscription(SUB_NAMES[0]);

subscription.create(function(err) {
if (!err) {
assert.fail('Should not have created subscription successfully.');
return;
}

// ...and it should fail, because the subscription name is unique to the
// project, and not the topic.
assert.strictEqual(err.code, 6);
done();
});
});

it('should list all subscriptions registered to the topic', function(done) {
topic.getSubscriptions(function(err, subs) {
assert.ifError(err);
Expand Down Expand Up @@ -442,10 +462,6 @@ describe('pubsub', function() {
});
});

it('should re-use an existing subscription', function(done) {
pubsub.createSubscription(topic, SUB_NAMES[0], done);
});

it('should error when using a non-existent subscription', function(done) {
const subscription = topic.subscription(generateSubName(), {
maxConnections: 1,
Expand Down
18 changes: 0 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,24 +481,6 @@ describe('PubSub', function() {
};
});

it('should re-use existing subscription', function(done) {
const apiResponse = {code: 6};

pubsub.subscription = function() {
return SUBSCRIPTION;
};

pubsub.request = function(config, callback) {
callback({code: 6}, apiResponse);
};

pubsub.createSubscription(TOPIC_NAME, SUB_NAME, function(err, sub) {
assert.ifError(err);
assert.strictEqual(sub, SUBSCRIPTION);
done();
});
});

it('should return error & API response to the callback', function(done) {
pubsub.request = function(config, callback) {
callback(error, apiResponse);
Expand Down

0 comments on commit 8d6c1c1

Please sign in to comment.