Merge pull request #385 from spalger/test/externalStreamLog

added test to ensure stream log could be configured
This commit is contained in:
Spencer
2016-04-05 09:41:56 -07:00
3 changed files with 76 additions and 46 deletions

View File

@ -57,7 +57,7 @@ Log.loggers = require('./loggers');
Log.prototype.close = function () {
this.emit('closing');
if (this.listenerCount()) {
console.error('Something is still listening for log events, but the logger is closing.');
console.error('Something is still listening for log events, but the logger is closing.'); // eslint-disable-line no-console
this.clearAllListeners();
}
};

4
test/.eslintrc Normal file
View File

@ -0,0 +1,4 @@
---
extends: ../.eslintrc
env:
mocha: true

View File

@ -1,11 +1,14 @@
describe('Client instances creation', function () {
var path = require('path');
var stream = require('stream');
var util = require('util');
var es = require('../../../src/elasticsearch');
var apis = require('../../../src/lib/apis');
var expect = require('expect.js');
var stub = require('../../utils/auto_release_stub').make();
var client;
describe('', function () {
beforeEach(function () {
client = new es.Client();
});
@ -18,6 +21,7 @@ describe('Client instances creation', function () {
var Es = es;
expect(function () {
var c = new Es();
return c
}).to.throwError(/previous "elasticsearch" module/);
});
@ -55,6 +59,28 @@ describe('Client instances creation', function () {
expect(client.transport.log.listenerCount('debug')).to.eql(0);
expect(client.transport.log.listenerCount('trace')).to.eql(0);
});
});
describe('config', function () {
it('accepts a stream type logger', function (done) {
function NullStream() {
stream.Writable.call(this);
}
util.inherits(NullStream, stream.Writable);
NullStream.prototype._write = function(/* chunk, encoding, next */) {
done();
};
var client = new es.Client({
log: [
{ type: 'stream', stream: new NullStream() }
]
});
client.transport.log.error(new Error());
});
});
describe('#ping', function () {
it('sets the default requestTimeout to 3000', function () {