Drop node v10 support (#1471)

This commit is contained in:
Tomas Della Vedova
2021-05-20 16:16:45 +02:00
committed by delvedor
parent 9a021f8445
commit 4ec32601e7
33 changed files with 655 additions and 668 deletions

View File

@ -3,9 +3,9 @@ STACK_VERSION:
- 7.x-SNAPSHOT - 7.x-SNAPSHOT
NODE_JS_VERSION: NODE_JS_VERSION:
- 16
- 14 - 14
- 12 - 12
- 10
TEST_SUITE: TEST_SUITE:
- free - free

View File

@ -9,7 +9,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [10.x, 12.x, 14.x, 15.x] node-version: [12.x, 14.x, 16.x]
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
steps: steps:
@ -46,7 +46,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [10.x, 12.x, 14.x] node-version: [12.x, 14.x, 16.x]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -19,8 +19,6 @@
'use strict' 'use strict'
const nodeMajor = Number(process.versions.node.split('.')[0])
const { EventEmitter } = require('events') const { EventEmitter } = require('events')
const { URL } = require('url') const { URL } = require('url')
const debug = require('debug')('elasticsearch') const debug = require('debug')('elasticsearch')
@ -47,15 +45,6 @@ const kEventEmitter = Symbol('elasticsearchjs-event-emitter')
const ESAPI = require('./api') const ESAPI = require('./api')
/* istanbul ignore next */
if (nodeMajor >= 10 && nodeMajor < 12) {
process.emitWarning('You are using a version of Node.js that will reach EOL in April 2021. ' +
'The support for this version will be dropped in 7.13. ' +
'Please refer to https://ela.st/nodejs-support for additional information.',
'DeprecationWarning'
)
}
class Client extends ESAPI { class Client extends ESAPI {
constructor (opts = {}) { constructor (opts = {}) {
super({ ConfigurationError }) super({ ConfigurationError })

View File

@ -25,7 +25,7 @@ const hpagent = require('hpagent')
const http = require('http') const http = require('http')
const https = require('https') const https = require('https')
const debug = require('debug')('elasticsearch') const debug = require('debug')('elasticsearch')
const pump = require('pump') const { pipeline } = require('stream')
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/ const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/
const { const {
ConnectionError, ConnectionError,
@ -133,7 +133,7 @@ class Connection {
// starts the request // starts the request
if (isStream(params.body) === true) { if (isStream(params.body) === true) {
pump(params.body, request, err => { pipeline(params.body, request, err => {
/* istanbul ignore if */ /* istanbul ignore if */
if (err != null && cleanedListeners === false) { if (err != null && cleanedListeners === false) {
cleanListeners() cleanListeners()

View File

@ -48,39 +48,38 @@
}, },
"devDependencies": { "devDependencies": {
"@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1", "@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1",
"@types/node": "^14.14.28", "@types/node": "^15.3.1",
"convert-hrtime": "^3.0.0", "convert-hrtime": "^5.0.0",
"cross-zip": "^4.0.0", "cross-zip": "^4.0.0",
"dedent": "^0.7.0", "dedent": "^0.7.0",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",
"dezalgo": "^1.0.3", "dezalgo": "^1.0.3",
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
"into-stream": "^6.0.0", "into-stream": "^6.0.0",
"js-yaml": "^4.0.0", "js-yaml": "^4.1.0",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"minimist": "^1.2.5", "minimist": "^1.2.5",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"ora": "^5.3.0", "ora": "^5.4.0",
"pretty-hrtime": "^1.0.3", "pretty-hrtime": "^1.0.3",
"proxy": "^1.0.2", "proxy": "^1.0.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"semver": "^7.3.4", "semver": "^7.3.5",
"simple-git": "^2.35.0", "simple-git": "^2.39.0",
"simple-statistics": "^7.4.1", "simple-statistics": "^7.7.0",
"split2": "^3.2.2", "split2": "^3.2.2",
"standard": "^16.0.3", "standard": "^16.0.3",
"stoppable": "^1.1.0", "stoppable": "^1.1.0",
"tap": "^14.11.0", "tap": "^15.0.9",
"tsd": "^0.14.0", "tsd": "^0.15.1",
"workq": "^3.0.0", "workq": "^3.0.0",
"xmlbuilder2": "^2.4.0" "xmlbuilder2": "^2.4.1"
}, },
"dependencies": { "dependencies": {
"debug": "^4.3.1", "debug": "^4.3.1",
"hpagent": "^0.1.1", "hpagent": "^0.1.1",
"ms": "^2.1.3", "ms": "^2.1.3",
"pump": "^3.0.0", "secure-json-parse": "^2.4.0"
"secure-json-parse": "^2.3.1"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
@ -91,13 +90,12 @@
"url": "https://github.com/elastic/elasticsearch-js/issues" "url": "https://github.com/elastic/elasticsearch-js/issues"
}, },
"engines": { "engines": {
"node": ">=10" "node": ">=12"
}, },
"tsd": { "tsd": {
"directory": "test/types" "directory": "test/types"
}, },
"tap": { "tap": {
"esm": false,
"ts": false, "ts": false,
"jsx": false, "jsx": false,
"flow": false, "flow": false,

View File

@ -57,27 +57,27 @@ test('No errors', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (err, request) => { client.on(events.DESERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.DESERIALIZATION) t.equal(order.shift(), events.DESERIALIZATION)
}) })
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.error(err) t.error(err)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -99,12 +99,12 @@ test('Connection error', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (_err, request) => { client.on(events.DESERIALIZATION, (_err, request) => {
@ -113,12 +113,12 @@ test('Connection error', t => {
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof ConnectionError) t.ok(err instanceof ConnectionError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof ConnectionError) t.ok(err instanceof ConnectionError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -140,12 +140,12 @@ test('TimeoutError error', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (_err, request) => { client.on(events.DESERIALIZATION, (_err, request) => {
@ -154,12 +154,12 @@ test('TimeoutError error', t => {
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof TimeoutError) t.ok(err instanceof TimeoutError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof TimeoutError) t.ok(err instanceof TimeoutError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -180,12 +180,12 @@ test('RequestAbortedError error', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (_err, request) => { client.on(events.DESERIALIZATION, (_err, request) => {
@ -194,12 +194,12 @@ test('RequestAbortedError error', t => {
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof RequestAbortedError) t.ok(err instanceof RequestAbortedError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
const request = client.info((err, result) => { const request = client.info((err, result) => {
t.ok(err instanceof RequestAbortedError) t.ok(err instanceof RequestAbortedError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
request.abort() request.abort()
@ -232,27 +232,27 @@ test('ResponseError error (no retry)', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (err, request) => { client.on(events.DESERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.DESERIALIZATION) t.equal(order.shift(), events.DESERIALIZATION)
}) })
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -285,27 +285,27 @@ test('ResponseError error (with retry)', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (err, request) => { client.on(events.DESERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.DESERIALIZATION) t.equal(order.shift(), events.DESERIALIZATION)
}) })
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -325,12 +325,12 @@ test('Serialization Error', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.ok(err instanceof SerializationError) t.ok(err instanceof SerializationError)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (_err, request) => { client.on(events.DESERIALIZATION, (_err, request) => {
@ -345,7 +345,7 @@ test('Serialization Error', t => {
body.o = body body.o = body
client.index({ index: 'test', body }, (err, result) => { client.index({ index: 'test', body }, (err, result) => {
t.ok(err instanceof SerializationError) t.ok(err instanceof SerializationError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -384,27 +384,27 @@ test('Deserialization Error', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (err, request) => { client.on(events.DESERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.DESERIALIZATION) t.equal(order.shift(), events.DESERIALIZATION)
}) })
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof DeserializationError) t.ok(err instanceof DeserializationError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof DeserializationError) t.ok(err instanceof DeserializationError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
}) })
}) })
@ -435,27 +435,27 @@ test('Socket destroyed while reading the body', t => {
client.on(events.SERIALIZATION, (err, request) => { client.on(events.SERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.SERIALIZATION) t.equal(order.shift(), events.SERIALIZATION)
}) })
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.REQUEST) t.equal(order.shift(), events.REQUEST)
}) })
client.on(events.DESERIALIZATION, (err, request) => { client.on(events.DESERIALIZATION, (err, request) => {
t.error(err) t.error(err)
t.strictEqual(order.shift(), events.DESERIALIZATION) t.equal(order.shift(), events.DESERIALIZATION)
}) })
client.on(events.RESPONSE, (err, request) => { client.on(events.RESPONSE, (err, request) => {
t.ok(err instanceof ConnectionError) t.ok(err instanceof ConnectionError)
t.strictEqual(order.shift(), events.RESPONSE) t.equal(order.shift(), events.RESPONSE)
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof ConnectionError) t.ok(err instanceof ConnectionError)
t.strictEqual(order.length, 0) t.equal(order.length, 0)
server.stop() server.stop()
}) })
}) })

View File

@ -17,7 +17,7 @@ test('Request id', t => {
t.type(genReqId, 'function') t.type(genReqId, 'function')
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 10; i++) {
t.strictEqual(genReqId(), i) t.equal(genReqId(), i)
} }
t.end() t.end()
@ -40,12 +40,12 @@ test('Request id', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 'custom-id') t.equal(meta.request.id, 'custom-id')
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 'custom-id') t.equal(meta.request.id, 'custom-id')
}) })
client.info({}, options, t.error) client.info({}, options, t.error)
@ -61,12 +61,12 @@ test('Request id', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 'custom-id') t.equal(meta.request.id, 'custom-id')
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 'custom-id') t.equal(meta.request.id, 'custom-id')
}) })
client.info({}, { id: 'custom-id' }, t.error) client.info({}, { id: 'custom-id' }, t.error)
@ -84,7 +84,7 @@ test('Request id', t => {
client.on('sniff', (err, { meta }) => { client.on('sniff', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 1) t.equal(meta.request.id, 1)
}) })
}) })
@ -99,15 +99,15 @@ test('Request id', t => {
}) })
client.on('request', (e, { meta }) => { client.on('request', (e, { meta }) => {
t.strictEqual(meta.request.id, 'custom') t.equal(meta.request.id, 'custom')
}) })
client.on('response', (e, { meta }) => { client.on('response', (e, { meta }) => {
t.strictEqual(meta.request.id, 'custom') t.equal(meta.request.id, 'custom')
}) })
client.on('sniff', (e, { meta }) => { client.on('sniff', (e, { meta }) => {
t.strictEqual(meta.request.id, 'custom') t.equal(meta.request.id, 'custom')
}) })
client.transport.request({ client.transport.request({
@ -139,7 +139,7 @@ test('Request id', t => {
client.on('resurrect', (err, meta) => { client.on('resurrect', (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.request.id, 'custom') t.equal(meta.request.id, 'custom')
clock.uninstall() clock.uninstall()
}) })
@ -160,12 +160,12 @@ test('Request context', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.context, null) t.equal(meta.context, null)
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.context, null) t.equal(meta.context, null)
}) })
client.info(t.error) client.info(t.error)
@ -181,12 +181,12 @@ test('Request context', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' }) t.same(meta.context, { winter: 'is coming' })
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' }) t.same(meta.context, { winter: 'is coming' })
}) })
client.info({}, { context: { winter: 'is coming' } }, t.error) client.info({}, { context: { winter: 'is coming' } }, t.error)
@ -203,12 +203,12 @@ test('Request context', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' }) t.same(meta.context, { winter: 'is coming' })
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' }) t.same(meta.context, { winter: 'is coming' })
}) })
client.info(t.error) client.info(t.error)
@ -225,12 +225,12 @@ test('Request context', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'has come' }) t.same(meta.context, { winter: 'has come' })
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.deepEqual(meta.context, { winter: 'has come' }) t.same(meta.context, { winter: 'has come' })
}) })
client.info({}, { context: { winter: 'has come' } }, t.error) client.info({}, { context: { winter: 'has come' } }, t.error)
@ -245,7 +245,7 @@ test('Client name', t => {
node: 'http://localhost:9200', node: 'http://localhost:9200',
name: 'cluster' name: 'cluster'
}) })
t.strictEqual(client.name, 'cluster') t.equal(client.name, 'cluster')
t.end() t.end()
}) })
@ -259,17 +259,17 @@ test('Client name', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'cluster') t.equal(meta.name, 'cluster')
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'cluster') t.equal(meta.name, 'cluster')
}) })
client.info((err, { meta }) => { client.info((err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'cluster') t.equal(meta.name, 'cluster')
}) })
}) })
@ -284,17 +284,17 @@ test('Client name', t => {
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, symbol) t.equal(meta.name, symbol)
}) })
client.on('response', (err, { meta }) => { client.on('response', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, symbol) t.equal(meta.name, symbol)
}) })
client.info((err, { meta }) => { client.info((err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, symbol) t.equal(meta.name, symbol)
}) })
}) })
@ -310,7 +310,7 @@ test('Client name', t => {
client.on('sniff', (err, { meta }) => { client.on('sniff', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
}) })
}) })
@ -325,15 +325,15 @@ test('Client name', t => {
}) })
client.on('request', (e, { meta }) => { client.on('request', (e, { meta }) => {
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
}) })
client.on('response', (e, { meta }) => { client.on('response', (e, { meta }) => {
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
}) })
client.on('sniff', (e, { meta }) => { client.on('sniff', (e, { meta }) => {
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
}) })
client.transport.request({ client.transport.request({
@ -364,7 +364,7 @@ test('Client name', t => {
client.on('resurrect', (err, meta) => { client.on('resurrect', (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
clock.uninstall() clock.uninstall()
}) })
@ -392,7 +392,7 @@ test('Client name', t => {
client.on('resurrect', (err, meta) => { client.on('resurrect', (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.name, 'child-client') t.equal(meta.name, 'child-client')
clock.uninstall() clock.uninstall()
}) })

View File

@ -18,7 +18,7 @@ test('http-http proxy support', async t => {
const server = await createServer() const server = await createServer()
const proxy = await createProxy() const proxy = await createProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -29,7 +29,7 @@ test('http-http proxy support', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()
@ -39,7 +39,7 @@ test('http-https proxy support', async t => {
const server = await createSecureServer() const server = await createSecureServer()
const proxy = await createProxy() const proxy = await createProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -50,7 +50,7 @@ test('http-https proxy support', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()
@ -60,7 +60,7 @@ test('https-http proxy support', async t => {
const server = await createServer() const server = await createServer()
const proxy = await createSecureProxy() const proxy = await createSecureProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -71,7 +71,7 @@ test('https-http proxy support', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()
@ -81,7 +81,7 @@ test('https-https proxy support', async t => {
const server = await createSecureServer() const server = await createSecureServer()
const proxy = await createSecureProxy() const proxy = await createSecureProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -92,7 +92,7 @@ test('https-https proxy support', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()
@ -102,7 +102,7 @@ test('http basic authentication', async t => {
const server = await createServer() const server = await createServer()
const proxy = await createProxy() const proxy = await createProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -117,7 +117,7 @@ test('http basic authentication', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()
@ -127,7 +127,7 @@ test('https basic authentication', async t => {
const server = await createSecureServer() const server = await createSecureServer()
const proxy = await createProxy() const proxy = await createProxy()
server.on('request', (req, res) => { server.on('request', (req, res) => {
t.strictEqual(req.url, '/_cluster/health') t.equal(req.url, '/_cluster/health')
res.setHeader('content-type', 'application/json') res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -142,7 +142,7 @@ test('https basic authentication', async t => {
}) })
const response = await client.cluster.health() const response = await client.cluster.health()
t.deepEqual(response.body, { hello: 'world' }) t.same(response.body, { hello: 'world' })
server.close() server.close()
proxy.close() proxy.close()

View File

@ -56,11 +56,11 @@ test('Should execute the recurrect API with the ping strategy', t => {
client.on(events.RESURRECT, (err, meta) => { client.on(events.RESURRECT, (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.strategy, 'ping') t.equal(meta.strategy, 'ping')
t.false(meta.isAlive) t.notOk(meta.isAlive)
t.strictEqual(meta.connection.id, 'node0') t.equal(meta.connection.id, 'node0')
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
t.deepEqual(meta.request, { id: 2 }) t.same(meta.request, { id: 2 })
}) })
q.add((q, done) => { q.add((q, done) => {
@ -117,14 +117,14 @@ test('Resurrect a node and handle 502/3/4 status code', t => {
let idCount = 2 let idCount = 2
client.on(events.RESURRECT, (err, meta) => { client.on(events.RESURRECT, (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.strategy, 'ping') t.equal(meta.strategy, 'ping')
t.strictEqual(meta.connection.id, 'node0') t.equal(meta.connection.id, 'node0')
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
t.deepEqual(meta.request, { id: idCount++ }) t.same(meta.request, { id: idCount++ })
if (count < 4) { if (count < 4) {
t.false(meta.isAlive) t.notOk(meta.isAlive)
} else { } else {
t.true(meta.isAlive) t.ok(meta.isAlive)
} }
}) })
@ -179,11 +179,11 @@ test('Should execute the recurrect API with the optimistic strategy', t => {
client.on(events.RESURRECT, (err, meta) => { client.on(events.RESURRECT, (err, meta) => {
t.error(err) t.error(err)
t.strictEqual(meta.strategy, 'optimistic') t.equal(meta.strategy, 'optimistic')
t.true(meta.isAlive) t.ok(meta.isAlive)
t.strictEqual(meta.connection.id, 'node0') t.equal(meta.connection.id, 'node0')
t.strictEqual(meta.name, 'elasticsearch-js') t.equal(meta.name, 'elasticsearch-js')
t.deepEqual(meta.request, { id: 2 }) t.same(meta.request, { id: 2 })
}) })
q.add((q, done) => { q.add((q, done) => {

View File

@ -43,11 +43,11 @@ test('Should update the connection pool', t => {
const client = new Client({ const client = new Client({
node: nodes[Object.keys(nodes)[0]].url node: nodes[Object.keys(nodes)[0]].url
}) })
t.strictEqual(client.connectionPool.size, 1) t.equal(client.connectionPool.size, 1)
client.on(events.SNIFF, (err, request) => { client.on(events.SNIFF, (err, request) => {
t.error(err) t.error(err)
t.strictEqual( t.equal(
request.meta.sniff.reason, request.meta.sniff.reason,
Transport.sniffReasons.DEFAULT Transport.sniffReasons.DEFAULT
) )
@ -56,14 +56,14 @@ test('Should update the connection pool', t => {
// run the sniffer // run the sniffer
client.transport.sniff((err, hosts) => { client.transport.sniff((err, hosts) => {
t.error(err) t.error(err)
t.strictEqual(hosts.length, 4) t.equal(hosts.length, 4)
const ids = Object.keys(nodes) const ids = Object.keys(nodes)
for (let i = 0; i < hosts.length; i++) { for (let i = 0; i < hosts.length; i++) {
const id = ids[i] const id = ids[i]
// the first node will be an update of the existing one // the first node will be an update of the existing one
if (id === 'node0') { if (id === 'node0') {
t.deepEqual(hosts[i], { t.same(hosts[i], {
url: new URL(nodes[id].url), url: new URL(nodes[id].url),
id: id, id: id,
roles: { roles: {
@ -74,7 +74,7 @@ test('Should update the connection pool', t => {
} }
}) })
} else { } else {
t.deepEqual(hosts[i], { t.same(hosts[i], {
url: new URL(nodes[id].url), url: new URL(nodes[id].url),
id: id, id: id,
roles: { roles: {
@ -90,7 +90,7 @@ test('Should update the connection pool', t => {
} }
} }
t.strictEqual(client.connectionPool.size, 4) t.equal(client.connectionPool.size, 4)
}) })
t.teardown(shutdown) t.teardown(shutdown)
}) })
@ -103,11 +103,11 @@ test('Should handle hostnames in publish_address', t => {
const client = new Client({ const client = new Client({
node: nodes[Object.keys(nodes)[0]].url node: nodes[Object.keys(nodes)[0]].url
}) })
t.strictEqual(client.connectionPool.size, 1) t.equal(client.connectionPool.size, 1)
client.on(events.SNIFF, (err, request) => { client.on(events.SNIFF, (err, request) => {
t.error(err) t.error(err)
t.strictEqual( t.equal(
request.meta.sniff.reason, request.meta.sniff.reason,
Transport.sniffReasons.DEFAULT Transport.sniffReasons.DEFAULT
) )
@ -116,14 +116,14 @@ test('Should handle hostnames in publish_address', t => {
// run the sniffer // run the sniffer
client.transport.sniff((err, hosts) => { client.transport.sniff((err, hosts) => {
t.error(err) t.error(err)
t.strictEqual(hosts.length, 4) t.equal(hosts.length, 4)
for (let i = 0; i < hosts.length; i++) { for (let i = 0; i < hosts.length; i++) {
// the first node will be an update of the existing one // the first node will be an update of the existing one
t.strictEqual(hosts[i].url.hostname, 'localhost') t.equal(hosts[i].url.hostname, 'localhost')
} }
t.strictEqual(client.connectionPool.size, 4) t.equal(client.connectionPool.size, 4)
}) })
t.teardown(shutdown) t.teardown(shutdown)
}) })
@ -144,21 +144,21 @@ test('Sniff interval', t => {
client.on(events.SNIFF, (err, request) => { client.on(events.SNIFF, (err, request) => {
t.error(err) t.error(err)
const { hosts, reason } = request.meta.sniff const { hosts, reason } = request.meta.sniff
t.strictEqual( t.equal(
client.connectionPool.size, client.connectionPool.size,
hosts.length hosts.length
) )
t.strictEqual(reason, Transport.sniffReasons.SNIFF_INTERVAL) t.equal(reason, Transport.sniffReasons.SNIFF_INTERVAL)
}) })
t.strictEqual(client.connectionPool.size, 1) t.equal(client.connectionPool.size, 1)
q.add((q, done) => { q.add((q, done) => {
clock.tick(51) clock.tick(51)
client.info(err => { client.info(err => {
t.error(err) t.error(err)
waitSniffEnd(() => { waitSniffEnd(() => {
t.strictEqual(client.connectionPool.size, 4) t.equal(client.connectionPool.size, 4)
done() done()
}) })
}) })
@ -173,7 +173,7 @@ test('Sniff interval', t => {
client.info(err => { client.info(err => {
t.error(err) t.error(err)
waitSniffEnd(() => { waitSniffEnd(() => {
t.strictEqual(client.connectionPool.size, 3) t.equal(client.connectionPool.size, 3)
done() done()
}) })
}) })
@ -208,14 +208,14 @@ test('Sniff on start', t => {
client.on(events.SNIFF, (err, request) => { client.on(events.SNIFF, (err, request) => {
t.error(err) t.error(err)
const { hosts, reason } = request.meta.sniff const { hosts, reason } = request.meta.sniff
t.strictEqual( t.equal(
client.connectionPool.size, client.connectionPool.size,
hosts.length hosts.length
) )
t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_START) t.equal(reason, Transport.sniffReasons.SNIFF_ON_START)
}) })
t.strictEqual(client.connectionPool.size, 1) t.equal(client.connectionPool.size, 1)
t.teardown(shutdown) t.teardown(shutdown)
}) })
}) })
@ -238,10 +238,10 @@ test('Should not close living connections', t => {
Connection: MyConnection Connection: MyConnection
}) })
t.strictEqual(client.connectionPool.size, 1) t.equal(client.connectionPool.size, 1)
client.transport.sniff((err, hosts) => { client.transport.sniff((err, hosts) => {
t.error(err) t.error(err)
t.strictEqual( t.equal(
client.connectionPool.size, client.connectionPool.size,
hosts.length hosts.length
) )
@ -276,16 +276,16 @@ test('Sniff on connection fault', t => {
Connection: MyConnection Connection: MyConnection
}) })
t.strictEqual(client.connectionPool.size, 2) t.equal(client.connectionPool.size, 2)
// this event will be triggered by the connection fault // this event will be triggered by the connection fault
client.on(events.SNIFF, (err, request) => { client.on(events.SNIFF, (err, request) => {
t.error(err) t.error(err)
const { hosts, reason } = request.meta.sniff const { hosts, reason } = request.meta.sniff
t.strictEqual( t.equal(
client.connectionPool.size, client.connectionPool.size,
hosts.length hosts.length
) )
t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT) t.equal(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT)
}) })
client.info((err, result) => { client.info((err, result) => {

View File

@ -102,9 +102,9 @@ test('bulk index with custom id', async t => {
id: '19273860' // id of document n° 4242 id: '19273860' // id of document n° 4242
}) })
t.strictEqual(body._index, INDEX) t.equal(body._index, INDEX)
t.strictEqual(body._id, '19273860') t.equal(body._id, '19273860')
t.strictEqual(body._source.id, '19273860') t.equal(body._source.id, '19273860')
}) })
test('abort the operation on document drop', async t => { test('abort the operation on document drop', async t => {
@ -113,9 +113,9 @@ test('abort the operation on document drop', async t => {
datasource: stream.pipe(split(JSON.parse)), datasource: stream.pipe(split(JSON.parse)),
concurrency: 1, concurrency: 1,
onDrop (doc) { onDrop (doc) {
t.strictEqual(doc.status, 400) t.equal(doc.status, 400)
t.strictEqual(doc.error.type, 'mapper_parsing_exception') t.equal(doc.error.type, 'mapper_parsing_exception')
t.strictEqual(doc.document.id, '45924372') t.equal(doc.document.id, '45924372')
b.abort() b.abort()
}, },
onDocument (doc) { onDocument (doc) {
@ -135,7 +135,7 @@ test('abort the operation on document drop', async t => {
const result = await b const result = await b
t.type(result.time, 'number') t.type(result.time, 'number')
t.type(result.bytes, 'number') t.type(result.bytes, 'number')
t.strictEqual(result.total - 1, result.successful) t.equal(result.total - 1, result.successful)
t.match(result, { t.match(result, {
retry: 0, retry: 0,
failed: 1, failed: 1,

View File

@ -62,7 +62,7 @@ test('Basic', t => {
{ query: { match: { title: 'javascript' } } }, { query: { match: { title: 'javascript' } } },
(err, result) => { (err, result) => {
t.error(err) t.error(err)
t.strictEqual(result.body.hits.total.value, 106) t.equal(result.body.hits.total.value, 106)
} }
) )
@ -71,7 +71,7 @@ test('Basic', t => {
{ query: { match: { title: 'ruby' } } }, { query: { match: { title: 'ruby' } } },
(err, result) => { (err, result) => {
t.error(err) t.error(err)
t.strictEqual(result.body.hits.total.value, 29) t.equal(result.body.hits.total.value, 29)
} }
) )
@ -87,7 +87,7 @@ test('Bad request', t => {
{ query: { match: { title: 'javascript' } } }, { query: { match: { title: 'javascript' } } },
(err, result) => { (err, result) => {
t.error(err) t.error(err)
t.strictEqual(result.body.hits.total.value, 106) t.equal(result.body.hits.total.value, 106)
} }
) )
@ -95,7 +95,7 @@ test('Bad request', t => {
{ index: INDEX }, { index: INDEX },
{ query: { foo: { title: 'ruby' } } }, { query: { foo: { title: 'ruby' } } },
(err, result) => { (err, result) => {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
} }
) )
@ -112,7 +112,7 @@ test('Send multiple request concurrently over the concurrency limit', t => {
{ query: { match: { title: 'javascript' } } }, { query: { match: { title: 'javascript' } } },
(err, result) => { (err, result) => {
t.error(err) t.error(err)
t.strictEqual(result.body.hits.total.value, 106) t.equal(result.body.hits.total.value, 106)
} }
) )
} }

View File

@ -69,10 +69,10 @@ test('search helper', async t => {
for await (const search of scrollSearch) { for await (const search of scrollSearch) {
count += 1 count += 1
for (const doc of search.documents) { for (const doc of search.documents) {
t.true(doc.title.toLowerCase().includes('javascript')) t.ok(doc.title.toLowerCase().includes('javascript'))
} }
} }
t.strictEqual(count, 11) t.equal(count, 11)
}) })
test('clear a scroll search', async t => { test('clear a scroll search', async t => {
@ -94,7 +94,7 @@ test('clear a scroll search', async t => {
search.clear() search.clear()
} }
} }
t.strictEqual(count, 2) t.equal(count, 2)
}) })
test('scroll documents', async t => { test('scroll documents', async t => {
@ -112,7 +112,7 @@ test('scroll documents', async t => {
let count = 0 let count = 0
for await (const doc of scrollSearch) { for await (const doc of scrollSearch) {
count += 1 count += 1
t.true(doc.title.toLowerCase().includes('javascript')) t.ok(doc.title.toLowerCase().includes('javascript'))
} }
t.strictEqual(count, 106) t.equal(count, 106)
}) })

View File

@ -64,8 +64,8 @@ test('search helper', async t => {
} }
} }
}) })
t.strictEqual(results.length, 10) t.equal(results.length, 10)
for (const result of results) { for (const result of results) {
t.true(result.title.toLowerCase().includes('javascript')) t.ok(result.title.toLowerCase().includes('javascript'))
} }
}) })

View File

@ -594,7 +594,7 @@ function match (val1, val2, action) {
// tap.match(val1, new RegExp(regStr, 'm'), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`) // tap.match(val1, new RegExp(regStr, 'm'), `should match pattern provided: ${val2}, action: ${JSON.stringify(action)}`)
// everything else // everything else
} else { } else {
assert.strictEqual(val1, val2, `should be equal: ${val1} - ${val2}, action: ${JSON.stringify(action)}`) assert.equal(val1, val2, `should be equal: ${val1} - ${val2}, action: ${JSON.stringify(action)}`)
} }
} }
@ -654,9 +654,9 @@ function gte (val1, val2) {
*/ */
function length (val, len) { function length (val, len) {
if (typeof val === 'string' || Array.isArray(val)) { if (typeof val === 'string' || Array.isArray(val)) {
assert.strictEqual(val.length, len) assert.equal(val.length, len)
} else if (typeof val === 'object' && val !== null) { } else if (typeof val === 'object' && val !== null) {
assert.strictEqual(Object.keys(val).length, len) assert.equal(Object.keys(val).length, len)
} else { } else {
assert.fail(`length: the given value is invalid: ${val}`) assert.fail(`length: the given value is invalid: ${val}`)
} }

View File

@ -42,7 +42,7 @@ function runAsyncTest (test) {
type: 'doc', type: 'doc',
q: 'foo:bar' q: 'foo:bar'
}) })
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
} catch (err) { } catch (err) {
t.fail(err) t.fail(err)
} }

View File

@ -41,7 +41,7 @@ test('Basic (callback)', t => {
q: 'foo:bar' q: 'foo:bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -66,7 +66,7 @@ test('Basic (promises)', t => {
q: 'foo:bar' q: 'foo:bar'
}) })
.then(({ body }) => { .then(({ body }) => {
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
.catch(t.fail) .catch(t.fail)
@ -169,7 +169,7 @@ test('Abort method (callback)', t => {
q: 'foo:bar' q: 'foo:bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
@ -197,7 +197,7 @@ test('Abort method (promises)', t => {
request request
.then(({ body }) => { .then(({ body }) => {
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
.catch(t.fail) .catch(t.fail)
@ -226,7 +226,7 @@ test('Basic (options and callback)', t => {
requestTimeout: 10000 requestTimeout: 10000
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -253,7 +253,7 @@ test('Basic (options and promises)', t => {
requestTimeout: 10000 requestTimeout: 10000
}) })
.then(({ body }) => { .then(({ body }) => {
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
.catch(t.fail) .catch(t.fail)
@ -264,7 +264,7 @@ test('If the API uses the same key for both url and query parameter, the url sho
t.plan(2) t.plan(2)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/index/_bulk') t.equal(req.url, '/index/_bulk')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }

View File

@ -30,7 +30,7 @@ test('API', t => {
const href = 'http://localhost:9200/' const href = 'http://localhost:9200/'
pool.addConnection(href) pool.addConnection(href)
t.ok(pool.connections.find(c => c.id === href) instanceof Connection) t.ok(pool.connections.find(c => c.id === href) instanceof Connection)
t.strictEqual(pool.connections.find(c => c.id === href).status, Connection.statuses.ALIVE) t.equal(pool.connections.find(c => c.id === href).status, Connection.statuses.ALIVE)
t.end() t.end()
}) })
@ -42,7 +42,7 @@ test('API', t => {
pool.addConnection(href) pool.addConnection(href)
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.is(err.message, `Connection with id '${href}' is already present`) t.equal(err.message, `Connection with id '${href}' is already present`)
} }
t.end() t.end()
}) })
@ -52,8 +52,8 @@ test('API', t => {
const href = 'http://us"er:p@assword@localhost:9200/' const href = 'http://us"er:p@assword@localhost:9200/'
pool.addConnection(href) pool.addConnection(href)
const conn = pool.connections[0] const conn = pool.connections[0]
t.strictEqual(conn.url.username, 'us%22er') t.equal(conn.url.username, 'us%22er')
t.strictEqual(conn.url.password, 'p%40assword') t.equal(conn.url.password, 'p%40assword')
t.match(conn.headers, { t.match(conn.headers, {
authorization: 'Basic ' + Buffer.from('us"er:p@assword').toString('base64') authorization: 'Basic ' + Buffer.from('us"er:p@assword').toString('base64')
}) })
@ -66,7 +66,7 @@ test('API', t => {
let connection = pool.addConnection(href) let connection = pool.addConnection(href)
t.same(pool.markDead(connection), pool) t.same(pool.markDead(connection), pool)
connection = pool.connections.find(c => c.id === href) connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.status, Connection.statuses.ALIVE) t.equal(connection.status, Connection.statuses.ALIVE)
t.end() t.end()
}) })
@ -76,7 +76,7 @@ test('API', t => {
let connection = pool.addConnection(href) let connection = pool.addConnection(href)
t.same(pool.markAlive(connection), pool) t.same(pool.markAlive(connection), pool)
connection = pool.connections.find(c => c.id === href) connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.status, Connection.statuses.ALIVE) t.equal(connection.status, Connection.statuses.ALIVE)
t.end() t.end()
}) })
@ -88,7 +88,7 @@ test('API', t => {
pool.getConnection() pool.getConnection()
t.fail('Should fail') t.fail('Should fail')
} catch (err) { } catch (err) {
t.is(err.message, 'getConnection must be implemented') t.equal(err.message, 'getConnection must be implemented')
} }
t.end() t.end()
}) })
@ -98,7 +98,7 @@ test('API', t => {
const href = 'http://localhost:9200/' const href = 'http://localhost:9200/'
const connection = pool.addConnection(href) const connection = pool.addConnection(href)
pool.removeConnection(connection) pool.removeConnection(connection)
t.strictEqual(pool.size, 0) t.equal(pool.size, 0)
t.end() t.end()
}) })
@ -107,7 +107,7 @@ test('API', t => {
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
pool.addConnection('http://localhost:9201/') pool.addConnection('http://localhost:9201/')
pool.empty(() => { pool.empty(() => {
t.strictEqual(pool.size, 0) t.equal(pool.size, 0)
t.end() t.end()
}) })
}) })
@ -115,7 +115,7 @@ test('API', t => {
t.test('urlToHost', t => { t.test('urlToHost', t => {
const pool = new BaseConnectionPool({ Connection }) const pool = new BaseConnectionPool({ Connection })
const url = 'http://localhost:9200' const url = 'http://localhost:9200'
t.deepEqual( t.same(
pool.urlToHost(url), pool.urlToHost(url),
{ url: new URL(url) } { url: new URL(url) }
) )
@ -140,7 +140,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://127.0.0.1:9200'), url: new URL('http://127.0.0.1:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -160,8 +160,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, '127.0.0.1:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, '127.0.0.1:9201')
t.end() t.end()
}) })
@ -182,7 +182,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://[::1]:9200'), url: new URL('http://[::1]:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -202,8 +202,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, '[::1]:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '[::1]:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, '[::1]:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, '[::1]:9201')
t.end() t.end()
}) })
@ -224,7 +224,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://example.com:9200'), url: new URL('http://example.com:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -244,8 +244,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201')
t.end() t.end()
}) })
@ -266,7 +266,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://example.com:9200'), url: new URL('http://example.com:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -286,8 +286,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201')
t.end() t.end()
}) })
@ -308,8 +308,8 @@ test('API', t => {
} }
} }
t.strictEqual(pool.nodesToHost(nodes, 'https:')[0].url.protocol, 'https:') t.equal(pool.nodesToHost(nodes, 'https:')[0].url.protocol, 'https:')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.protocol, 'http:') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.protocol, 'http:')
t.end() t.end()
}) })
@ -425,13 +425,13 @@ test('API', t => {
// roles will never be updated, we only use it to do // roles will never be updated, we only use it to do
// a dummy check to see if the connection has been updated // a dummy check to see if the connection has been updated
t.deepEqual(pool.connections.find(c => c.id === 'a1').roles, { t.same(pool.connections.find(c => c.id === 'a1').roles, {
master: true, master: true,
data: true, data: true,
ingest: true, ingest: true,
ml: false ml: false
}) })
t.strictEqual(pool.connections.find(c => c.id === 'http://127.0.0.1:9200/'), undefined) t.equal(pool.connections.find(c => c.id === 'http://127.0.0.1:9200/'), undefined)
}) })
t.test('Add a new connection', t => { t.test('Add a new connection', t => {
@ -480,9 +480,9 @@ test('API', t => {
roles: null roles: null
}]) }])
t.false(pool.connections.find(c => c.id === 'a1')) t.notOk(pool.connections.find(c => c.id === 'a1'))
t.true(pool.connections.find(c => c.id === 'a2')) t.ok(pool.connections.find(c => c.id === 'a2'))
t.true(pool.connections.find(c => c.id === 'a3')) t.ok(pool.connections.find(c => c.id === 'a3'))
}) })
t.end() t.end()
@ -497,7 +497,7 @@ test('API', t => {
pool.createConnection('http://localhost:9200') pool.createConnection('http://localhost:9200')
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.is(err.message, 'Connection with id \'http://localhost:9200/\' is already present') t.equal(err.message, 'Connection with id \'http://localhost:9200/\' is already present')
} }
}) })

View File

@ -76,7 +76,7 @@ test('Should create a child client (timeout check)', t => {
client.info((err, res) => { client.info((err, res) => {
t.error(err) t.error(err)
child.info((err, res) => { child.info((err, res) => {
t.true(err instanceof errors.TimeoutError) t.ok(err instanceof errors.TimeoutError)
server.stop() server.stop()
}) })
}) })
@ -238,7 +238,7 @@ test('Should create a child client (generateRequestId check)', t => {
let count = 0 let count = 0
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual( t.equal(
meta.request.id, meta.request.id,
count++ === 0 ? 'trace-1-0' : 'trace-2-0' count++ === 0 ? 'trace-1-0' : 'trace-2-0'
) )
@ -263,13 +263,13 @@ test('Should create a child client (name check)', t => {
name: 'child' name: 'child'
}) })
t.strictEqual(client.name, 'parent') t.equal(client.name, 'parent')
t.strictEqual(child.name, 'child') t.equal(child.name, 'child')
let count = 0 let count = 0
client.on('request', (err, { meta }) => { client.on('request', (err, { meta }) => {
t.error(err) t.error(err)
t.strictEqual( t.equal(
meta.name, meta.name,
count++ === 0 ? 'parent' : 'child' count++ === 0 ? 'parent' : 'child'
) )

View File

@ -111,7 +111,7 @@ test('Configure host', t => {
resurrectTimeout: 0 resurrectTimeout: 0
}) })
t.deepEqual(pool.connections.find(c => c.id === 'node').roles, { t.same(pool.connections.find(c => c.id === 'node').roles, {
master: true, master: true,
data: false, data: false,
ingest: false, ingest: false,
@ -152,7 +152,7 @@ test('Configure host', t => {
resurrectTimeout: 0 resurrectTimeout: 0
}) })
t.deepEqual(pool.connections.find(c => c.id === 'node1').roles, { t.same(pool.connections.find(c => c.id === 'node1').roles, {
master: true, master: true,
data: false, data: false,
ingest: false, ingest: false,
@ -167,7 +167,7 @@ test('Configure host', t => {
resurrectTimeout: 0 resurrectTimeout: 0
}) })
t.deepEqual(pool.connections.find(c => c.id === 'node2').roles, { t.same(pool.connections.find(c => c.id === 'node2').roles, {
master: false, master: false,
data: true, data: true,
ingest: false, ingest: false,
@ -226,7 +226,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -250,7 +250,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -278,7 +278,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -307,12 +307,12 @@ test('Authentication', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
first = false first = false
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -346,12 +346,12 @@ test('Authentication', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
first = false first = false
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -383,7 +383,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -410,7 +410,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -439,12 +439,12 @@ test('Authentication', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
first = false first = false
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -477,12 +477,12 @@ test('Authentication', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
first = false first = false
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -510,7 +510,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -539,7 +539,7 @@ test('Authentication', t => {
client.info((err, { body }) => { client.info((err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -575,7 +575,7 @@ test('Custom headers per request', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -625,8 +625,8 @@ test('Extend client APIs', t => {
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
client.extend('method', ({ makeRequest, result, ConfigurationError }) => { client.extend('method', ({ makeRequest, result, ConfigurationError }) => {
t.type(makeRequest, 'function') t.type(makeRequest, 'function')
t.true(new ConfigurationError() instanceof Error) t.ok(new ConfigurationError() instanceof Error)
t.deepEqual(result, { t.same(result, {
body: null, body: null,
statusCode: null, statusCode: null,
headers: null, headers: null,
@ -634,8 +634,8 @@ test('Extend client APIs', t => {
}) })
return (params, options) => { return (params, options) => {
t.deepEqual(params, { you_know: 'for search' }) t.same(params, { you_know: 'for search' })
t.deepEqual(options, { winter: 'is coming' }) t.same(options, { winter: 'is coming' })
} }
}) })
@ -651,8 +651,8 @@ test('Extend client APIs', t => {
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
client.extend('namespace.method', ({ makeRequest, result, ConfigurationError }) => { client.extend('namespace.method', ({ makeRequest, result, ConfigurationError }) => {
t.type(makeRequest, 'function') t.type(makeRequest, 'function')
t.true(new ConfigurationError() instanceof Error) t.ok(new ConfigurationError() instanceof Error)
t.deepEqual(result, { t.same(result, {
body: null, body: null,
statusCode: null, statusCode: null,
headers: null, headers: null,
@ -660,8 +660,8 @@ test('Extend client APIs', t => {
}) })
return (params, options) => { return (params, options) => {
t.deepEqual(params, { you_know: 'for search' }) t.same(params, { you_know: 'for search' })
t.deepEqual(options, { winter: 'is coming' }) t.same(options, { winter: 'is coming' })
} }
}) })
@ -677,8 +677,8 @@ test('Extend client APIs', t => {
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
client.extend('namespace.method1', ({ makeRequest, result, ConfigurationError }) => { client.extend('namespace.method1', ({ makeRequest, result, ConfigurationError }) => {
t.type(makeRequest, 'function') t.type(makeRequest, 'function')
t.true(new ConfigurationError() instanceof Error) t.ok(new ConfigurationError() instanceof Error)
t.deepEqual(result, { t.same(result, {
body: null, body: null,
statusCode: null, statusCode: null,
headers: null, headers: null,
@ -686,15 +686,15 @@ test('Extend client APIs', t => {
}) })
return (params, options) => { return (params, options) => {
t.deepEqual(params, { you_know: 'for search' }) t.same(params, { you_know: 'for search' })
t.deepEqual(options, { winter: 'is coming' }) t.same(options, { winter: 'is coming' })
} }
}) })
client.extend('namespace.method2', ({ makeRequest, result, ConfigurationError }) => { client.extend('namespace.method2', ({ makeRequest, result, ConfigurationError }) => {
t.type(makeRequest, 'function') t.type(makeRequest, 'function')
t.true(new ConfigurationError() instanceof Error) t.ok(new ConfigurationError() instanceof Error)
t.deepEqual(result, { t.same(result, {
body: null, body: null,
statusCode: null, statusCode: null,
headers: null, headers: null,
@ -702,8 +702,8 @@ test('Extend client APIs', t => {
}) })
return (params, options) => { return (params, options) => {
t.deepEqual(params, { you_know: 'for search' }) t.same(params, { you_know: 'for search' })
t.deepEqual(options, { winter: 'is coming' }) t.same(options, { winter: 'is coming' })
} }
}) })
@ -726,7 +726,7 @@ test('Extend client APIs', t => {
client.extend('index', () => {}) client.extend('index', () => {})
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.is(err.message, 'The method "index" already exists') t.equal(err.message, 'The method "index" already exists')
} }
}) })
@ -738,7 +738,7 @@ test('Extend client APIs', t => {
client.extend('indices.delete', () => {}) client.extend('indices.delete', () => {})
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.is(err.message, 'The method "delete" already exists on namespace "indices"') t.equal(err.message, 'The method "delete" already exists on namespace "indices"')
} }
}) })
@ -769,8 +769,8 @@ test('Extend client APIs', t => {
class MyTransport extends Transport { class MyTransport extends Transport {
request (params, options) { request (params, options) {
t.deepEqual(params, { you_know: 'for search' }) t.same(params, { you_know: 'for search' })
t.deepEqual(options, { winter: 'is coming' }) t.same(options, { winter: 'is coming' })
} }
} }
@ -803,7 +803,7 @@ test('Extend client APIs', t => {
{ winter: 'is coming' }, { winter: 'is coming' },
(err, res) => { (err, res) => {
t.error(err) t.error(err)
t.deepEqual(res, { hello: 'world' }) t.same(res, { hello: 'world' })
} }
) )
}) })
@ -825,7 +825,7 @@ test('Extend client APIs', t => {
{ you_know: 'for search' }, { you_know: 'for search' },
{ winter: 'is coming' } { winter: 'is coming' }
) )
.then(res => t.deepEqual(res, { hello: 'world' })) .then(res => t.same(res, { hello: 'world' }))
.catch(err => t.fail(err)) .catch(err => t.fail(err))
}) })
@ -863,9 +863,9 @@ test('Elastic cloud config', t => {
} }
}) })
t.strictEqual(client.transport.compression, 'gzip') t.equal(client.transport.compression, 'gzip')
t.strictEqual(client.transport.suggestCompression, true) t.equal(client.transport.suggestCompression, true)
t.deepEqual(pool._ssl, { secureProtocol: 'TLSv1_2_method' }) t.same(pool._ssl, { secureProtocol: 'TLSv1_2_method' })
}) })
t.test('Without kibana component', t => { t.test('Without kibana component', t => {
@ -898,9 +898,9 @@ test('Elastic cloud config', t => {
} }
}) })
t.strictEqual(client.transport.compression, 'gzip') t.equal(client.transport.compression, 'gzip')
t.strictEqual(client.transport.suggestCompression, true) t.equal(client.transport.suggestCompression, true)
t.deepEqual(pool._ssl, { secureProtocol: 'TLSv1_2_method' }) t.same(pool._ssl, { secureProtocol: 'TLSv1_2_method' })
}) })
t.test('Auth as separate option', t => { t.test('Auth as separate option', t => {
@ -935,9 +935,9 @@ test('Elastic cloud config', t => {
} }
}) })
t.strictEqual(client.transport.compression, 'gzip') t.equal(client.transport.compression, 'gzip')
t.strictEqual(client.transport.suggestCompression, true) t.equal(client.transport.suggestCompression, true)
t.deepEqual(pool._ssl, { secureProtocol: 'TLSv1_2_method' }) t.same(pool._ssl, { secureProtocol: 'TLSv1_2_method' })
}) })
t.test('ApiKey should take precedence over basic auth', t => { t.test('ApiKey should take precedence over basic auth', t => {
@ -973,9 +973,9 @@ test('Elastic cloud config', t => {
} }
}) })
t.strictEqual(client.transport.compression, 'gzip') t.equal(client.transport.compression, 'gzip')
t.strictEqual(client.transport.suggestCompression, true) t.equal(client.transport.suggestCompression, true)
t.deepEqual(pool._ssl, { secureProtocol: 'TLSv1_2_method' }) t.same(pool._ssl, { secureProtocol: 'TLSv1_2_method' })
}) })
t.test('Override default options', t => { t.test('Override default options', t => {
@ -995,9 +995,9 @@ test('Elastic cloud config', t => {
}) })
t.ok(client.connectionPool instanceof CloudConnectionPool) t.ok(client.connectionPool instanceof CloudConnectionPool)
t.strictEqual(client.transport.compression, false) t.equal(client.transport.compression, false)
t.strictEqual(client.transport.suggestCompression, false) t.equal(client.transport.suggestCompression, false)
t.deepEqual(client.connectionPool._ssl, { secureProtocol: 'TLSv1_1_method' }) t.same(client.connectionPool._ssl, { secureProtocol: 'TLSv1_1_method' })
}) })
t.end() t.end()
@ -1008,7 +1008,7 @@ test('Opaque Id support', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers['x-opaque-id'], undefined) t.equal(req.headers['x-opaque-id'], undefined)
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -1023,7 +1023,7 @@ test('Opaque Id support', t => {
q: 'foo:bar' q: 'foo:bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1033,7 +1033,7 @@ test('Opaque Id support', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers['x-opaque-id'], 'bar') t.equal(req.headers['x-opaque-id'], 'bar')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -1050,7 +1050,7 @@ test('Opaque Id support', t => {
opaqueId: 'bar' opaqueId: 'bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1060,7 +1060,7 @@ test('Opaque Id support', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers['x-opaque-id'], 'foo-bar') t.equal(req.headers['x-opaque-id'], 'foo-bar')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -1078,7 +1078,7 @@ test('Opaque Id support', t => {
opaqueId: 'bar' opaqueId: 'bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1091,8 +1091,8 @@ test('Correctly handles the same header cased differently', t => {
t.plan(4) t.plan(4)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers.authorization, 'Basic foobar') t.equal(req.headers.authorization, 'Basic foobar')
t.strictEqual(req.headers.foo, 'baz') t.equal(req.headers.foo, 'baz')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -1119,7 +1119,7 @@ test('Correctly handles the same header cased differently', t => {
} }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1144,7 +1144,7 @@ test('Random selector', t => {
q: 'foo:bar' q: 'foo:bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1154,7 +1154,7 @@ test('Disable keep alive agent', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers.connection, 'close') t.equal(req.headers.connection, 'close')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -1170,7 +1170,7 @@ test('Disable keep alive agent', t => {
q: 'foo:bar' q: 'foo:bar'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1184,7 +1184,7 @@ test('name property as string', t => {
name: 'client-name' name: 'client-name'
}) })
t.strictEqual(client.name, 'client-name') t.equal(client.name, 'client-name')
}) })
test('name property as symbol', t => { test('name property as symbol', t => {
@ -1196,7 +1196,7 @@ test('name property as symbol', t => {
name: symbol name: symbol
}) })
t.strictEqual(client.name, symbol) t.equal(client.name, symbol)
}) })
// The nodejs http agent will try to wait for the whole // The nodejs http agent will try to wait for the whole
@ -1218,8 +1218,8 @@ test('Bad content length', t => {
const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 }) const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 })
client.info((err, { body }) => { client.info((err, { body }) => {
t.ok(err instanceof errors.ConnectionError) t.ok(err instanceof errors.ConnectionError)
t.is(err.message, 'Response aborted while reading the body') t.equal(err.message, 'Response aborted while reading the body')
t.strictEqual(count, 2) t.equal(count, 2)
server.stop() server.stop()
}) })
}) })
@ -1244,8 +1244,8 @@ test('Socket destryed while reading the body', t => {
const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 }) const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 })
client.info((err, { body }) => { client.info((err, { body }) => {
t.ok(err instanceof errors.ConnectionError) t.ok(err instanceof errors.ConnectionError)
t.is(err.message, 'Response aborted while reading the body') t.equal(err.message, 'Response aborted while reading the body')
t.strictEqual(count, 2) t.equal(count, 2)
server.stop() server.stop()
}) })
}) })
@ -1274,8 +1274,8 @@ test('Content length too big (buffer)', t => {
const client = new Client({ node: 'http://localhost:9200', Connection: MockConnection }) const client = new Client({ node: 'http://localhost:9200', Connection: MockConnection })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof errors.RequestAbortedError) t.ok(err instanceof errors.RequestAbortedError)
t.is(err.message, `The content length (${buffer.constants.MAX_LENGTH + 10}) is bigger than the maximum allowed buffer (${buffer.constants.MAX_LENGTH})`) t.equal(err.message, `The content length (${buffer.constants.MAX_LENGTH + 10}) is bigger than the maximum allowed buffer (${buffer.constants.MAX_LENGTH})`)
t.strictEqual(result.meta.attempts, 0) t.equal(result.meta.attempts, 0)
}) })
}) })
@ -1301,8 +1301,8 @@ test('Content length too big (string)', t => {
const client = new Client({ node: 'http://localhost:9200', Connection: MockConnection }) const client = new Client({ node: 'http://localhost:9200', Connection: MockConnection })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof errors.RequestAbortedError) t.ok(err instanceof errors.RequestAbortedError)
t.is(err.message, `The content length (${buffer.constants.MAX_STRING_LENGTH + 10}) is bigger than the maximum allowed string (${buffer.constants.MAX_STRING_LENGTH})`) t.equal(err.message, `The content length (${buffer.constants.MAX_STRING_LENGTH + 10}) is bigger than the maximum allowed string (${buffer.constants.MAX_STRING_LENGTH})`)
t.strictEqual(result.meta.attempts, 0) t.equal(result.meta.attempts, 0)
}) })
}) })
@ -1389,7 +1389,7 @@ test('Prototype poisoning protection enabled by default', t => {
}) })
client.info((err, result) => { client.info((err, result) => {
t.true(err instanceof errors.DeserializationError) t.ok(err instanceof errors.DeserializationError)
}) })
}) })

