Verify connection to Elasticsearch (#1487)

This commit is contained in:
Tomas Della Vedova
2021-07-19 16:42:04 +02:00
committed by GitHub
parent 76f5845ac1
commit 17c744ed80
24 changed files with 1456 additions and 106 deletions

View File

@ -133,7 +133,7 @@ function buildMockConnection (opts) {
class MockConnection extends Connection {
request (params, callback) {
let { body, statusCode } = opts.onRequest(params)
let { body, statusCode, headers } = opts.onRequest(params)
if (typeof body !== 'string') {
body = JSON.stringify(body)
}
@ -144,7 +144,8 @@ function buildMockConnection (opts) {
'content-type': 'application/json;utf=8',
date: new Date().toISOString(),
connection: 'keep-alive',
'content-length': Buffer.byteLength(body)
'content-length': Buffer.byteLength(body),
...headers
}
process.nextTick(() => {
if (!aborted) {

View File

@ -25,6 +25,7 @@ const buildServer = require('./buildServer')
const buildCluster = require('./buildCluster')
const buildProxy = require('./buildProxy')
const connection = require('./MockConnection')
const { Client } = require('../../')
async function waitCluster (client, waitForStatus = 'green', timeout = '50s', times = 0) {
if (!client) {
@ -41,10 +42,25 @@ async function waitCluster (client, waitForStatus = 'green', timeout = '50s', ti
}
}
function skipProductCheck (client) {
const tSymbol = Object.getOwnPropertySymbols(client.transport || client)
.filter(symbol => symbol.description === 'product check')[0]
;(client.transport || client)[tSymbol] = 2
}
class NoProductCheckClient extends Client {
constructor (opts) {
super(opts)
skipProductCheck(this)
}
}
module.exports = {
buildServer,
buildCluster,
buildProxy,
connection,
waitCluster
waitCluster,
skipProductCheck,
Client: NoProductCheckClient
}