use eslint autofix to start fixing violations

This commit is contained in:
spalger
2017-06-14 18:48:24 -07:00
parent da8e558817
commit 3d75c6ff0f
97 changed files with 1281 additions and 1280 deletions

View File

@ -1,12 +1,12 @@
var Transport = require('../../../src/lib/transport');
var Host = require('../../../src/lib/host');
var errors = require('../../../src/lib/errors');
const Transport = require('../../../src/lib/transport');
const Host = require('../../../src/lib/host');
const errors = require('../../../src/lib/errors');
var sinon = require('sinon');
var expect = require('expect.js');
var _ = require('lodash');
var nodeList = require('../../fixtures/short_node_list.5.0.json');
var stub = require('../../utils/auto_release_stub').make();
const sinon = require('sinon');
const expect = require('expect.js');
const _ = require('lodash');
const nodeList = require('../../fixtures/short_node_list.5.0.json');
const stub = require('../../utils/auto_release_stub').make();
/**
* Allows the tests call #request() without it doing anything past trying to select
@ -31,7 +31,7 @@ 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({
const trans = new Transport({
log: CustomLogClass
});
@ -39,7 +39,7 @@ describe('Transport Class', function () {
});
it('Accepts a connection pool class and intanciates it at this.connectionPool', function () {
var trans = new Transport({
const trans = new Transport({
connectionPool: CustomConnectionPool
});
@ -49,7 +49,7 @@ describe('Transport Class', function () {
it('Accepts the name of a connectionPool class that is defined on Transport.connectionPools', function () {
Transport.connectionPools.custom = CustomConnectionPool;
var trans = new Transport({
const trans = new Transport({
connectionPool: 'custom'
});
@ -59,7 +59,7 @@ describe('Transport Class', function () {
it('Throws an error when connectionPool config is set wrong', function () {
expect(function () {
var trans = new Transport({
const trans = new Transport({
connectionPool: 'pasta'
});
}).to.throwError(/invalid connectionpool/i);
@ -67,7 +67,7 @@ describe('Transport Class', function () {
it('calls sniff immediately if sniffOnStart is true', function () {
stub(Transport.prototype, 'sniff');
var trans = new Transport({
const trans = new Transport({
sniffOnStart: true
});
@ -75,16 +75,16 @@ describe('Transport Class', function () {
});
it('schedules a sniff when sniffInterval is set', function () {
var clock = sinon.useFakeTimers('setTimeout');
const clock = sinon.useFakeTimers('setTimeout');
stub.autoRelease(clock);
stub(Transport.prototype, 'sniff');
var trans = new Transport({
const trans = new Transport({
sniffInterval: 25000
});
expect(_.size(clock.timers)).to.eql(1);
var id = _.keys(clock.timers).pop();
const id = _.keys(clock.timers).pop();
clock.tick(25000);
expect(trans.sniff.callCount).to.eql(1);
expect(_.size(clock.timers)).to.eql(1);
@ -94,15 +94,15 @@ describe('Transport Class', function () {
describe('config.sniffedNodesProtocol', function () {
it('Assigns to itself', function () {
var football = {};
var trans = new Transport({
const football = {};
const trans = new Transport({
sniffedNodesProtocol: football
});
expect(trans).to.have.property('sniffedNodesProtocol', football);
});
it('Defaults to null when no hosts given', function () {
var trans = new Transport({
const trans = new Transport({
hosts: []
});
@ -110,7 +110,7 @@ describe('Transport Class', function () {
});
it('Defaults to "http" when a single http host given', function () {
var trans = new Transport({
const trans = new Transport({
hosts: [
new Host({
protocol: 'http'
@ -122,7 +122,7 @@ describe('Transport Class', function () {
});
it('Defaults to "http" when multiple http host given', function () {
var trans = new Transport({
const trans = new Transport({
hosts: [
new Host(),
'http://google.com',
@ -137,7 +137,7 @@ describe('Transport Class', function () {
});
it('Defaults to "https" when a single https host given', function () {
var trans = new Transport({
const trans = new Transport({
host: {
protocol: 'https'
}
@ -147,7 +147,7 @@ describe('Transport Class', function () {
});
it('Defaults to "https" when every seed host uses https', function () {
var trans = new Transport({
const trans = new Transport({
hosts: [
'https://localhost:9200',
new Host({
@ -166,7 +166,7 @@ describe('Transport Class', function () {
describe('host config', function () {
it('rejects non-strings/objects', function () {
expect(function () {
var trans = new Transport({
const trans = new Transport({
host: [
'localhost',
9393
@ -175,7 +175,7 @@ describe('Transport Class', function () {
}).to.throwError(TypeError);
expect(function () {
var trans = new Transport({
const trans = new Transport({
host: [
[9292]
]
@ -185,7 +185,7 @@ describe('Transport Class', function () {
it('accepts the config value on the host: key', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
var trans = new Transport({
const trans = new Transport({
host: 'localhost'
});
@ -197,7 +197,7 @@ describe('Transport Class', function () {
it('accepts the config value on the hosts: key', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
@ -209,8 +209,8 @@ describe('Transport Class', function () {
it('accepts A host object as the config', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
var h = new Host('localhost');
var trans = new Transport({
const h = new Host('localhost');
const trans = new Transport({
host: h
});
@ -220,7 +220,7 @@ describe('Transport Class', function () {
it('accepts strings as the config', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
var trans = new Transport({
const trans = new Transport({
hosts: [
'localhost:8888',
]
@ -237,7 +237,7 @@ describe('Transport Class', function () {
it('accepts objects as the config', function () {
stub(Transport.connectionPools.main.prototype, 'setHosts');
var trans = new Transport({
const trans = new Transport({
hosts: [
{
protocol: 'https',
@ -262,13 +262,13 @@ describe('Transport Class', function () {
// check that it's getting the suggestCompression setting
stub(Transport.connectionPools.main.prototype, 'setHosts');
var trans = new Transport({
let trans = new Transport({
suggestCompression: true,
hosts: ['localhost:9200']
});
expect(trans.connectionPool.setHosts).to.have.property('callCount', 1);
var hosts = trans.connectionPool.setHosts.firstCall.args[0];
let hosts = trans.connectionPool.setHosts.firstCall.args[0];
expect(hosts).to.have.length(1);
expect(hosts[0]).to.have.property('suggestCompression', true);
@ -285,20 +285,20 @@ describe('Transport Class', function () {
describe('randomizeHosts options', function () {
it('calls _.shuffle be default', function () {
var _ = require('../../../src/lib/utils');
const _ = require('../../../src/lib/utils');
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
expect(_.shuffle.callCount).to.eql(1);
});
it('skips the call to _.shuffle when false', function () {
var _ = require('../../../src/lib/utils');
const _ = require('../../../src/lib/utils');
stub(Transport.connectionPools.main.prototype, 'setHosts');
stub(_, 'shuffle');
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost',
randomizeHosts: false
});
@ -310,7 +310,7 @@ describe('Transport Class', function () {
describe('#defer', function () {
it('returns a custom defer object', function () {
var defer = Transport.prototype.defer();
const defer = Transport.prototype.defer();
expect(defer).to.have.property('promise');
expect(defer).to.have.property('resolve');
expect(defer).to.have.property('reject');
@ -319,7 +319,7 @@ describe('Transport Class', function () {
describe('#sniff', function () {
var trans;
let trans;
beforeEach(function () {
trans = new Transport({ suggestCompression: true });
@ -366,7 +366,7 @@ describe('Transport Class', function () {
function (done) {
trans.sniff(function () {
expect(trans.connectionPool.setHosts.callCount).to.eql(1);
var hosts = trans.connectionPool.setHosts.lastCall.args[0];
const hosts = trans.connectionPool.setHosts.lastCall.args[0];
expect(hosts).to.have.length(2);
@ -386,7 +386,7 @@ describe('Transport Class', function () {
// check that it's getting the suggestCompression setting
trans.sniff(function () {
expect(trans.connectionPool.setHosts).to.have.property('callCount', 1);
var hosts = trans.connectionPool.setHosts.lastCall.args[0];
const hosts = trans.connectionPool.setHosts.lastCall.args[0];
expect(hosts).to.have.length(2);
expect(hosts[0]).to.have.property('suggestCompression', true);
expect(hosts[1]).to.have.property('suggestCompression', true);
@ -423,7 +423,7 @@ describe('Transport Class', function () {
describe('#request', function () {
it('logs when it begins', function (done) {
var trans = new Transport();
const trans = new Transport();
stub(trans.log, 'debug');
stub(trans.connectionPool, 'select', function (cb) {
// simulate "no connections"
@ -437,7 +437,7 @@ describe('Transport Class', function () {
});
it('rejects GET requests with a body (callback)', function (done) {
var trans = new Transport();
const trans = new Transport();
stub(trans.log, 'debug');
stub(trans.connectionPool, 'select', function (cb) {
// simulate "no connections"
@ -454,7 +454,7 @@ describe('Transport Class', function () {
});
it('rejects GET requests with a body (promise)', function (done) {
var trans = new Transport();
const trans = new Transport();
stub(trans.log, 'debug');
stub(trans.connectionPool, 'select', function (cb) {
// simulate "no connections"
@ -475,11 +475,11 @@ describe('Transport Class', function () {
describe('gets a body', function () {
it('serializes it', function (done) {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
var conn = getConnection(trans);
var body = {
const conn = getConnection(trans);
const body = {
_id: 'simple body',
name: 'ഢധയമബ'
};
@ -495,11 +495,11 @@ describe('Transport Class', function () {
});
});
it('serializes bulk bodies', function (done) {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
var conn = getConnection(trans);
var body = [
const conn = getConnection(trans);
const body = [
{ _id: 'simple body' },
{ name: 'ഢധയമബ' }
];
@ -522,11 +522,11 @@ describe('Transport Class', function () {
describe('gets a body it cant serialize', function () {
it('throws an error', function () {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
getConnection(trans);
var body = {
const body = {
_id: 'circular body'
};
body.body = body;
@ -541,7 +541,7 @@ describe('Transport Class', function () {
describe('when selecting a connection', function () {
it('logs a warning, and responds with NoConnection when it receives nothing', function (done) {
var trans = new Transport();
const trans = new Transport();
stub(trans.log, 'warning');
trans.request({}, function (err, body, status) {
expect(trans.log.warning.callCount).to.eql(1);
@ -552,7 +552,7 @@ describe('Transport Class', function () {
});
});
it('quits if a sync selector throws an error', function () {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost',
selector: function () {
throw new Error('I am broken');
@ -564,7 +564,7 @@ describe('Transport Class', function () {
});
});
it('quits if gets an error from an async selector', function () {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost',
selector: function (connections, cb) {
process.nextTick(function () {
@ -578,10 +578,10 @@ describe('Transport Class', function () {
});
});
it('calls connection#request once it gets one', function (done) {
var trans = new Transport({
const trans = new Transport({
hosts: 'localhost'
});
var conn = getConnection(trans);
const conn = getConnection(trans);
stub(conn, 'request', function () {
done();
@ -595,9 +595,9 @@ describe('Transport Class', function () {
// create a test that checks N retries
function testRetries(retries) {
return function (done) {
var randomSelector = require('../../../src/lib/selectors/random');
var connections;
var attempts = 0;
const randomSelector = require('../../../src/lib/selectors/random');
let connections;
let attempts = 0;
function failRequest(params, cb) {
attempts++;
process.nextTick(function () {
@ -605,7 +605,7 @@ describe('Transport Class', function () {
});
}
var trans = new Transport({
const trans = new Transport({
hosts: _.map(new Array(retries + 1), function (val, i) {
return 'localhost/' + i;
}),
@ -639,24 +639,24 @@ describe('Transport Class', function () {
describe('return value', function () {
it('returns an object with an abort() method when a callback is sent', function () {
var tran = new Transport();
const tran = new Transport();
shortCircuitRequest(tran);
var ret = tran.request({}, _.noop);
const ret = tran.request({}, _.noop);
expect(ret).to.be.a('object');
expect(ret.abort).to.be.a('function');
});
it('the object is a promise when a callback is not suplied', function () {
var tran = new Transport();
const tran = new Transport();
shortCircuitRequest(tran);
var ret = tran.request({});
const ret = tran.request({});
expect(ret.then).to.be.a('function');
expect(ret.abort).to.be.a('function');
ret.then(_.noop, _.noop); // prevent complaining from bluebird
});
it('promise is always pulled from the defer created by this.defer()', function () {
var fakePromise = {};
var origDefer = Transport.prototype.defer;
var tran = new Transport({
const fakePromise = {};
const origDefer = Transport.prototype.defer;
const tran = new Transport({
defer: function () {
return {
resolve: _.noop,
@ -666,7 +666,7 @@ describe('Transport Class', function () {
}
});
shortCircuitRequest(tran);
var ret = tran.request({});
const ret = tran.request({});
Transport.prototype.defer = origDefer;
expect(ret).to.be(fakePromise);
expect(ret.abort).to.be.a('function');
@ -677,7 +677,7 @@ describe('Transport Class', function () {
if (process && process.hasOwnProperty('domain')) {
it('works without a domain', function () {
expect(process.domain).to.be(null);
var tran = new Transport();
const tran = new Transport();
shortCircuitRequest(tran);
tran.request({}, function () {
expect(process.domain).to.be(null);
@ -686,12 +686,12 @@ describe('Transport Class', function () {
it('binds the callback to the correct domain', function () {
expect(process.domain).to.be(null);
var domain = require('domain').create();
const domain = require('domain').create();
domain.run(function () {
var tran = new Transport();
const tran = new Transport();
shortCircuitRequest(tran);
expect(process.domain).not.to.be(null);
var startingDomain = process.domain
const startingDomain = process.domain;
tran.request({}, function () {
expect(process.domain).not.to.be(null);
expect(process.domain).to.be(startingDomain);
@ -704,24 +704,24 @@ describe('Transport Class', function () {
describe('aborting', function () {
it('prevents the request from starting if called in the same tick', function () {
var tran = new Transport({
const tran = new Transport({
host: 'localhost'
});
var con = getConnection(tran);
const con = getConnection(tran);
stub(con, 'request', function () {
throw new Error('Request should not have been called.');
});
var ret = tran.request({});
const ret = tran.request({});
ret.abort();
});
it('calls the function returned by the connector if it has been called', function (done) {
var tran = new Transport({
const tran = new Transport({
host: 'localhost'
});
var con = getConnection(tran);
const con = getConnection(tran);
stub(con, 'request', function () {
process.nextTick(function () {
ret.abort();
@ -734,16 +734,16 @@ describe('Transport Class', function () {
var ret = tran.request({});
});
it('ignores the response from the connection when the connector does not support aborting', function (done) {
var tran = new Transport({
const tran = new Transport({
host: 'localhost'
});
var con = getConnection(tran);
const con = getConnection(tran);
stub(con, 'request', function (params, cb) {
cb();
});
var ret = tran.request({}, function () {
const ret = tran.request({}, function () {
throw new Error('Callback should not have been called.');
});
ret.abort();
@ -753,11 +753,11 @@ describe('Transport Class', function () {
describe('timeout', function () {
it('uses 30 seconds for the default', function () {
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stub.autoRelease(clock);
var tran = new Transport({});
const tran = new Transport({});
var prom = tran.request({});
const prom = tran.request({});
// disregard promise, prevent bluebird's warnings
prom.then(_.noop, _.noop);
@ -768,13 +768,13 @@ describe('Transport Class', function () {
});
});
it('inherits the requestTimeout from the transport', function () {
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stub.autoRelease(clock);
var tran = new Transport({
const tran = new Transport({
requestTimeout: 5000
});
var prom = tran.request({});
const prom = tran.request({});
// disregard promise, prevent bluebird's warnings
prom.then(_.noop, _.noop);
@ -788,9 +788,9 @@ describe('Transport Class', function () {
_.each([false, 0, null], function (falsy) {
it('skips the timeout when it is ' + falsy, function () {
var clock = sinon.useFakeTimers();
const clock = sinon.useFakeTimers();
stub.autoRelease(clock);
var tran = new Transport({});
const tran = new Transport({});
stub(tran.connectionPool, 'select', function () {});
tran.request({
@ -806,7 +806,7 @@ describe('Transport Class', function () {
describe('#setHosts', function () {
it('accepts strings, host objects, and host configs', function () {
var trans = new Transport({ suggestCompression: true });
const trans = new Transport({ suggestCompression: true });
stub(trans.connectionPool, 'setHosts');
trans.setHosts([
@ -816,7 +816,7 @@ describe('Transport Class', function () {
]);
sinon.assert.calledOnce(trans.connectionPool.setHosts);
var host, hosts = trans.connectionPool.setHosts.firstCall.args[0];
let host, hosts = trans.connectionPool.setHosts.firstCall.args[0];
expect(hosts).to.have.length(3);
@ -842,7 +842,7 @@ describe('Transport Class', function () {
describe('#close', function () {
it('proxies the call to it\'s log and connection pool', function () {
var tran = new Transport();
const tran = new Transport();
stub(tran.connectionPool, 'close');
stub(tran.log, 'close');