View File

@ -33,7 +33,7 @@ test('Should expose a cloudConnection property', t => {
test('Get connection should always return cloudConnection', t => { test('Get connection should always return cloudConnection', t => {
const pool = new CloudConnectionPool({ Connection }) const pool = new CloudConnectionPool({ Connection })
const conn = pool.addConnection('http://localhost:9200/') const conn = pool.addConnection('http://localhost:9200/')
t.deepEqual(pool.getConnection(), conn) t.same(pool.getConnection(), conn)
t.end() t.end()
}) })
@ -42,7 +42,7 @@ test('pool.empty should reset cloudConnection', t => {
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
t.ok(pool.cloudConnection instanceof Connection) t.ok(pool.cloudConnection instanceof Connection)
pool.empty(() => { pool.empty(() => {
t.strictEqual(pool.cloudConnection, null) t.equal(pool.cloudConnection, null)
t.end() t.end()
}) })
}) })

View File

@ -32,8 +32,8 @@ test('API', t => {
const href = 'http://localhost:9200/' const href = 'http://localhost:9200/'
pool.addConnection(href) pool.addConnection(href)
t.ok(pool.connections.find(c => c.id === href) instanceof Connection) t.ok(pool.connections.find(c => c.id === href) instanceof Connection)
t.strictEqual(pool.connections.find(c => c.id === href).status, Connection.statuses.ALIVE) t.equal(pool.connections.find(c => c.id === href).status, Connection.statuses.ALIVE)
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
@ -45,7 +45,7 @@ test('API', t => {
pool.addConnection(href) pool.addConnection(href)
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.is(err.message, `Connection with id '${href}' is already present`) t.equal(err.message, `Connection with id '${href}' is already present`)
} }
t.end() t.end()
}) })
@ -55,8 +55,8 @@ test('API', t => {
const href = 'http://us"er:p@assword@localhost:9200/' const href = 'http://us"er:p@assword@localhost:9200/'
pool.addConnection(href) pool.addConnection(href)
const conn = pool.getConnection() const conn = pool.getConnection()
t.strictEqual(conn.url.username, 'us%22er') t.equal(conn.url.username, 'us%22er')
t.strictEqual(conn.url.password, 'p%40assword') t.equal(conn.url.password, 'p%40assword')
t.match(conn.headers, { t.match(conn.headers, {
authorization: 'Basic ' + Buffer.from('us"er:p@assword').toString('base64') authorization: 'Basic ' + Buffer.from('us"er:p@assword').toString('base64')
}) })
@ -69,9 +69,9 @@ test('API', t => {
let connection = pool.addConnection(href) let connection = pool.addConnection(href)
pool.markDead(connection) pool.markDead(connection)
connection = pool.connections.find(c => c.id === href) connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.deadCount, 1) t.equal(connection.deadCount, 1)
t.true(connection.resurrectTimeout > 0) t.ok(connection.resurrectTimeout > 0)
t.deepEqual(pool.dead, [href]) t.same(pool.dead, [href])
t.end() t.end()
}) })
@ -84,7 +84,7 @@ test('API', t => {
pool.markDead(conn2) pool.markDead(conn2)
setTimeout(() => { setTimeout(() => {
pool.markDead(conn1) pool.markDead(conn1)
t.deepEqual(pool.dead, [href2, href1]) t.same(pool.dead, [href2, href1])
t.end() t.end()
}, 10) }, 10)
}) })
@ -93,7 +93,7 @@ test('API', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true }) const pool = new ConnectionPool({ Connection, sniffEnabled: true })
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
pool.markDead({ id: 'foo-bar' }) pool.markDead({ id: 'foo-bar' })
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
@ -104,10 +104,10 @@ test('API', t => {
pool.markDead(connection) pool.markDead(connection)
pool.markAlive(connection) pool.markAlive(connection)
connection = pool.connections.find(c => c.id === href) connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.deadCount, 0) t.equal(connection.deadCount, 0)
t.strictEqual(connection.resurrectTimeout, 0) t.equal(connection.resurrectTimeout, 0)
t.strictEqual(connection.status, Connection.statuses.ALIVE) t.equal(connection.status, Connection.statuses.ALIVE)
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
@ -129,12 +129,12 @@ test('API', t => {
name: 'elasticsearch-js' name: 'elasticsearch-js'
} }
pool.resurrect(opts, (isAlive, connection) => { pool.resurrect(opts, (isAlive, connection) => {
t.true(isAlive) t.ok(isAlive)
connection = pool.connections.find(c => c.id === connection.id) connection = pool.connections.find(c => c.id === connection.id)
t.strictEqual(connection.deadCount, 0) t.equal(connection.deadCount, 0)
t.strictEqual(connection.resurrectTimeout, 0) t.equal(connection.resurrectTimeout, 0)
t.strictEqual(connection.status, Connection.statuses.ALIVE) t.equal(connection.status, Connection.statuses.ALIVE)
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
}) })
@ -155,12 +155,12 @@ test('API', t => {
name: 'elasticsearch-js' name: 'elasticsearch-js'
} }
pool.resurrect(opts, (isAlive, connection) => { pool.resurrect(opts, (isAlive, connection) => {
t.false(isAlive) t.notOk(isAlive)
connection = pool.connections.find(c => c.id === connection.id) connection = pool.connections.find(c => c.id === connection.id)
t.strictEqual(connection.deadCount, 2) t.equal(connection.deadCount, 2)
t.true(connection.resurrectTimeout > 0) t.ok(connection.resurrectTimeout > 0)
t.strictEqual(connection.status, Connection.statuses.DEAD) t.equal(connection.status, Connection.statuses.DEAD)
t.deepEqual(pool.dead, [href]) t.same(pool.dead, [href])
t.end() t.end()
}) })
}) })
@ -183,12 +183,12 @@ test('API', t => {
name: 'elasticsearch-js' name: 'elasticsearch-js'
} }
pool.resurrect(opts, (isAlive, connection) => { pool.resurrect(opts, (isAlive, connection) => {
t.true(isAlive) t.ok(isAlive)
connection = pool.connections.find(c => c.id === connection.id) connection = pool.connections.find(c => c.id === connection.id)
t.strictEqual(connection.deadCount, 1) t.equal(connection.deadCount, 1)
t.true(connection.resurrectTimeout > 0) t.ok(connection.resurrectTimeout > 0)
t.strictEqual(connection.status, Connection.statuses.ALIVE) t.equal(connection.status, Connection.statuses.ALIVE)
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
}) })
@ -211,10 +211,10 @@ test('API', t => {
t.ok(isAlive === null) t.ok(isAlive === null)
t.ok(connection === null) t.ok(connection === null)
connection = pool.connections.find(c => c.id === href) connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.deadCount, 1) t.equal(connection.deadCount, 1)
t.true(connection.resurrectTimeout > 0) t.ok(connection.resurrectTimeout > 0)
t.strictEqual(connection.status, Connection.statuses.DEAD) t.equal(connection.status, Connection.statuses.DEAD)
t.deepEqual(pool.dead, [href]) t.same(pool.dead, [href])
t.end() t.end()
}) })
}) })
@ -238,7 +238,7 @@ test('API', t => {
pool.addConnection([href1, href2]) pool.addConnection([href1, href2])
const filter = node => node.id === href1 const filter = node => node.id === href1
t.strictEqual(pool.getConnection({ filter }).id, href1) t.equal(pool.getConnection({ filter }).id, href1)
t.end() t.end()
}) })
@ -266,7 +266,7 @@ test('API', t => {
pool.markDead(conn) pool.markDead(conn)
const filter = node => { const filter = node => {
t.strictEqual(node.status, Connection.statuses.ALIVE) t.equal(node.status, Connection.statuses.ALIVE)
return true return true
} }
pool.getConnection({ filter }) pool.getConnection({ filter })
@ -282,7 +282,7 @@ test('API', t => {
pool.markDead(conn2) pool.markDead(conn2)
const conn = pool.getConnection() const conn = pool.getConnection()
t.ok(conn instanceof Connection) t.ok(conn instanceof Connection)
t.is(conn.status, 'dead') t.equal(conn.status, 'dead')
t.end() t.end()
}) })
@ -295,7 +295,7 @@ test('API', t => {
const connection = pool.addConnection(href) const connection = pool.addConnection(href)
t.ok(pool.getConnection() instanceof Connection) t.ok(pool.getConnection() instanceof Connection)
pool.removeConnection(connection) pool.removeConnection(connection)
t.strictEqual(pool.getConnection(), null) t.equal(pool.getConnection(), null)
t.end() t.end()
}) })
@ -304,8 +304,8 @@ test('API', t => {
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
pool.addConnection('http://localhost:9201/') pool.addConnection('http://localhost:9201/')
pool.empty(() => { pool.empty(() => {
t.strictEqual(pool.size, 0) t.equal(pool.size, 0)
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.end() t.end()
}) })
}) })
@ -313,7 +313,7 @@ test('API', t => {
t.test('urlToHost', t => { t.test('urlToHost', t => {
const pool = new ConnectionPool({ Connection }) const pool = new ConnectionPool({ Connection })
const url = 'http://localhost:9200' const url = 'http://localhost:9200'
t.deepEqual( t.same(
pool.urlToHost(url), pool.urlToHost(url),
{ url: new URL(url) } { url: new URL(url) }
) )
@ -338,7 +338,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://127.0.0.1:9200'), url: new URL('http://127.0.0.1:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -358,8 +358,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, '127.0.0.1:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, '127.0.0.1:9201')
t.end() t.end()
}) })
@ -380,7 +380,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://[::1]:9200'), url: new URL('http://[::1]:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -400,8 +400,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, '[::1]:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '[::1]:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, '[::1]:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, '[::1]:9201')
t.end() t.end()
}) })
@ -422,7 +422,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://example.com:9200'), url: new URL('http://example.com:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -442,8 +442,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201')
t.end() t.end()
}) })
@ -464,7 +464,7 @@ test('API', t => {
} }
} }
t.deepEqual(pool.nodesToHost(nodes, 'http:'), [{ t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://example.com:9200'), url: new URL('http://example.com:9200'),
id: 'a1', id: 'a1',
roles: { roles: {
@ -484,8 +484,8 @@ test('API', t => {
} }
}]) }])
t.strictEqual(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200') t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, 'example.com:9200')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.host, 'example.com:9201')
t.end() t.end()
}) })
@ -506,8 +506,8 @@ test('API', t => {
} }
} }
t.strictEqual(pool.nodesToHost(nodes, 'https:')[0].url.protocol, 'https:') t.equal(pool.nodesToHost(nodes, 'https:')[0].url.protocol, 'https:')
t.strictEqual(pool.nodesToHost(nodes, 'http:')[1].url.protocol, 'http:') t.equal(pool.nodesToHost(nodes, 'http:')[1].url.protocol, 'http:')
t.end() t.end()
}) })
@ -662,13 +662,13 @@ test('API', t => {
// roles will never be updated, we only use it to do // roles will never be updated, we only use it to do
// a dummy check to see if the connection has been updated // a dummy check to see if the connection has been updated
t.deepEqual(pool.connections.find(c => c.id === 'a1').roles, { t.same(pool.connections.find(c => c.id === 'a1').roles, {
master: true, master: true,
data: true, data: true,
ingest: true, ingest: true,
ml: false ml: false
}) })
t.strictEqual(pool.connections.find(c => c.id === 'http://127.0.0.1:9200/'), undefined) t.equal(pool.connections.find(c => c.id === 'http://127.0.0.1:9200/'), undefined)
}) })
t.test('Add a new connection', t => { t.test('Add a new connection', t => {
@ -717,9 +717,9 @@ test('API', t => {
roles: null roles: null
}]) }])
t.false(pool.connections.find(c => c.id === 'a1')) t.notOk(pool.connections.find(c => c.id === 'a1'))
t.true(pool.connections.find(c => c.id === 'a2')) t.ok(pool.connections.find(c => c.id === 'a2'))
t.true(pool.connections.find(c => c.id === 'a3')) t.ok(pool.connections.find(c => c.id === 'a3'))
}) })
t.test('Remove old connections (markDead)', t => { t.test('Remove old connections (markDead)', t => {
@ -732,7 +732,7 @@ test('API', t => {
}) })
pool.markDead(conn) pool.markDead(conn)
t.deepEqual(pool.dead, ['a1']) t.same(pool.dead, ['a1'])
pool.update([{ pool.update([{
url: new URL('http://127.0.0.1:9200'), url: new URL('http://127.0.0.1:9200'),
@ -744,10 +744,10 @@ test('API', t => {
roles: null roles: null
}]) }])
t.deepEqual(pool.dead, []) t.same(pool.dead, [])
t.false(pool.connections.find(c => c.id === 'a1')) t.notOk(pool.connections.find(c => c.id === 'a1'))
t.true(pool.connections.find(c => c.id === 'a2')) t.ok(pool.connections.find(c => c.id === 'a2'))
t.true(pool.connections.find(c => c.id === 'a3')) t.ok(pool.connections.find(c => c.id === 'a3'))
}) })
t.end() t.end()
@ -761,14 +761,14 @@ test('Node selector', t => {
t.plan(1) t.plan(1)
const pool = new ConnectionPool({ Connection }) const pool = new ConnectionPool({ Connection })
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
t.true(pool.getConnection({ selector: roundRobinSelector() }) instanceof Connection) t.ok(pool.getConnection({ selector: roundRobinSelector() }) instanceof Connection)
}) })
t.test('random', t => { t.test('random', t => {
t.plan(1) t.plan(1)
const pool = new ConnectionPool({ Connection }) const pool = new ConnectionPool({ Connection })
pool.addConnection('http://localhost:9200/') pool.addConnection('http://localhost:9200/')
t.true(pool.getConnection({ selector: roundRobinSelector() }) instanceof Connection) t.ok(pool.getConnection({ selector: roundRobinSelector() }) instanceof Connection)
}) })
t.end() t.end()
@ -779,7 +779,7 @@ test('Node filter', t => {
t.plan(1) t.plan(1)
const pool = new ConnectionPool({ Connection }) const pool = new ConnectionPool({ Connection })
pool.addConnection({ url: new URL('http://localhost:9200/') }) pool.addConnection({ url: new URL('http://localhost:9200/') })
t.true(pool.getConnection({ filter: defaultNodeFilter }) instanceof Connection) t.ok(pool.getConnection({ filter: defaultNodeFilter }) instanceof Connection)
}) })
t.test('Should filter master only nodes', t => { t.test('Should filter master only nodes', t => {
@ -794,7 +794,7 @@ test('Node filter', t => {
ml: false ml: false
} }
}) })
t.strictEqual(pool.getConnection({ filter: defaultNodeFilter }), null) t.equal(pool.getConnection({ filter: defaultNodeFilter }), null)
}) })
t.end() t.end()

