forked from arobson/rabbot
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add passive option to queueFsm
allows for checkQueue instead of assertQueue when clients have restricted permissions fixes issue arobson#183
- Loading branch information
Showing
4 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require('../setup.js'); | ||
var ampqQueue = require('../../src/amqp/queue'); | ||
|
||
describe('AMQP Queue', function () { | ||
let amqpChannelMock, options, topology, serializers; | ||
|
||
beforeEach(() => { | ||
amqpChannelMock = { | ||
ack: sinon.stub().callsFake(() => Promise.resolve()), | ||
nack: sinon.stub().callsFake(() => Promise.resolve()), | ||
checkQueue: sinon.stub().callsFake(() => Promise.resolve()), | ||
assertQueue: sinon.stub().callsFake(() => Promise.resolve()) | ||
}; | ||
|
||
options = { | ||
uniqueName: 'one-unique-name-coming-up' | ||
}; | ||
|
||
topology = { | ||
connection: { | ||
getChannel: sinon.stub().callsFake(() => Promise.resolve(amqpChannelMock)) | ||
} | ||
}; | ||
|
||
serializers = sinon.stub(); | ||
}); | ||
|
||
describe('when executing "define"', () => { | ||
describe('when options.passive is not set', () => { | ||
it('calls assertQueue', function () { | ||
return ampqQueue(options, topology, serializers) | ||
.then((instance) => { | ||
return instance.define(); | ||
}) | ||
.then(() => { | ||
amqpChannelMock.checkQueue.calledOnce.should.equal(false); | ||
amqpChannelMock.assertQueue.calledOnce.should.equal(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when options.passive is true', function () { | ||
it('calls checkQueue instead of assertQueue', async () => { | ||
options.passive = true; | ||
return ampqQueue(options, topology, serializers) | ||
.then((instance) => { | ||
return instance.define(); | ||
}) | ||
.then(() => { | ||
amqpChannelMock.checkQueue.calledOnce.should.equal(true); | ||
amqpChannelMock.assertQueue.calledOnce.should.equal(false); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require('../setup'); | ||
const rabbit = require('../../src/index.js'); | ||
|
||
describe('Adding Queues', function () { | ||
describe('with a connection', function () { | ||
describe('when the queue does not already exist', function () { | ||
it('should error on addQueue in passive mode', function () { | ||
return rabbit.configure({ | ||
connection: { | ||
name: 'temp' | ||
} | ||
}).then(() => { | ||
return rabbit.addQueue('no-queue-here', { passive: true }, 'temp') | ||
.then( | ||
() => { throw new Error('Should not have succeeded in the checkQueue call'); }, | ||
(err) => { | ||
err.toString().should.contain("Failed to create queue 'no-queue-here' on connection 'temp' with 'Error: Operation failed: QueueDeclare; 404 (NOT-FOUND)"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the queue does exist', function () { | ||
const existingQueueName = 'totes-exists-already'; | ||
it('should NOT error on addQueue when in passive mode', function () { | ||
return rabbit.configure({ | ||
connection: { | ||
name: 'temp' | ||
}, | ||
queues: [ | ||
{ name: existingQueueName, connection: 'temp' } | ||
] | ||
}).then(() => { | ||
return rabbit.addQueue(existingQueueName, { passive: true }, 'temp'); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
return rabbit.deleteQueue(existingQueueName, 'temp'); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
rabbit.reset(); | ||
return rabbit.shutdown('temp'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters