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: Return error if subscription name already exists. #226

Merged
merged 3 commits into from
Aug 31, 2018
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
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