Skip to content

Commit

Permalink
Merge pull request #112 from Yoctol/master
Browse files Browse the repository at this point in the history
feat: add bindQueue and assertExchange on ChannelWrapper
  • Loading branch information
Jason Walton authored Jan 20, 2020
2 parents 3d1f9d0 + 879e522 commit 23b495a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/ChannelWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,14 @@ export default class ChannelWrapper extends EventEmitter {
assertQueue() {
return this._channel && this._channel.assertQueue.apply(this._channel, arguments);
}

// Send a `bindQueue` to the underlying channel.
bindQueue() {
return this._channel && this._channel.bindQueue.apply(this._channel, arguments);
}

// Send a `assertExchange` to the underlying channel.
assertExchange() {
return this._channel && this._channel.assertExchange.apply(this._channel, arguments);
}
}
56 changes: 56 additions & 0 deletions test/ChannelWrapperTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,62 @@ describe('ChannelWrapper', function() {
return channelWrapper.nack('c', false, true);
});

it('should proxy assertQueue, bindQueue, assertExchange to the underlying channel', function() {
connectionManager.simulateConnect();
const channelWrapper = new ChannelWrapper(connectionManager);
return channelWrapper.waitForConnect()
.then(function() {
// get the underlying channel
const channel = channelWrapper._channel;

channelWrapper.assertQueue('dog');
expect(channel.assertQueue.calledOnce).to.be.true;
expect(channel.assertQueue.lastCall.args).to.eql(['dog']);

channelWrapper.bindQueue('dog', 'bone');
expect(channel.bindQueue.calledOnce).to.be.true;
expect(channel.bindQueue.lastCall.args).to.eql(['dog', 'bone']);

channelWrapper.assertExchange('bone');
expect(channel.assertExchange.calledOnce).to.be.true;
expect(channel.assertExchange.lastCall.args).to.eql(['bone']);
});
});

it(`should proxy assertQueue, bindQueue, assertExchange to the underlying channel,
even if we aren't done setting up`, function() {
const channelWrapper = new ChannelWrapper(connectionManager);

channelWrapper.addSetup(function() {
channelWrapper.assertQueue('dog');
channelWrapper.bindQueue('dog', 'bone');
channelWrapper.assertExchange('bone');
return Promise.resolve();
});

connectionManager.simulateConnect();

return channelWrapper.waitForConnect()
.then(function() {
const channel = channelWrapper._channel;
expect(channel.assertQueue.calledOnce).to.be.true;
expect(channel.assertQueue.lastCall.args).to.eql(['dog']);

expect(channel.bindQueue.calledOnce).to.be.true;
expect(channel.bindQueue.lastCall.args).to.eql(['dog', 'bone']);

expect(channel.assertExchange.calledOnce).to.be.true;
expect(channel.assertExchange.lastCall.args).to.eql(['bone']);
});
});

it('should ignore assertQueue, bindQueue, assertExchange if we are disconnected', function() {
const channelWrapper = new ChannelWrapper(connectionManager);
channelWrapper.assertQueue('dog', true);
channelWrapper.bindQueue('dog', 'bone', true);
channelWrapper.assertExchange('bone', true);
});

// Not much to test here - just make sure we don't throw any exceptions or anything weird. :)

it('clean up when closed', function() {
Expand Down
8 changes: 7 additions & 1 deletion test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export class FakeConfirmChannel extends EventEmitter {

this.nackAll = sinon.spy(function(requeue) {}); // eslint-disable-line

this.assertQueue = sinon.spy(function(queue, options) {}); //eslint-disable-line

this.bindQueue = sinon.spy(function(queue, source, pattern, args) {}); //eslint-disable-line

this.assertExchange = sinon.spy(function(exchange, type, options) {}); //eslint-disable-line

this.close = sinon.spy(() => this.emit('close'));
}
}
Expand Down Expand Up @@ -119,4 +125,4 @@ export class FakeAmqpConnectionManager extends EventEmitter {
err: new Error(('Boom!'))
});
}
}
}

0 comments on commit 23b495a

Please sign in to comment.