Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
teardown tests completed
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaugh42 committed Jun 20, 2016
1 parent ad56560 commit 87bab26
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/fudd.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ var Fudd = {

series(establishChannel, function(error, connection, channel) {
if(error) return finalCallback(error);
var teardownMethods = [];
//config.exchanges
var infrastructure = [];

mapEach(config.exchanges, Fudd._deleteExchange.bind(null, channel), function(err) {
if (err) return finalCallback(err);
config.exchanges.reduce(function(series, exchangeDefinition) {
infrastructure.push(Fudd._deleteExchange.bind(null, channel, exchangeDefinition));
}, infrastructure);

mapEach(config.queues, Fudd._deleteQueue.bind(null, channel), function(err) {
if (err) return finalCallback(err);
config.queues.reduce(function(series, queueDefinition) {
series.push(Fudd._deleteQueue.bind(null, channel, queueDefinition));
return series;
}, infrastructure);

finalCallback();
});
series(infrastructure, function(error) {
if (error) return finalCallback(error);
Fudd._disconnect(connection, finalCallback);
});
});
},
Expand Down Expand Up @@ -77,10 +80,10 @@ var Fudd = {
}
},
_deleteExchange: function(channel, exchangeDefinition, callback) {
channel.deleteExchange(exchangeDefinition.name, {}, callback);
channel.deleteExchange(exchangeDefinition.name, {}, function(error) { callback(error)});
},
_deleteQueue: function(channel, queueDefinition, callback) {
channel.deleteQueue(queueDefinition.name, {}, callback);
channel.deleteQueue(queueDefinition.name, {}, function(error) { callback(error)});
},
_connect: function(config, callback) {
var url = formatAmqpUrl(config.cluster);
Expand Down
49 changes: 49 additions & 0 deletions test/unit/fudd.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,55 @@ describe('fudd', function() {
deleteQueueBindStub.reset();
Fudd.teardown(config, callbackSpy);
});

it('should bind config to the _connect function', function() {
expect(connectBindStub.args[0]).to.eql([
null, config
]);
});

it('should invoke series with the bound _connect and Fudd._create channel functions', function() {
expect(seriesStub.args[0][0]).to.eql([boundConnect, Fudd._createChannel]);
});

it('should call the finalCallback if the first series call calls back with an error', function() {
var expectedError = new Error('things happened');
seriesStub.callArgWith(1, expectedError);
expect(callbackSpy.args[0]).to.eql([expectedError]);
});

it('should call _deleteExchange.bind for each exchange in the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(deleteExchangeBindStub.callCount).to.equal(config.exchanges.length);
});

it('should call _deleteExchange.bind for each queue in the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(deleteQueueBindStub.callCount).to.equal(config.queues.length);
});

it('should invoke series again with a sequence of functions derived from the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(seriesStub.args[1][0]).to.eql([
boundDeleteExchange,
boundDeleteQueue
]);
});

it('should call the final callback with the error returned from creating the infrastructure', function() {
var expectedError = new Error('error creating infrastructure');
seriesStub.callArgWith(1, null, 'connection', 'channel');
seriesStub.callArgWith(1, expectedError);
expect(callbackSpy.args[0]).to.eql([expectedError]);
});

it('should invoke Fudd._disconnect wtih the connection and callback', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
seriesStub.callArgWith(1, null);
expect(disconnectStub.args[0]).to.eql([
'connection', callbackSpy
]);
});
});
});
});

0 comments on commit 87bab26

Please sign in to comment.