Reorganized test and force 100% code coverage (#1226)
This commit is contained in:
committed by
GitHub
parent
04d082cb49
commit
b4d0dc87d3
@ -20,7 +20,7 @@ const {
|
||||
} = require('./errors')
|
||||
|
||||
class Connection {
|
||||
constructor (opts = {}) {
|
||||
constructor (opts) {
|
||||
this.url = opts.url
|
||||
this.ssl = opts.ssl || null
|
||||
this.id = opts.id || stripAuth(opts.url.href)
|
||||
@ -64,6 +64,7 @@ class Connection {
|
||||
// https://github.com/nodejs/node/commit/b961d9fd83
|
||||
if (INVALID_PATH_REGEX.test(requestParams.path) === true) {
|
||||
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null)
|
||||
/* istanbul ignore next */
|
||||
return { abort: () => {} }
|
||||
}
|
||||
|
||||
@ -73,6 +74,7 @@ class Connection {
|
||||
// listen for the response event
|
||||
// TODO: handle redirects?
|
||||
request.on('response', response => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -87,6 +89,7 @@ class Connection {
|
||||
|
||||
// handles request timeout
|
||||
request.on('timeout', () => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -97,6 +100,7 @@ class Connection {
|
||||
|
||||
// handles request error
|
||||
request.on('error', err => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -107,6 +111,7 @@ class Connection {
|
||||
// updates the ended state
|
||||
request.on('abort', () => {
|
||||
debug('Request aborted', params)
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -121,7 +126,7 @@ class Connection {
|
||||
if (isStream(params.body) === true) {
|
||||
pump(params.body, request, err => {
|
||||
/* istanbul ignore if */
|
||||
if (err != null && ended === false) {
|
||||
if (err != null && /* istanbul ignore next */ ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
callback(err, null)
|
||||
@ -300,6 +305,7 @@ function resolve (host, path) {
|
||||
|
||||
function prepareHeaders (headers = {}, auth) {
|
||||
if (auth != null && headers.authorization == null) {
|
||||
/* istanbul ignore else */
|
||||
if (auth.apiKey) {
|
||||
if (typeof auth.apiKey === 'object') {
|
||||
headers.authorization = 'ApiKey ' + Buffer.from(`${auth.apiKey.id}:${auth.apiKey.api_key}`).toString('base64')
|
||||
|
||||
@ -13,6 +13,7 @@ const { ResponseError, ConfigurationError } = require('./errors')
|
||||
const pImmediate = promisify(setImmediate)
|
||||
const sleep = promisify(setTimeout)
|
||||
const kClient = Symbol('elasticsearch-client')
|
||||
/* istanbul ignore next */
|
||||
const noop = () => {}
|
||||
|
||||
class Helpers {
|
||||
@ -477,7 +478,7 @@ class Helpers {
|
||||
} else if (operation === 'update') {
|
||||
actionBody = serialize(action[0])
|
||||
payloadBody = typeof chunk === 'string'
|
||||
? `{doc:${chunk}}`
|
||||
? `{"doc":${chunk}}`
|
||||
: serialize({ doc: chunk, ...action[1] })
|
||||
chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody)
|
||||
bulkBody.push(actionBody, payloadBody)
|
||||
@ -641,6 +642,7 @@ class Helpers {
|
||||
operation: deserialize(bulkBody[i]),
|
||||
document: operation !== 'delete'
|
||||
? deserialize(bulkBody[i + 1])
|
||||
/* istanbul ignore next */
|
||||
: null,
|
||||
retried: isRetrying
|
||||
})
|
||||
@ -672,6 +674,7 @@ class Helpers {
|
||||
// but the ES node were handling too many operations.
|
||||
if (status === 429) {
|
||||
retry.push(bulkBody[indexSlice])
|
||||
/* istanbul ignore next */
|
||||
if (operation !== 'delete') {
|
||||
retry.push(bulkBody[indexSlice + 1])
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ const clientVersion = require('../package.json').version
|
||||
const userAgent = `elasticsearch-js/${clientVersion} (${os.platform()} ${os.release()}-${os.arch()}; Node.js ${process.version})`
|
||||
|
||||
class Transport {
|
||||
constructor (opts = {}) {
|
||||
constructor (opts) {
|
||||
if (typeof opts.compression === 'string' && opts.compression !== 'gzip') {
|
||||
throw new ConfigurationError(`Invalid compression: '${opts.compression}'`)
|
||||
}
|
||||
@ -51,7 +51,6 @@ class Transport {
|
||||
} else if (opts.nodeSelector === 'round-robin') {
|
||||
this.nodeSelector = roundRobinSelector()
|
||||
} else if (opts.nodeSelector === 'random') {
|
||||
/* istanbul ignore next */
|
||||
this.nodeSelector = randomSelector
|
||||
} else {
|
||||
this.nodeSelector = roundRobinSelector()
|
||||
@ -385,7 +384,7 @@ class Transport {
|
||||
}
|
||||
|
||||
debug('Sniffing ended successfully', result.body)
|
||||
const protocol = result.meta.connection.url.protocol || 'http:'
|
||||
const protocol = result.meta.connection.url.protocol || /* istanbul ignore next */ 'http:'
|
||||
const hosts = this.connectionPool.nodesToHost(result.body.nodes, protocol)
|
||||
this.connectionPool.update(hosts)
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ class BaseConnectionPool {
|
||||
}
|
||||
|
||||
if (opts.ssl == null) opts.ssl = this._ssl
|
||||
/* istanbul ignore else */
|
||||
if (opts.agent == null) opts.agent = this._agent
|
||||
|
||||
const connection = new this.Connection(opts)
|
||||
@ -201,6 +202,7 @@ class BaseConnectionPool {
|
||||
}
|
||||
|
||||
address = address.slice(0, 4) === 'http'
|
||||
/* istanbul ignore next */
|
||||
? address
|
||||
: `${protocol}//${address}`
|
||||
const roles = node.roles.reduce((acc, role) => {
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
const BaseConnectionPool = require('./BaseConnectionPool')
|
||||
|
||||
class CloudConnectionPool extends BaseConnectionPool {
|
||||
constructor (opts = {}) {
|
||||
constructor (opts) {
|
||||
super(opts)
|
||||
this.cloudConnection = null
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ const Connection = require('../Connection')
|
||||
const noop = () => {}
|
||||
|
||||
class ConnectionPool extends BaseConnectionPool {
|
||||
constructor (opts = {}) {
|
||||
constructor (opts) {
|
||||
super(opts)
|
||||
|
||||
this.dead = []
|
||||
|
||||
Reference in New Issue
Block a user