many tests
This commit is contained in:
@ -1,9 +1,24 @@
|
||||
var Transport = require('../../src/lib/transport');
|
||||
var Host = require('../../src/lib/host');
|
||||
|
||||
var sinon = require('sinon');
|
||||
var nodeList = require('../fixtures/short_node_list.json');
|
||||
|
||||
var stubs = [];
|
||||
function stub() {
|
||||
stubs.push(sinon.stub.apply(sinon, arguments));
|
||||
}
|
||||
afterEach(function () {
|
||||
var stub;
|
||||
while (stub = stubs.pop()) {
|
||||
stub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
describe('Transport Class', function () {
|
||||
|
||||
describe('Constructor', function () {
|
||||
|
||||
it('Accepts a log class and intanciates it at this.log', function () {
|
||||
function CustomLogClass() {}
|
||||
var trans = new Transport({
|
||||
@ -73,7 +88,90 @@ describe('Transport Class', function () {
|
||||
});
|
||||
}).should.throw(/invalid logclass/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sniff', function () {
|
||||
var trans;
|
||||
|
||||
beforeEach(function () {
|
||||
trans = new Transport();
|
||||
stub(trans, 'request', function (params, cb) {
|
||||
process.nextTick(function () {
|
||||
cb(void 0, {
|
||||
ok: true,
|
||||
cluster_name: 'clustername',
|
||||
nodes: nodeList
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
|
||||
stub(trans.connectionPool, 'setHosts');
|
||||
});
|
||||
|
||||
it('works without a callback', function (done) {
|
||||
trans.sniff();
|
||||
setTimeout(function () {
|
||||
trans.request.callCount.should.eql(1);
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
it('calls the nodesToHostCallback with the list of nodes', function (done) {
|
||||
trans.nodesToHostCallback = function (nodes) {
|
||||
nodes.should.eql(nodeList);
|
||||
done();
|
||||
return [];
|
||||
};
|
||||
trans.sniff();
|
||||
});
|
||||
|
||||
it('takes the host configs, converts them into Host objects, and passes them to connectionPool.setHosts',
|
||||
function (done) {
|
||||
trans.sniff(function () {
|
||||
trans.connectionPool.setHosts.callCount.should.eql(1);
|
||||
var hosts = trans.connectionPool.setHosts.lastCall.args[0];
|
||||
|
||||
hosts.should.have.length(2);
|
||||
|
||||
hosts[0].should.be.an.instanceOf(Host);
|
||||
hosts[0].host.should.eql('10.10.10.100');
|
||||
hosts[0].port.should.eql(9205);
|
||||
|
||||
hosts[0].should.be.an.instanceOf(Host);
|
||||
hosts[1].host.should.eql('10.10.10.101');
|
||||
hosts[1].port.should.eql(9205);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('passed back errors caught from the request', function (done) {
|
||||
trans.request.func = function (params, cb) {
|
||||
process.nextTick(function () {
|
||||
cb(new Error('something funked up'));
|
||||
});
|
||||
};
|
||||
|
||||
trans.sniff(function (err) {
|
||||
err.message.should.eql('something funked up');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('passed back the full server response', function (done) {
|
||||
trans.sniff(function (err, resp, status) {
|
||||
resp.should.include({
|
||||
ok: true,
|
||||
cluster_name: 'clustername'
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('passed back the server response code', function (done) {
|
||||
trans.sniff(function (err, resp, status) {
|
||||
status.should.eql(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user