View File

@ -63,7 +63,7 @@ test('Basic (http)', t => {
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -103,7 +103,7 @@ test('Basic (https)', t => {
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -144,7 +144,7 @@ test('Basic (https with ssl agent)', t => {
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -179,7 +179,7 @@ test('Custom http agent', t => {
return agent return agent
} }
}) })
t.true(connection.agent.custom) t.ok(connection.agent.custom)
connection.request({ connection.request({
path: '/hello', path: '/hello',
method: 'GET', method: 'GET',
@ -198,7 +198,7 @@ test('Custom http agent', t => {
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -268,7 +268,7 @@ test('querystring', t => {
t.plan(2) t.plan(2)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello?hello=world&you_know=for%20search') t.equal(req.url, '/hello?hello=world&you_know=for%20search')
res.end('ok') res.end('ok')
} }
@ -291,7 +291,7 @@ test('querystring', t => {
t.plan(2) t.plan(2)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello') t.equal(req.url, '/hello')
res.end('ok') res.end('ok')
} }
@ -322,7 +322,7 @@ test('Body request', t => {
req.on('data', chunk => { payload += chunk }) req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.strictEqual(payload, 'hello') t.equal(payload, 'hello')
res.end('ok') res.end('ok')
}) })
} }
@ -351,7 +351,7 @@ test('Send body as buffer', t => {
req.on('data', chunk => { payload += chunk }) req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.strictEqual(payload, 'hello') t.equal(payload, 'hello')
res.end('ok') res.end('ok')
}) })
} }
@ -380,7 +380,7 @@ test('Send body as stream', t => {
req.on('data', chunk => { payload += chunk }) req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.strictEqual(payload, 'hello') t.equal(payload, 'hello')
res.end('ok') res.end('ok')
}) })
} }
@ -413,7 +413,7 @@ test('Should not close a connection if there are open requests', t => {
}) })
setTimeout(() => { setTimeout(() => {
t.strictEqual(connection._openRequests, 1) t.equal(connection._openRequests, 1)
connection.close() connection.close()
}, 500) }, 500)
@ -422,14 +422,14 @@ test('Should not close a connection if there are open requests', t => {
method: 'GET' method: 'GET'
}, (err, res) => { }, (err, res) => {
t.error(err) t.error(err)
t.strictEqual(connection._openRequests, 0) t.equal(connection._openRequests, 0)
let payload = '' let payload = ''
res.setEncoding('utf8') res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -450,7 +450,7 @@ test('Should not close a connection if there are open requests (with agent disab
}) })
setTimeout(() => { setTimeout(() => {
t.strictEqual(connection._openRequests, 1) t.equal(connection._openRequests, 1)
connection.close() connection.close()
}, 500) }, 500)
@ -459,14 +459,14 @@ test('Should not close a connection if there are open requests (with agent disab
method: 'GET' method: 'GET'
}, (err, res) => { }, (err, res) => {
t.error(err) t.error(err)
t.strictEqual(connection._openRequests, 0) t.equal(connection._openRequests, 0)
let payload = '' let payload = ''
res.setEncoding('utf8') res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -502,7 +502,7 @@ test('Url with querystring', t => {
t.plan(2) t.plan(2)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello?foo=bar&baz=faz') t.equal(req.url, '/hello?foo=bar&baz=faz')
res.end('ok') res.end('ok')
} }
@ -546,7 +546,7 @@ test('Custom headers for connection', t => {
}, (err, res) => { }, (err, res) => {
t.error(err) t.error(err)
// should not update the default // should not update the default
t.deepEqual(connection.headers, { 'x-foo': 'bar' }) t.same(connection.headers, { 'x-foo': 'bar' })
server.stop() server.stop()
}) })
}) })
@ -576,7 +576,7 @@ test('asStream set to true', t => {
res.on('data', chunk => { payload += chunk }) res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err)) res.on('error', err => t.fail(err))
res.on('end', () => { res.on('end', () => {
t.strictEqual(payload, 'ok') t.equal(payload, 'ok')
server.stop() server.stop()
}) })
}) })
@ -587,7 +587,7 @@ test('Connection id should not contain credentials', t => {
const connection = new Connection({ const connection = new Connection({
url: new URL('http://user:password@localhost:9200') url: new URL('http://user:password@localhost:9200')
}) })
t.strictEqual(connection.id, 'http://localhost:9200/') t.equal(connection.id, 'http://localhost:9200/')
t.end() t.end()
}) })
@ -595,7 +595,7 @@ test('Ipv6 support', t => {
const connection = new Connection({ const connection = new Connection({
url: new URL('http://[::1]:9200') url: new URL('http://[::1]:9200')
}) })
t.strictEqual(connection.buildRequestObject({}).hostname, '::1') t.equal(connection.buildRequestObject({}).hostname, '::1')
t.end() t.end()
}) })
@ -607,7 +607,7 @@ test('Should throw if the protocol is not http or https', t => {
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.ok(err instanceof ConfigurationError) t.ok(err instanceof ConfigurationError)
t.is(err.message, 'Invalid protocol: \'nope:\'') t.equal(err.message, 'Invalid protocol: \'nope:\'')
} }
t.end() t.end()
}) })
@ -623,7 +623,7 @@ test('Should disallow two-byte characters in URL path', t => {
path: '/thisisinvalid\uffe2', path: '/thisisinvalid\uffe2',
method: 'GET' method: 'GET'
}, (err, res) => { }, (err, res) => {
t.strictEqual( t.equal(
err.message, err.message,
'ERR_UNESCAPED_CHARACTERS: /thisisinvalid\uffe2' 'ERR_UNESCAPED_CHARACTERS: /thisisinvalid\uffe2'
) )
@ -638,7 +638,7 @@ test('setRole', t => {
url: new URL('http://localhost:9200') url: new URL('http://localhost:9200')
}) })
t.deepEqual(connection.roles, { t.same(connection.roles, {
master: true, master: true,
data: true, data: true,
ingest: true, ingest: true,
@ -647,7 +647,7 @@ test('setRole', t => {
connection.setRole('master', false) connection.setRole('master', false)
t.deepEqual(connection.roles, { t.same(connection.roles, {
master: false, master: false,
data: true, data: true,
ingest: true, ingest: true,
@ -666,8 +666,8 @@ test('setRole', t => {
connection.setRole('car', true) connection.setRole('car', true)
t.fail('Shoud throw') t.fail('Shoud throw')
} catch (err) { } catch (err) {
t.true(err instanceof ConfigurationError) t.ok(err instanceof ConfigurationError)
t.is(err.message, 'Unsupported role: \'car\'') t.equal(err.message, 'Unsupported role: \'car\'')
} }
}) })
@ -682,8 +682,8 @@ test('setRole', t => {
connection.setRole('master', 1) connection.setRole('master', 1)
t.fail('Shoud throw') t.fail('Shoud throw')
} catch (err) { } catch (err) {
t.true(err instanceof ConfigurationError) t.ok(err instanceof ConfigurationError)
t.is(err.message, 'enabled should be a boolean') t.equal(err.message, 'enabled should be a boolean')
} }
}) })
@ -708,7 +708,7 @@ test('Util.inspect Connection class should hide agent, ssl and auth', t => {
.replace(/(\r\n|\n|\r)/gm, '') .replace(/(\r\n|\n|\r)/gm, '')
} }
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url: 'http://localhost:9200/', t.equal(cleanStr(inspect(connection)), cleanStr(`{ url: 'http://localhost:9200/',
id: 'node-id', id: 'node-id',
headers: { foo: 'bar' }, headers: { foo: 'bar' },
deadCount: 0, deadCount: 0,
@ -728,7 +728,7 @@ test('connection.toJSON should hide agent, ssl and auth', t => {
headers: { foo: 'bar' } headers: { foo: 'bar' }
}) })
t.deepEqual(connection.toJSON(), { t.same(connection.toJSON(), {
url: 'http://localhost:9200/', url: 'http://localhost:9200/',
id: 'node-id', id: 'node-id',
headers: { headers: {
@ -754,7 +754,7 @@ test('Port handling', t => {
url: new URL('http://localhost:80') url: new URL('http://localhost:80')
}) })
t.strictEqual( t.equal(
connection.buildRequestObject({}).port, connection.buildRequestObject({}).port,
undefined undefined
) )
@ -767,7 +767,7 @@ test('Port handling', t => {
url: new URL('https://localhost:443') url: new URL('https://localhost:443')
}) })
t.strictEqual( t.equal(
connection.buildRequestObject({}).port, connection.buildRequestObject({}).port,
undefined undefined
) )
@ -784,7 +784,7 @@ test('Authorization header', t => {
url: new URL('http://localhost:9200') url: new URL('http://localhost:9200')
}) })
t.deepEqual(connection.headers, {}) t.same(connection.headers, {})
t.end() t.end()
}) })
@ -795,7 +795,7 @@ test('Authorization header', t => {
auth: { username: 'foo', password: 'bar' } auth: { username: 'foo', password: 'bar' }
}) })
t.deepEqual(connection.headers, { authorization: 'Basic Zm9vOmJhcg==' }) t.same(connection.headers, { authorization: 'Basic Zm9vOmJhcg==' })
t.end() t.end()
}) })
@ -806,7 +806,7 @@ test('Authorization header', t => {
auth: { apiKey: 'Zm9vOmJhcg==' } auth: { apiKey: 'Zm9vOmJhcg==' }
}) })
t.deepEqual(connection.headers, { authorization: 'ApiKey Zm9vOmJhcg==' }) t.same(connection.headers, { authorization: 'ApiKey Zm9vOmJhcg==' })
t.end() t.end()
}) })
@ -817,7 +817,7 @@ test('Authorization header', t => {
auth: { apiKey: { id: 'foo', api_key: 'bar' } } auth: { apiKey: { id: 'foo', api_key: 'bar' } }
}) })
t.deepEqual(connection.headers, { authorization: 'ApiKey Zm9vOmJhcg==' }) t.same(connection.headers, { authorization: 'ApiKey Zm9vOmJhcg==' })
t.end() t.end()
}) })
@ -830,7 +830,7 @@ test('Should not add agent and ssl to the serialized connection', t => {
url: new URL('http://localhost:9200') url: new URL('http://localhost:9200')
}) })
t.strictEqual( t.equal(
JSON.stringify(connection), JSON.stringify(connection),
'{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":{},"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}}' '{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":{},"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}}'
) )
@ -890,7 +890,7 @@ test('Should correctly resolve request pathname', t => {
url: new URL('http://localhost:80/test') url: new URL('http://localhost:80/test')
}) })
t.strictEqual( t.equal(
connection.buildRequestObject({ connection.buildRequestObject({
path: 'hello' path: 'hello'
}).pathname, }).pathname,
@ -906,7 +906,7 @@ test('Proxy agent (http)', t => {
proxy: 'http://localhost:8080' proxy: 'http://localhost:8080'
}) })
t.true(connection.agent instanceof hpagent.HttpProxyAgent) t.ok(connection.agent instanceof hpagent.HttpProxyAgent)
}) })
test('Proxy agent (https)', t => { test('Proxy agent (https)', t => {
@ -917,7 +917,7 @@ test('Proxy agent (https)', t => {
proxy: 'http://localhost:8080' proxy: 'http://localhost:8080'
}) })
t.true(connection.agent instanceof hpagent.HttpsProxyAgent) t.ok(connection.agent instanceof hpagent.HttpsProxyAgent)
}) })
test('Abort with a slow body', t => { test('Abort with a slow body', t => {

View File

@ -26,57 +26,57 @@ const { errors } = require('../../index')
test('ElasticsearchClientError', t => { test('ElasticsearchClientError', t => {
const err = new errors.ElasticsearchClientError() const err = new errors.ElasticsearchClientError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.end() t.end()
}) })
test('TimeoutError', t => { test('TimeoutError', t => {
const err = new errors.TimeoutError() const err = new errors.TimeoutError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.true(err.hasOwnProperty('meta')) t.ok(err.hasOwnProperty('meta'))
t.end() t.end()
}) })
test('ConnectionError', t => { test('ConnectionError', t => {
const err = new errors.ConnectionError() const err = new errors.ConnectionError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.true(err.hasOwnProperty('meta')) t.ok(err.hasOwnProperty('meta'))
t.end() t.end()
}) })
test('NoLivingConnectionsError', t => { test('NoLivingConnectionsError', t => {
const err = new errors.NoLivingConnectionsError() const err = new errors.NoLivingConnectionsError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.true(err.hasOwnProperty('meta')) t.ok(err.hasOwnProperty('meta'))
t.end() t.end()
}) })
test('SerializationError', t => { test('SerializationError', t => {
const err = new errors.SerializationError() const err = new errors.SerializationError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.false(err.hasOwnProperty('meta')) t.notOk(err.hasOwnProperty('meta'))
t.true(err.hasOwnProperty('data')) t.ok(err.hasOwnProperty('data'))
t.end() t.end()
}) })
test('DeserializationError', t => { test('DeserializationError', t => {
const err = new errors.DeserializationError() const err = new errors.DeserializationError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.false(err.hasOwnProperty('meta')) t.notOk(err.hasOwnProperty('meta'))
t.true(err.hasOwnProperty('data')) t.ok(err.hasOwnProperty('data'))
t.end() t.end()
}) })
test('ConfigurationError', t => { test('ConfigurationError', t => {
const err = new errors.ConfigurationError() const err = new errors.ConfigurationError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.false(err.hasOwnProperty('meta')) t.notOk(err.hasOwnProperty('meta'))
t.end() t.end()
}) })
@ -87,9 +87,9 @@ test('ResponseError', t => {
headers: 1 headers: 1
} }
const err = new errors.ResponseError(meta) const err = new errors.ResponseError(meta)
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.true(err.hasOwnProperty('meta')) t.ok(err.hasOwnProperty('meta'))
t.ok(err.body) t.ok(err.body)
t.ok(err.statusCode) t.ok(err.statusCode)
t.ok(err.headers) t.ok(err.headers)
@ -98,9 +98,9 @@ test('ResponseError', t => {
test('RequestAbortedError', t => { test('RequestAbortedError', t => {
const err = new errors.RequestAbortedError() const err = new errors.RequestAbortedError()
t.true(err instanceof Error) t.ok(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError) t.ok(err instanceof errors.ElasticsearchClientError)
t.true(err.hasOwnProperty('meta')) t.ok(err.hasOwnProperty('meta'))
t.end() t.end()
}) })
@ -131,8 +131,8 @@ test('ResponseError with meaningful message / 1', t => {
headers: {} headers: {}
} }
const err = new errors.ResponseError(meta) const err = new errors.ResponseError(meta)
t.strictEqual(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]') t.equal(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]')
t.strictEqual(err.toString(), JSON.stringify(meta.body)) t.equal(err.toString(), JSON.stringify(meta.body))
t.end() t.end()
}) })
@ -171,8 +171,8 @@ test('ResponseError with meaningful message / 2', t => {
headers: {} headers: {}
} }
const err = new errors.ResponseError(meta) const err = new errors.ResponseError(meta)
t.strictEqual(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]; [nested_cause] Reason: this is a nested cause') t.equal(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]; [nested_cause] Reason: this is a nested cause')
t.strictEqual(err.toString(), JSON.stringify(meta.body)) t.equal(err.toString(), JSON.stringify(meta.body))
t.end() t.end()
}) })
@ -193,7 +193,7 @@ test('ResponseError with meaningful message / 3', t => {
headers: {} headers: {}
} }
const err = new errors.ResponseError(meta) const err = new errors.ResponseError(meta)
t.strictEqual(err.message, 'index_not_found_exception') t.equal(err.message, 'index_not_found_exception')
t.strictEqual(err.toString(), JSON.stringify(meta.body)) t.equal(err.toString(), JSON.stringify(meta.body))
t.end() t.end()
}) })

View File

@ -4,5 +4,5 @@ import { Client } from '../../../index.mjs'
t.test('esm support', t => { t.test('esm support', t => {
t.plan(1) t.plan(1)
const client = new Client({ node: 'http://localhost:9200' }) const client = new Client({ node: 'http://localhost:9200' })
t.strictEqual(client.name, 'elasticsearch-js') t.equal(client.name, 'elasticsearch-js')
}) })

View File

@ -289,7 +289,7 @@ test('Emit event', t => {
client.on(events.REQUEST, (err, request) => { client.on(events.REQUEST, (err, request) => {
t.error(err) t.error(err)
t.deepEqual(request, { hello: 'world' }) t.same(request, { hello: 'world' })
}) })
client.emit(events.REQUEST, null, { hello: 'world' }) client.emit(events.REQUEST, null, { hello: 'world' })

View File

@ -44,14 +44,14 @@ test('bulk index', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { t.match(params.headers, {
'content-type': 'application/x-ndjson', 'content-type': 'application/x-ndjson',
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp` 'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp`
}) })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -89,14 +89,14 @@ test('bulk index', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
t.notMatch(params.headers, { t.notMatch(params.headers, {
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp` 'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp`
}) })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -134,9 +134,9 @@ test('bulk index', t => {
t.test('Should perform a bulk request (high flush size)', async t => { t.test('Should perform a bulk request (high flush size)', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
t.strictEqual(params.body.split('\n').filter(Boolean).length, 6) t.equal(params.body.split('\n').filter(Boolean).length, 6)
return { body: { errors: false, items: new Array(3).fill({}) } } return { body: { errors: false, items: new Array(3).fill({}) } }
} }
}) })
@ -175,14 +175,14 @@ test('bulk index', t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
if (params.method === 'GET') { if (params.method === 'GET') {
t.strictEqual(params.path, '/_all/_refresh') t.equal(params.path, '/_all/_refresh')
return { body: { acknowledged: true } } return { body: { acknowledged: true } }
} else { } else {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
} }
@ -220,14 +220,14 @@ test('bulk index', t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
if (params.method === 'GET') { if (params.method === 'GET') {
t.strictEqual(params.path, '/test/_refresh') t.equal(params.path, '/test/_refresh')
return { body: { acknowledged: true } } return { body: { acknowledged: true } }
} else { } else {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
} }
@ -264,11 +264,11 @@ test('bulk index', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test', _id: count } }) t.same(JSON.parse(action), { index: { _index: 'test', _id: count } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -308,7 +308,7 @@ test('bulk index', t => {
t.test('Should perform a bulk request (retry)', async t => { t.test('Should perform a bulk request (retry)', async t => {
async function handler (req, res) { async function handler (req, res) {
t.strictEqual(req.url, '/_bulk') t.equal(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' }) t.match(req.headers, { 'content-type': 'application/x-ndjson' })
let body = '' let body = ''
@ -353,7 +353,7 @@ test('bulk index', t => {
} }
}, },
onDrop (doc) { onDrop (doc) {
t.deepEqual(doc, { t.same(doc, {
status: 429, status: 429,
error: null, error: null,
operation: { index: { _index: 'test' } }, operation: { index: { _index: 'test' } },
@ -402,7 +402,7 @@ test('bulk index', t => {
} }
}, },
onDrop (doc) { onDrop (doc) {
t.deepEqual(doc, { t.same(doc, {
status: 429, status: 429,
error: null, error: null,
operation: { index: { _index: 'test' } }, operation: { index: { _index: 'test' } },
@ -426,7 +426,7 @@ test('bulk index', t => {
t.test('Should perform a bulk request (failure)', async t => { t.test('Should perform a bulk request (failure)', async t => {
async function handler (req, res) { async function handler (req, res) {
t.strictEqual(req.url, '/_bulk') t.equal(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' }) t.match(req.headers, { 'content-type': 'application/x-ndjson' })
let body = '' let body = ''
@ -471,7 +471,7 @@ test('bulk index', t => {
} }
}, },
onDrop (doc) { onDrop (doc) {
t.deepEqual(doc, { t.same(doc, {
status: 400, status: 400,
error: { something: 'went wrong' }, error: { something: 'went wrong' },
operation: { index: { _index: 'test' } }, operation: { index: { _index: 'test' } },
@ -525,7 +525,7 @@ test('bulk index', t => {
await b await b
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
} }
}) })
@ -561,13 +561,13 @@ test('bulk index', t => {
await b await b
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
} }
}) })
t.test('Should abort a bulk request', async t => { t.test('Should abort a bulk request', async t => {
async function handler (req, res) { async function handler (req, res) {
t.strictEqual(req.url, '/_bulk') t.equal(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' }) t.match(req.headers, { 'content-type': 'application/x-ndjson' })
let body = '' let body = ''
@ -653,8 +653,8 @@ test('bulk index', t => {
} }
}) })
.catch(err => { .catch(err => {
t.true(err instanceof errors.ConfigurationError) t.ok(err instanceof errors.ConfigurationError)
t.is(err.message, 'Bulk helper invalid action: \'foo\'') t.equal(err.message, 'Bulk helper invalid action: \'foo\'')
}) })
}) })
@ -666,11 +666,11 @@ test('bulk index', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test', _id: count } }) t.same(JSON.parse(action), { index: { _index: 'test', _id: count } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -718,11 +718,11 @@ test('bulk index', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -774,11 +774,11 @@ test('bulk create', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { create: { _index: 'test', _id: count } }) t.same(JSON.parse(action), { create: { _index: 'test', _id: count } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -823,11 +823,11 @@ test('bulk update', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { update: { _index: 'test', _id: count } }) t.same(JSON.parse(action), { update: { _index: 'test', _id: count } })
t.deepEqual(JSON.parse(payload), { doc: dataset[count++], doc_as_upsert: true }) t.same(JSON.parse(payload), { doc: dataset[count++], doc_as_upsert: true })
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -871,11 +871,11 @@ test('bulk update', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { update: { _index: 'test', _id: count } }) t.same(JSON.parse(action), { update: { _index: 'test', _id: count } })
t.deepEqual(JSON.parse(payload), { doc: dataset[count++] }) t.same(JSON.parse(payload), { doc: dataset[count++] })
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -921,9 +921,9 @@ test('bulk delete', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
t.deepEqual(JSON.parse(params.body), { delete: { _index: 'test', _id: count++ } }) t.same(JSON.parse(params.body), { delete: { _index: 'test', _id: count++ } })
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -963,7 +963,7 @@ test('bulk delete', t => {
t.test('Should perform a bulk request (failure)', async t => { t.test('Should perform a bulk request (failure)', async t => {
async function handler (req, res) { async function handler (req, res) {
t.strictEqual(req.url, '/_bulk') t.equal(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' }) t.match(req.headers, { 'content-type': 'application/x-ndjson' })
let body = '' let body = ''
@ -1011,7 +1011,7 @@ test('bulk delete', t => {
} }
}, },
onDrop (doc) { onDrop (doc) {
t.deepEqual(doc, { t.same(doc, {
status: 400, status: 400,
error: { something: 'went wrong' }, error: { something: 'went wrong' },
operation: { delete: { _index: 'test', _id: 1 } }, operation: { delete: { _index: 'test', _id: 1 } },
@ -1051,7 +1051,7 @@ test('transport options', t => {
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
t.strictEqual(params.path, '/_all/_refresh') t.equal(params.path, '/_all/_refresh')
t.match(params.headers, { t.match(params.headers, {
foo: 'bar' foo: 'bar'
}) })
@ -1081,7 +1081,7 @@ test('transport options', t => {
} }
}) })
t.strictEqual(count, 4) // three bulk requests, one refresh t.equal(count, 4) // three bulk requests, one refresh
t.type(result.time, 'number') t.type(result.time, 'number')
t.type(result.bytes, 'number') t.type(result.bytes, 'number')
t.match(result, { t.match(result, {
@ -1111,8 +1111,8 @@ test('errors', t => {
} }
}) })
} catch (err) { } catch (err) {
t.true(err instanceof errors.ConfigurationError) t.ok(err instanceof errors.ConfigurationError)
t.is(err.message, 'bulk helper: the datasource must be an array or a buffer or a readable stream or an async generator') t.equal(err.message, 'bulk helper: the datasource must be an array or a buffer or a readable stream or an async generator')
} }
}) })
@ -1129,8 +1129,8 @@ test('errors', t => {
} }
}) })
} catch (err) { } catch (err) {
t.true(err instanceof errors.ConfigurationError) t.ok(err instanceof errors.ConfigurationError)
t.is(err.message, 'bulk helper: the datasource is required') t.equal(err.message, 'bulk helper: the datasource is required')
} }
}) })
@ -1143,8 +1143,8 @@ test('errors', t => {
datasource: dataset.slice() datasource: dataset.slice()
}) })
} catch (err) { } catch (err) {
t.true(err instanceof errors.ConfigurationError) t.ok(err instanceof errors.ConfigurationError)
t.is(err.message, 'bulk helper: the onDocument callback is required') t.equal(err.message, 'bulk helper: the onDocument callback is required')
} }
}) })
@ -1159,11 +1159,11 @@ test('Flush interval', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })
@ -1210,12 +1210,12 @@ test('Flush interval', t => {
let count = 0 let count = 0
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.true(count < 2) t.ok(count < 2)
t.strictEqual(params.path, '/_bulk') t.equal(params.path, '/_bulk')
t.match(params.headers, { 'content-type': 'application/x-ndjson' }) t.match(params.headers, { 'content-type': 'application/x-ndjson' })
const [action, payload] = params.body.split('\n') const [action, payload] = params.body.split('\n')
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } }) t.same(JSON.parse(action), { index: { _index: 'test' } })
t.deepEqual(JSON.parse(payload), dataset[count++]) t.same(JSON.parse(payload), dataset[count++])
return { body: { errors: false, items: [{}] } } return { body: { errors: false, items: [{}] } }
} }
}) })

View File

@ -56,7 +56,7 @@ test('Basic', async t => {
{ query: { match: { foo: 'bar' } } } { query: { match: { foo: 'bar' } } }
) )
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -67,7 +67,7 @@ test('Basic', async t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -116,7 +116,7 @@ test('Multiple searches (inside async iterator)', t => {
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -127,7 +127,7 @@ test('Multiple searches (inside async iterator)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -136,7 +136,7 @@ test('Multiple searches (inside async iterator)', t => {
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -147,7 +147,7 @@ test('Multiple searches (inside async iterator)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ four: 'four' }, { four: 'four' },
{ five: 'five' }, { five: 'five' },
{ six: 'six' } { six: 'six' }
@ -197,7 +197,7 @@ test('Multiple searches (async iterator exits)', t => {
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -208,7 +208,7 @@ test('Multiple searches (async iterator exits)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -217,7 +217,7 @@ test('Multiple searches (async iterator exits)', t => {
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -228,7 +228,7 @@ test('Multiple searches (async iterator exits)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ four: 'four' }, { four: 'four' },
{ five: 'five' }, { five: 'five' },
{ six: 'six' } { six: 'six' }
@ -260,7 +260,7 @@ test('Stop a msearch processor (promises)', async t => {
{ query: { match: { foo: 'bar' } } } { query: { match: { foo: 'bar' } } }
) )
} catch (err) { } catch (err) {
t.strictEqual(err.message, 'The msearch processor has been stopped') t.equal(err.message, 'The msearch processor has been stopped')
} }
t.teardown(() => m.stop()) t.teardown(() => m.stop())
@ -285,7 +285,7 @@ test('Stop a msearch processor (callbacks)', t => {
m.stop() m.stop()
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.strictEqual(err.message, 'The msearch processor has been stopped') t.equal(err.message, 'The msearch processor has been stopped')
}) })
}) })
@ -306,12 +306,12 @@ test('Bad header', t => {
const m = client.helpers.msearch() const m = client.helpers.msearch()
m.search(null, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search(null, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.strictEqual(err.message, 'The header should be an object') t.equal(err.message, 'The header should be an object')
}) })
m.search(null, { query: { match: { foo: 'bar' } } }) m.search(null, { query: { match: { foo: 'bar' } } })
.catch(err => { .catch(err => {
t.strictEqual(err.message, 'The header should be an object') t.equal(err.message, 'The header should be an object')
}) })
t.teardown(() => m.stop()) t.teardown(() => m.stop())
@ -334,12 +334,12 @@ test('Bad body', t => {
const m = client.helpers.msearch() const m = client.helpers.msearch()
m.search({ index: 'test' }, null, (err, result) => { m.search({ index: 'test' }, null, (err, result) => {
t.strictEqual(err.message, 'The body should be an object') t.equal(err.message, 'The body should be an object')
}) })
m.search({ index: 'test' }, null) m.search({ index: 'test' }, null)
.catch(err => { .catch(err => {
t.strictEqual(err.message, 'The body should be an object') t.equal(err.message, 'The body should be an object')
}) })
t.teardown(() => m.stop()) t.teardown(() => m.stop())
@ -389,7 +389,7 @@ test('Retry on 429', async t => {
{ query: { match: { foo: 'bar' } } } { query: { match: { foo: 'bar' } } }
) )
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -400,7 +400,7 @@ test('Retry on 429', async t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -436,7 +436,7 @@ test('Single search errors', async t => {
{ query: { match: { foo: 'bar' } } } { query: { match: { foo: 'bar' } } }
) )
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
} }
t.teardown(() => m.stop()) t.teardown(() => m.stop())
@ -465,13 +465,13 @@ test('Entire msearch fails', t => {
const m = client.helpers.msearch({ operations: 1 }) const m = client.helpers.msearch({ operations: 1 })
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
t.deepEqual(result.documents, []) t.same(result.documents, [])
}) })
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
t.deepEqual(result.documents, []) t.same(result.documents, [])
}) })
t.teardown(() => m.stop()) t.teardown(() => m.stop())
@ -523,13 +523,13 @@ test('Stop the msearch helper with an error', t => {
m.then( m.then(
() => t.fail('Should fail'), () => t.fail('Should fail'),
err => t.is(err.message, 'kaboom') err => t.equal(err.message, 'kaboom')
) )
m.catch(err => t.is(err.message, 'kaboom')) m.catch(err => t.equal(err.message, 'kaboom'))
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.is(err.message, 'kaboom') t.equal(err.message, 'kaboom')
}) })
}) })
@ -564,7 +564,7 @@ test('Multiple searches (concurrency = 1)', t => {
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -575,7 +575,7 @@ test('Multiple searches (concurrency = 1)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -584,7 +584,7 @@ test('Multiple searches (concurrency = 1)', t => {
m.search({ index: 'test' }, { query: {} }, (err, result) => { m.search({ index: 'test' }, { query: {} }, (err, result) => {
t.error(err) t.error(err)
t.deepEqual(result.body, { t.same(result.body, {
status: 200, status: 200,
hits: { hits: {
hits: [ hits: [
@ -595,7 +595,7 @@ test('Multiple searches (concurrency = 1)', t => {
} }
}) })
t.deepEqual(result.documents, [ t.same(result.documents, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -647,12 +647,12 @@ test('Flush interval', t => {
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.is(result.documents.length, 3) t.equal(result.documents.length, 3)
}) })
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.is(result.documents.length, 3) t.equal(result.documents.length, 3)
}) })
setImmediate(clock.next) setImmediate(clock.next)
@ -691,7 +691,7 @@ test('Flush interval - early stop', t => {
m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => {
t.error(err) t.error(err)
t.is(result.documents.length, 3) t.equal(result.documents.length, 3)
}) })
setImmediate(() => { setImmediate(() => {
@ -750,11 +750,11 @@ test('Stop should resolve the helper (error)', t => {
setImmediate(m.stop, new Error('kaboom')) setImmediate(m.stop, new Error('kaboom'))
m.then(() => t.fail('Should not fail')) m.then(() => t.fail('Should not fail'))
.catch(err => t.is(err.message, 'kaboom')) .catch(err => t.equal(err.message, 'kaboom'))
m.catch(err => t.is(err.message, 'kaboom')) m.catch(err => t.equal(err.message, 'kaboom'))
m.then(() => t.fail('Should not fail'), err => t.is(err.message, 'kaboom')) m.then(() => t.fail('Should not fail'), err => t.equal(err.message, 'kaboom'))
}) })
test('Should use req options', async t => { test('Should use req options', async t => {

View File

@ -38,11 +38,11 @@ test('Scroll search', async t => {
count += 1 count += 1
if (params.method === 'POST') { if (params.method === 'POST') {
t.strictEqual(params.querystring, 'scroll=1m') t.equal(params.querystring, 'scroll=1m')
} }
if (count === 4) { if (count === 4) {
// final automated clear // final automated clear
t.strictEqual(params.method, 'DELETE') t.equal(params.method, 'DELETE')
} }
return { return {
body: { body: {
@ -73,8 +73,8 @@ test('Scroll search', async t => {
}) })
for await (const result of scrollSearch) { for await (const result of scrollSearch) {
t.strictEqual(result.body.count, count) t.equal(result.body.count, count)
t.strictEqual(result.body._scroll_id, 'id') t.equal(result.body._scroll_id, 'id')
} }
}) })
@ -87,7 +87,7 @@ test('Clear a scroll search', async t => {
}) })
if (params.method === 'DELETE') { if (params.method === 'DELETE') {
const body = JSON.parse(params.body) const body = JSON.parse(params.body)
t.strictEqual(body.scroll_id, 'id') t.equal(body.scroll_id, 'id')
} }
return { return {
body: { body: {
@ -120,7 +120,7 @@ test('Clear a scroll search', async t => {
if (count === 2) { if (count === 2) {
t.fail('The scroll search should be cleared') t.fail('The scroll search should be cleared')
} }
t.strictEqual(result.body.count, count) t.equal(result.body.count, count)
if (count === 1) { if (count === 1) {
await result.clear() await result.clear()
} }
@ -138,7 +138,7 @@ test('Scroll search (retry)', async t => {
} }
if (count === 5) { if (count === 5) {
// final automated clear // final automated clear
t.strictEqual(params.method, 'DELETE') t.equal(params.method, 'DELETE')
} }
return { return {
statusCode: 200, statusCode: 200,
@ -172,9 +172,9 @@ test('Scroll search (retry)', async t => {
}) })
for await (const result of scrollSearch) { for await (const result of scrollSearch) {
t.strictEqual(result.body.count, count) t.equal(result.body.count, count)
t.notStrictEqual(result.body.count, 1) t.not(result.body.count, 1)
t.strictEqual(result.body._scroll_id, 'id') t.equal(result.body._scroll_id, 'id')
} }
}) })
@ -208,9 +208,9 @@ test('Scroll search (retry throws and maxRetries)', async t => {
t.fail('we should not be here') t.fail('we should not be here')
} }
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
t.strictEqual(err.statusCode, 429) t.equal(err.statusCode, 429)
t.strictEqual(count, expectedAttempts) t.equal(count, expectedAttempts)
} }
}) })
@ -222,7 +222,7 @@ test('Scroll search (retry throws later)', async t => {
onRequest (params) { onRequest (params) {
count += 1 count += 1
// filter_path should not be added if is not already present // filter_path should not be added if is not already present
t.strictEqual(params.querystring, 'scroll=1m') t.equal(params.querystring, 'scroll=1m')
if (count > 1) { if (count > 1) {
return { body: {}, statusCode: 429 } return { body: {}, statusCode: 429 }
} }
@ -258,12 +258,12 @@ test('Scroll search (retry throws later)', async t => {
try { try {
for await (const result of scrollSearch) { // eslint-disable-line for await (const result of scrollSearch) { // eslint-disable-line
t.strictEqual(result.body.count, count) t.equal(result.body.count, count)
} }
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
t.strictEqual(err.statusCode, 429) t.equal(err.statusCode, 429)
t.strictEqual(count, expectedAttempts) t.equal(count, expectedAttempts)
} }
}) })
@ -272,11 +272,11 @@ test('Scroll search documents', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
if (count === 0) { if (count === 0) {
t.strictEqual(params.querystring, 'filter_path=hits.hits._source%2C_scroll_id&scroll=1m') t.equal(params.querystring, 'filter_path=hits.hits._source%2C_scroll_id&scroll=1m')
} else { } else {
if (params.method !== 'DELETE') { if (params.method !== 'DELETE') {
t.strictEqual(params.querystring, 'scroll=1m') t.equal(params.querystring, 'scroll=1m')
t.strictEqual(params.body, '{"scroll_id":"id"}') t.equal(params.body, '{"scroll_id":"id"}')
} }
} }
return { return {
@ -309,7 +309,7 @@ test('Scroll search documents', async t => {
let n = 1 let n = 1
for await (const hit of scrollSearch) { for await (const hit of scrollSearch) {
t.deepEqual(hit, { val: n * count }) t.same(hit, { val: n * count })
n += 1 n += 1
if (n === 4) { if (n === 4) {
count += 1 count += 1
@ -348,9 +348,9 @@ test('Should not retry if maxRetries = 0', async t => {
t.fail('we should not be here') t.fail('we should not be here')
} }
} catch (err) { } catch (err) {
t.true(err instanceof errors.ResponseError) t.ok(err instanceof errors.ResponseError)
t.strictEqual(err.statusCode, 429) t.equal(err.statusCode, 429)
t.strictEqual(count, expectedAttempts) t.equal(count, expectedAttempts)
} }
}) })
@ -359,10 +359,10 @@ test('Fix querystring for scroll search', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
if (count === 0) { if (count === 0) {
t.strictEqual(params.querystring, 'size=1&scroll=1m') t.equal(params.querystring, 'size=1&scroll=1m')
} else { } else {
if (params.method !== 'DELETE') { if (params.method !== 'DELETE') {
t.strictEqual(params.querystring, 'scroll=1m') t.equal(params.querystring, 'scroll=1m')
} }
} }
return { return {
@ -392,7 +392,7 @@ test('Fix querystring for scroll search', async t => {
}) })
for await (const response of scrollSearch) { for await (const response of scrollSearch) {
t.strictEqual(response.body.hits.hits.length, 1) t.equal(response.body.hits.hits.length, 1)
count += 1 count += 1
} }
}) })

View File

@ -26,7 +26,7 @@ const { connection } = require('../../utils')
test('Search should have an additional documents property', async t => { test('Search should have an additional documents property', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=hits.hits._source') t.equal(params.querystring, 'filter_path=hits.hits._source')
return { return {
body: { body: {
hits: { hits: {
@ -50,7 +50,7 @@ test('Search should have an additional documents property', async t => {
index: 'test', index: 'test',
body: { foo: 'bar' } body: { foo: 'bar' }
}) })
t.deepEqual(result, [ t.same(result, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -60,7 +60,7 @@ test('Search should have an additional documents property', async t => {
test('kGetHits fallback', async t => { test('kGetHits fallback', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=hits.hits._source') t.equal(params.querystring, 'filter_path=hits.hits._source')
return { body: {} } return { body: {} }
} }
}) })
@ -74,13 +74,13 @@ test('kGetHits fallback', async t => {
index: 'test', index: 'test',
body: { foo: 'bar' } body: { foo: 'bar' }
}) })
t.deepEqual(result, []) t.same(result, [])
}) })
test('Merge filter paths (snake_case)', async t => { test('Merge filter paths (snake_case)', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=foo%2Chits.hits._source') t.equal(params.querystring, 'filter_path=foo%2Chits.hits._source')
return { return {
body: { body: {
hits: { hits: {
@ -105,7 +105,7 @@ test('Merge filter paths (snake_case)', async t => {
filter_path: 'foo', filter_path: 'foo',
body: { foo: 'bar' } body: { foo: 'bar' }
}) })
t.deepEqual(result, [ t.same(result, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }
@ -115,7 +115,7 @@ test('Merge filter paths (snake_case)', async t => {
test('Merge filter paths (camelCase)', async t => { test('Merge filter paths (camelCase)', async t => {
const MockConnection = connection.buildMockConnection({ const MockConnection = connection.buildMockConnection({
onRequest (params) { onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=foo%2Chits.hits._source') t.equal(params.querystring, 'filter_path=foo%2Chits.hits._source')
return { return {
body: { body: {
hits: { hits: {
@ -140,7 +140,7 @@ test('Merge filter paths (camelCase)', async t => {
filterPath: 'foo', filterPath: 'foo',
body: { foo: 'bar' } body: { foo: 'bar' }
}) })
t.deepEqual(result, [ t.same(result, [
{ one: 'one' }, { one: 'one' },
{ two: 'two' }, { two: 'two' },
{ three: 'three' } { three: 'three' }

View File

@ -28,7 +28,7 @@ test('RoundRobinSelector', t => {
t.plan(arr.length + 1) t.plan(arr.length + 1)
for (let i = 0; i <= arr.length; i++) { for (let i = 0; i <= arr.length; i++) {
t.strictEqual( t.equal(
selector(arr), selector(arr),
i === arr.length ? arr[0] : arr[i] i === arr.length ? arr[0] : arr[i]
) )

View File

@ -29,8 +29,8 @@ test('Basic', t => {
const s = new Serializer() const s = new Serializer()
const obj = { hello: 'world' } const obj = { hello: 'world' }
const json = JSON.stringify(obj) const json = JSON.stringify(obj)
t.strictEqual(s.serialize(obj), json) t.equal(s.serialize(obj), json)
t.deepEqual(s.deserialize(json), obj) t.same(s.deserialize(json), obj)
}) })
test('ndserialize', t => { test('ndserialize', t => {
@ -41,7 +41,7 @@ test('ndserialize', t => {
{ winter: 'is coming' }, { winter: 'is coming' },
{ you_know: 'for search' } { you_know: 'for search' }
] ]
t.strictEqual( t.equal(
s.ndserialize(obj), s.ndserialize(obj),
JSON.stringify(obj[0]) + '\n' + JSON.stringify(obj[0]) + '\n' +
JSON.stringify(obj[1]) + '\n' + JSON.stringify(obj[1]) + '\n' +
@ -57,7 +57,7 @@ test('ndserialize (strings)', t => {
JSON.stringify({ winter: 'is coming' }), JSON.stringify({ winter: 'is coming' }),
JSON.stringify({ you_know: 'for search' }) JSON.stringify({ you_know: 'for search' })
] ]
t.strictEqual( t.equal(
s.ndserialize(obj), s.ndserialize(obj),
obj[0] + '\n' + obj[0] + '\n' +
obj[1] + '\n' + obj[1] + '\n' +
@ -73,7 +73,7 @@ test('qserialize', t => {
you_know: 'for search' you_know: 'for search'
} }
t.strictEqual( t.equal(
s.qserialize(obj), s.qserialize(obj),
stringify(obj) stringify(obj)
) )
@ -87,7 +87,7 @@ test('qserialize (array)', t => {
arr: ['foo', 'bar'] arr: ['foo', 'bar']
} }
t.strictEqual( t.equal(
s.qserialize(obj), s.qserialize(obj),
'hello=world&arr=foo%2Cbar' 'hello=world&arr=foo%2Cbar'
) )
@ -101,7 +101,7 @@ test('qserialize (string)', t => {
you_know: 'for search' you_know: 'for search'
} }
t.strictEqual( t.equal(
s.qserialize(stringify(obj)), s.qserialize(stringify(obj)),
stringify(obj) stringify(obj)
) )
@ -116,7 +116,7 @@ test('qserialize (key with undefined value)', t => {
foo: 'bar' foo: 'bar'
} }
t.strictEqual( t.equal(
s.qserialize(obj), s.qserialize(obj),
'hello=world&foo=bar' 'hello=world&foo=bar'
) )

View File

@ -71,7 +71,7 @@ test('Basic', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -99,7 +99,7 @@ test('Basic (promises support)', t => {
path: '/hello' path: '/hello'
}) })
.then(({ body }) => { .then(({ body }) => {
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
.catch(t.fail) .catch(t.fail)
}) })
@ -154,7 +154,7 @@ test('Basic (options + promises support)', t => {
requestTimeout: 1000 requestTimeout: 1000
}) })
.then(({ body }) => { .then(({ body }) => {
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
.catch(t.fail) .catch(t.fail)
}) })
@ -171,7 +171,7 @@ test('Send POST', t => {
req.on('data', chunk => { json += chunk }) req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.deepEqual(JSON.parse(json), { hello: 'world' }) t.same(JSON.parse(json), { hello: 'world' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -197,7 +197,7 @@ test('Send POST', t => {
body: { hello: 'world' } body: { hello: 'world' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -222,7 +222,7 @@ test('Send POST (ndjson)', t => {
req.on('data', chunk => { json += chunk }) req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.strictEqual( t.equal(
json, json,
JSON.stringify(bulkBody[0]) + '\n' + JSON.stringify(bulkBody[0]) + '\n' +
JSON.stringify(bulkBody[1]) + '\n' + JSON.stringify(bulkBody[1]) + '\n' +
@ -253,7 +253,7 @@ test('Send POST (ndjson)', t => {
bulkBody bulkBody
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -270,7 +270,7 @@ test('Send stream', t => {
req.on('data', chunk => { json += chunk }) req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.deepEqual(JSON.parse(json), { hello: 'world' }) t.same(JSON.parse(json), { hello: 'world' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -296,7 +296,7 @@ test('Send stream', t => {
body: intoStream(JSON.stringify({ hello: 'world' })) body: intoStream(JSON.stringify({ hello: 'world' }))
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -313,7 +313,7 @@ test('Send stream (bulkBody)', t => {
req.on('data', chunk => { json += chunk }) req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err)) req.on('error', err => t.fail(err))
req.on('end', () => { req.on('end', () => {
t.deepEqual(JSON.parse(json), { hello: 'world' }) t.same(JSON.parse(json), { hello: 'world' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
}) })
@ -339,7 +339,7 @@ test('Send stream (bulkBody)', t => {
bulkBody: intoStream(JSON.stringify({ hello: 'world' })) bulkBody: intoStream(JSON.stringify({ hello: 'world' }))
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -371,7 +371,7 @@ test('Not JSON payload from server', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.strictEqual(body, 'hello!') t.equal(body, 'hello!')
server.stop() server.stop()
}) })
}) })
@ -391,8 +391,8 @@ test('NoLivingConnectionsError (null connection)', t => {
sniffInterval: false, sniffInterval: false,
sniffOnStart: false, sniffOnStart: false,
nodeSelector (connections) { nodeSelector (connections) {
t.is(connections.length, 1) t.equal(connections.length, 1)
t.true(connections[0] instanceof Connection) t.ok(connections[0] instanceof Connection)
return null return null
} }
}) })
@ -419,8 +419,8 @@ test('NoLivingConnectionsError (undefined connection)', t => {
sniffInterval: false, sniffInterval: false,
sniffOnStart: false, sniffOnStart: false,
nodeSelector (connections) { nodeSelector (connections) {
t.is(connections.length, 1) t.equal(connections.length, 1)
t.true(connections[0] instanceof Connection) t.ok(connections[0] instanceof Connection)
return undefined return undefined
} }
}) })
@ -521,7 +521,7 @@ test('TimeoutError (should call markDead on the failing connection)', t => {
class CustomConnectionPool extends ConnectionPool { class CustomConnectionPool extends ConnectionPool {
markDead (connection) { markDead (connection) {
t.strictEqual(connection.id, 'node1') t.equal(connection.id, 'node1')
super.markDead(connection) super.markDead(connection)
} }
} }
@ -555,7 +555,7 @@ test('ConnectionError (should call markDead on the failing connection)', t => {
class CustomConnectionPool extends ConnectionPool { class CustomConnectionPool extends ConnectionPool {
markDead (connection) { markDead (connection) {
t.strictEqual(connection.id, 'node1') t.equal(connection.id, 'node1')
super.markDead(connection) super.markDead(connection)
} }
} }
@ -626,7 +626,7 @@ test('Retry mechanism', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -671,7 +671,7 @@ test('Should not retry if the body is a stream', t => {
body: intoStream(JSON.stringify({ hello: 'world' })) body: intoStream(JSON.stringify({ hello: 'world' }))
}, (err, { body }) => { }, (err, { body }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(count, 1) t.equal(count, 1)
server.stop() server.stop()
}) })
}) })
@ -716,7 +716,7 @@ test('Should not retry if the bulkBody is a stream', t => {
bulkBody: intoStream(JSON.stringify([{ hello: 'world' }])) bulkBody: intoStream(JSON.stringify([{ hello: 'world' }]))
}, (err, { body }) => { }, (err, { body }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(count, 1) t.equal(count, 1)
server.stop() server.stop()
}) })
}) })
@ -763,7 +763,7 @@ test('No retry', t => {
maxRetries: 0 maxRetries: 0
}, (err, { body }) => { }, (err, { body }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.strictEqual(count, 1) t.equal(count, 1)
server.stop() server.stop()
}) })
}) })
@ -813,7 +813,7 @@ test('Custom retry mechanism', t => {
maxRetries: 1 maxRetries: 1
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -824,7 +824,7 @@ test('Should not retry on 429', t => {
let count = 0 let count = 0
function handler (req, res) { function handler (req, res) {
t.strictEqual(count++, 0) t.equal(count++, 0)
res.statusCode = 429 res.statusCode = 429
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
@ -858,7 +858,7 @@ test('Should not retry on 429', t => {
path: '/hello' path: '/hello'
}, (err, result) => { }, (err, result) => {
t.ok(err) t.ok(err)
t.strictEqual(err.statusCode, 429) t.equal(err.statusCode, 429)
server.stop() server.stop()
}) })
}) })
@ -869,7 +869,7 @@ test('Should call markAlive with a successful response', t => {
class CustomConnectionPool extends ConnectionPool { class CustomConnectionPool extends ConnectionPool {
markAlive (connection) { markAlive (connection) {
t.strictEqual(connection.id, 'node1') t.equal(connection.id, 'node1')
super.markAlive(connection) super.markAlive(connection)
} }
} }
@ -895,7 +895,7 @@ test('Should call markAlive with a successful response', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
}) })
@ -932,7 +932,7 @@ test('Should call resurrect on every request', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
}) })
@ -1076,8 +1076,8 @@ test('ResponseError', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.deepEqual(err.body, { status: 500 }) t.same(err.body, { status: 500 })
t.strictEqual(err.statusCode, 500) t.equal(err.statusCode, 500)
server.stop() server.stop()
}) })
}) })
@ -1113,7 +1113,7 @@ test('Override requestTimeout', t => {
requestTimeout: 2000 requestTimeout: 2000
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1125,7 +1125,7 @@ test('sniff', t => {
class MyTransport extends Transport { class MyTransport extends Transport {
sniff (opts) { sniff (opts) {
t.strictEqual(opts.reason, Transport.sniffReasons.SNIFF_ON_START) t.equal(opts.reason, Transport.sniffReasons.SNIFF_ON_START)
} }
} }
@ -1150,7 +1150,7 @@ test('sniff', t => {
class MyTransport extends Transport { class MyTransport extends Transport {
sniff (opts) { sniff (opts) {
t.strictEqual(opts.reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT) t.equal(opts.reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT)
} }
} }
@ -1184,7 +1184,7 @@ test('sniff', t => {
class MyTransport extends Transport { class MyTransport extends Transport {
sniff (opts) { sniff (opts) {
t.strictEqual(opts.reason, Transport.sniffReasons.SNIFF_INTERVAL) t.equal(opts.reason, Transport.sniffReasons.SNIFF_INTERVAL)
} }
} }
@ -1329,7 +1329,7 @@ test('Should retry the request if the statusCode is 502/3/4', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1362,7 +1362,7 @@ test('Ignore status code', t => {
ignore: [404] ignore: [404]
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
transport.request({ transport.request({
@ -1386,7 +1386,7 @@ test('Should serialize the querystring', t => {
t.plan(2) t.plan(2)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello?hello=world&you_know=for%20search') t.equal(req.url, '/hello?hello=world&you_know=for%20search')
res.end('ok') res.end('ok')
} }
@ -1582,8 +1582,8 @@ test('Should cast to boolean HEAD request', t => {
path: '/200' path: '/200'
}, (err, { body, statusCode }) => { }, (err, { body, statusCode }) => {
t.error(err) t.error(err)
t.strictEqual(statusCode, 200) t.equal(statusCode, 200)
t.strictEqual(body, true) t.equal(body, true)
}) })
}) })
@ -1607,8 +1607,8 @@ test('Should cast to boolean HEAD request', t => {
path: '/404' path: '/404'
}, (err, { body, statusCode }) => { }, (err, { body, statusCode }) => {
t.error(err) t.error(err)
t.strictEqual(statusCode, 404) t.equal(statusCode, 404)
t.strictEqual(body, false) t.equal(body, false)
}) })
}) })
@ -1633,8 +1633,8 @@ test('Should cast to boolean HEAD request', t => {
path: '/400' path: '/400'
}, (err, { body, statusCode }) => { }, (err, { body, statusCode }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.false(typeof err.body === 'boolean') t.notOk(typeof err.body === 'boolean')
t.strictEqual(statusCode, 400) t.equal(statusCode, 400)
}) })
}) })
@ -1658,8 +1658,8 @@ test('Should cast to boolean HEAD request', t => {
path: '/500' path: '/500'
}, (err, { body, statusCode }) => { }, (err, { body, statusCode }) => {
t.ok(err instanceof ResponseError) t.ok(err instanceof ResponseError)
t.false(typeof err.body === 'boolean') t.notOk(typeof err.body === 'boolean')
t.strictEqual(statusCode, 500) t.equal(statusCode, 500)
}) })
}) })
@ -1700,7 +1700,7 @@ test('Suggest compression', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1775,7 +1775,7 @@ test('Warning header', t => {
path: '/hello' path: '/hello'
}, (err, { warnings }) => { }, (err, { warnings }) => {
t.error(err) t.error(err)
t.deepEqual(warnings, [warn]) t.same(warnings, [warn])
warnings.forEach(w => t.type(w, 'string')) warnings.forEach(w => t.type(w, 'string'))
server.stop() server.stop()
}) })
@ -1812,7 +1812,7 @@ test('Warning header', t => {
path: '/hello' path: '/hello'
}, (err, { warnings }) => { }, (err, { warnings }) => {
t.error(err) t.error(err)
t.deepEqual(warnings, [warn1, warn2]) t.same(warnings, [warn1, warn2])
warnings.forEach(w => t.type(w, 'string')) warnings.forEach(w => t.type(w, 'string'))
server.stop() server.stop()
}) })
@ -1846,7 +1846,7 @@ test('Warning header', t => {
path: '/hello' path: '/hello'
}, (err, { warnings }) => { }, (err, { warnings }) => {
t.error(err) t.error(err)
t.strictEqual(warnings, null) t.equal(warnings, null)
server.stop() server.stop()
}) })
}) })
@ -1893,7 +1893,7 @@ test('asStream set to true', t => {
body.on('data', chunk => { payload += chunk }) body.on('data', chunk => { payload += chunk })
body.on('error', err => t.fail(err)) body.on('error', err => t.fail(err))
body.on('end', () => { body.on('end', () => {
t.deepEqual(JSON.parse(payload), { hello: 'world' }) t.same(JSON.parse(payload), { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -1914,7 +1914,7 @@ test('Compress request', t => {
.on('data', chunk => { json += chunk }) .on('data', chunk => { json += chunk })
.on('error', err => t.fail(err)) .on('error', err => t.fail(err))
.on('end', () => { .on('end', () => {
t.deepEqual(JSON.parse(json), { you_know: 'for search' }) t.same(JSON.parse(json), { you_know: 'for search' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ you_know: 'for search' })) res.end(JSON.stringify({ you_know: 'for search' }))
}) })
@ -1942,7 +1942,7 @@ test('Compress request', t => {
compression: 'gzip' compression: 'gzip'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { you_know: 'for search' }) t.same(body, { you_know: 'for search' })
server.stop() server.stop()
}) })
}) })
@ -1961,7 +1961,7 @@ test('Compress request', t => {
.on('data', chunk => { json += chunk }) .on('data', chunk => { json += chunk })
.on('error', err => t.fail(err)) .on('error', err => t.fail(err))
.on('end', () => { .on('end', () => {
t.deepEqual(JSON.parse(json), { you_know: 'for search' }) t.same(JSON.parse(json), { you_know: 'for search' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ you_know: 'for search' })) res.end(JSON.stringify({ you_know: 'for search' }))
}) })
@ -1988,7 +1988,7 @@ test('Compress request', t => {
body: { you_know: 'for search' } body: { you_know: 'for search' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { you_know: 'for search' }) t.same(body, { you_know: 'for search' })
server.stop() server.stop()
}) })
}) })
@ -2007,7 +2007,7 @@ test('Compress request', t => {
.on('data', chunk => { json += chunk }) .on('data', chunk => { json += chunk })
.on('error', err => t.fail(err)) .on('error', err => t.fail(err))
.on('end', () => { .on('end', () => {
t.deepEqual(JSON.parse(json), { you_know: 'for search' }) t.same(JSON.parse(json), { you_know: 'for search' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ you_know: 'for search' })) res.end(JSON.stringify({ you_know: 'for search' }))
}) })
@ -2035,7 +2035,7 @@ test('Compress request', t => {
compression: 'gzip' compression: 'gzip'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { you_know: 'for search' }) t.same(body, { you_know: 'for search' })
server.stop() server.stop()
}) })
}) })
@ -2057,8 +2057,8 @@ test('Compress request', t => {
}) })
t.fail('Should throw') t.fail('Should throw')
} catch (err) { } catch (err) {
t.true(err instanceof ConfigurationError) t.ok(err instanceof ConfigurationError)
t.is(err.message, 'Invalid compression: \'deflate\'') t.equal(err.message, 'Invalid compression: \'deflate\'')
} }
}) })
@ -2066,8 +2066,8 @@ test('Compress request', t => {
t.plan(9) t.plan(9)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.headers['content-encoding'], undefined) t.equal(req.headers['content-encoding'], undefined)
t.strictEqual(req.headers['content-type'], undefined) t.equal(req.headers['content-type'], undefined)
res.end() res.end()
} }
@ -2126,7 +2126,7 @@ test('Compress request', t => {
.on('data', chunk => { json += chunk }) .on('data', chunk => { json += chunk })
.on('error', err => t.fail(err)) .on('error', err => t.fail(err))
.on('end', () => { .on('end', () => {
t.deepEqual(JSON.parse(json), { you_know: 'for search' }) t.same(JSON.parse(json), { you_know: 'for search' })
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
if (count++ > 0) { if (count++ > 0) {
res.end(JSON.stringify({ you_know: 'for search' })) res.end(JSON.stringify({ you_know: 'for search' }))
@ -2160,8 +2160,8 @@ test('Compress request', t => {
compression: 'gzip' compression: 'gzip'
}, (err, { body, meta }) => { }, (err, { body, meta }) => {
t.error(err) t.error(err)
t.deepEqual(body, { you_know: 'for search' }) t.same(body, { you_know: 'for search' })
t.strictEqual(count, 2) t.equal(count, 2)
server.stop() server.stop()
}) })
}) })
@ -2201,7 +2201,7 @@ test('Headers configuration', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -2242,7 +2242,7 @@ test('Headers configuration', t => {
headers: { 'x-baz': 'faz' } headers: { 'x-baz': 'faz' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -2280,7 +2280,7 @@ test('Headers configuration', t => {
headers: { 'x-foo': 'faz' } headers: { 'x-foo': 'faz' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -2318,7 +2318,7 @@ test('nodeFilter and nodeSelector', t => {
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
}) })
}) })
@ -2327,7 +2327,7 @@ test('Should accept custom querystring in the optons object', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello?foo=bar') t.equal(req.url, '/hello?foo=bar')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -2353,7 +2353,7 @@ test('Should accept custom querystring in the optons object', t => {
querystring: { foo: 'bar' } querystring: { foo: 'bar' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -2363,7 +2363,7 @@ test('Should accept custom querystring in the optons object', t => {
t.plan(3) t.plan(3)
function handler (req, res) { function handler (req, res) {
t.strictEqual(req.url, '/hello?baz=faz&foo=bar') t.equal(req.url, '/hello?baz=faz&foo=bar')
res.setHeader('Content-Type', 'application/json;utf=8') res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' })) res.end(JSON.stringify({ hello: 'world' }))
} }
@ -2390,7 +2390,7 @@ test('Should accept custom querystring in the optons object', t => {
querystring: { foo: 'bar' } querystring: { foo: 'bar' }
}, (err, { body }) => { }, (err, { body }) => {
t.error(err) t.error(err)
t.deepEqual(body, { hello: 'world' }) t.same(body, { hello: 'world' })
server.stop() server.stop()
}) })
}) })
@ -2454,8 +2454,8 @@ test('Should pass request params and options to generateRequestId', t => {
sniffInterval: false, sniffInterval: false,
sniffOnStart: false, sniffOnStart: false,
generateRequestId: function (requestParams, requestOptions) { generateRequestId: function (requestParams, requestOptions) {
t.deepEqual(requestParams, params) t.same(requestParams, params)
t.deepEqual(requestOptions, options) t.same(requestOptions, options)
return 'id' return 'id'
} }
}) })
@ -2489,8 +2489,8 @@ test('Secure json parsing', t => {
method: 'GET', method: 'GET',
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.true(err instanceof DeserializationError) t.ok(err instanceof DeserializationError)
t.is(err.message, 'Object contains forbidden prototype property') t.equal(err.message, 'Object contains forbidden prototype property')
server.stop() server.stop()
}) })
}) })
@ -2521,8 +2521,8 @@ test('Secure json parsing', t => {
method: 'GET', method: 'GET',
path: '/hello' path: '/hello'
}, (err, { body }) => { }, (err, { body }) => {
t.true(err instanceof DeserializationError) t.ok(err instanceof DeserializationError)
t.is(err.message, 'Object contains forbidden prototype property') t.equal(err.message, 'Object contains forbidden prototype property')
server.stop() server.stop()
}) })
}) })
@ -2535,7 +2535,7 @@ test('Lowercase headers utilty', t => {
t.plan(4) t.plan(4)
const { lowerCaseHeaders } = Transport.internals const { lowerCaseHeaders } = Transport.internals
t.deepEqual(lowerCaseHeaders({ t.same(lowerCaseHeaders({
Foo: 'bar', Foo: 'bar',
Faz: 'baz', Faz: 'baz',
'X-Hello': 'world' 'X-Hello': 'world'
@ -2545,7 +2545,7 @@ test('Lowercase headers utilty', t => {
'x-hello': 'world' 'x-hello': 'world'
}) })
t.deepEqual(lowerCaseHeaders({ t.same(lowerCaseHeaders({
Foo: 'bar', Foo: 'bar',
faz: 'baz', faz: 'baz',
'X-hello': 'world' 'X-hello': 'world'
@ -2555,9 +2555,9 @@ test('Lowercase headers utilty', t => {
'x-hello': 'world' 'x-hello': 'world'
}) })
t.strictEqual(lowerCaseHeaders(null), null) t.equal(lowerCaseHeaders(null), null)
t.strictEqual(lowerCaseHeaders(undefined), undefined) t.equal(lowerCaseHeaders(undefined), undefined)
}) })
test('The callback with a sync error should be called in the next tick - json', t => { test('The callback with a sync error should be called in the next tick - json', t => {