Added x-elastic-client-meta header (#1373)
This commit is contained in:
committed by
GitHub
parent
4cace4c234
commit
61eee69424
@ -26,6 +26,8 @@ const intoStream = require('into-stream')
|
||||
const { Client, ConnectionPool, Transport, Connection, errors } = require('../../index')
|
||||
const { CloudConnectionPool } = require('../../lib/pool')
|
||||
const { buildServer } = require('../utils')
|
||||
const clientVersion = require('../../package.json').version
|
||||
const nodeVersion = process.versions.node
|
||||
|
||||
test('Configure host', t => {
|
||||
t.test('Single string', t => {
|
||||
@ -1300,3 +1302,62 @@ test('Content length too big (string)', t => {
|
||||
t.strictEqual(result.meta.attempts, 0)
|
||||
})
|
||||
})
|
||||
|
||||
test('Meta header enabled', t => {
|
||||
t.plan(2)
|
||||
|
||||
class MockConnection extends Connection {
|
||||
request (params, callback) {
|
||||
t.match(params.headers, { 'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}` })
|
||||
const stream = intoStream(JSON.stringify({ hello: 'world' }))
|
||||
stream.statusCode = 200
|
||||
stream.headers = {
|
||||
'content-type': 'application/json;utf=8',
|
||||
'content-length': '17',
|
||||
connection: 'keep-alive',
|
||||
date: new Date().toISOString()
|
||||
}
|
||||
process.nextTick(callback, null, stream)
|
||||
return { abort () {} }
|
||||
}
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
})
|
||||
|
||||
client.info((err, result) => {
|
||||
t.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
test('Meta header disabled', t => {
|
||||
t.plan(2)
|
||||
|
||||
class MockConnection extends Connection {
|
||||
request (params, callback) {
|
||||
t.notMatch(params.headers, { 'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}` })
|
||||
const stream = intoStream(JSON.stringify({ hello: 'world' }))
|
||||
stream.statusCode = 200
|
||||
stream.headers = {
|
||||
'content-type': 'application/json;utf=8',
|
||||
'content-length': '17',
|
||||
connection: 'keep-alive',
|
||||
date: new Date().toISOString()
|
||||
}
|
||||
process.nextTick(callback, null, stream)
|
||||
return { abort () {} }
|
||||
}
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection,
|
||||
enableMetaHeader: false
|
||||
})
|
||||
|
||||
client.info((err, result) => {
|
||||
t.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
@ -27,6 +27,8 @@ const semver = require('semver')
|
||||
const { test } = require('tap')
|
||||
const { Client, errors } = require('../../../')
|
||||
const { buildServer, connection } = require('../../utils')
|
||||
const clientVersion = require('../../../package.json').version
|
||||
const nodeVersion = process.versions.node
|
||||
|
||||
const dataset = [
|
||||
{ user: 'jon', age: 23 },
|
||||
@ -41,7 +43,10 @@ test('bulk index', t => {
|
||||
const MockConnection = connection.buildMockConnection({
|
||||
onRequest (params) {
|
||||
t.strictEqual(params.path, '/_bulk')
|
||||
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
|
||||
t.match(params.headers, {
|
||||
'content-type': 'application/x-ndjson',
|
||||
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp`
|
||||
})
|
||||
const [action, payload] = params.body.split('\n')
|
||||
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } })
|
||||
t.deepEqual(JSON.parse(payload), dataset[count++])
|
||||
@ -84,6 +89,9 @@ test('bulk index', t => {
|
||||
onRequest (params) {
|
||||
t.strictEqual(params.path, '/_bulk')
|
||||
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
|
||||
t.notMatch(params.headers, {
|
||||
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=bp`
|
||||
})
|
||||
const [action, payload] = params.body.split('\n')
|
||||
t.deepEqual(JSON.parse(action), { index: { _index: 'test' } })
|
||||
t.deepEqual(JSON.parse(payload), dataset[count++])
|
||||
@ -93,7 +101,8 @@ test('bulk index', t => {
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
Connection: MockConnection,
|
||||
enableMetaHeader: false
|
||||
})
|
||||
const result = await client.helpers.bulk({
|
||||
datasource: dataset.slice(),
|
||||
|
||||
@ -22,11 +22,17 @@
|
||||
const { test } = require('tap')
|
||||
const { Client, errors } = require('../../../')
|
||||
const { connection } = require('../../utils')
|
||||
const clientVersion = require('../../../package.json').version
|
||||
const nodeVersion = process.versions.node
|
||||
|
||||
test('Scroll search', async t => {
|
||||
var count = 0
|
||||
const MockConnection = connection.buildMockConnection({
|
||||
onRequest (params) {
|
||||
t.match(params.headers, {
|
||||
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=s`
|
||||
})
|
||||
|
||||
count += 1
|
||||
if (params.method === 'POST') {
|
||||
t.strictEqual(params.querystring, 'scroll=1m')
|
||||
@ -73,6 +79,9 @@ test('Clear a scroll search', async t => {
|
||||
var count = 0
|
||||
const MockConnection = connection.buildMockConnection({
|
||||
onRequest (params) {
|
||||
t.notMatch(params.headers, {
|
||||
'x-elastic-client-meta': `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion},h=s`
|
||||
})
|
||||
if (params.method === 'DELETE') {
|
||||
const body = JSON.parse(params.body)
|
||||
t.strictEqual(body.scroll_id, 'id')
|
||||
@ -95,7 +104,8 @@ test('Clear a scroll search', async t => {
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
Connection: MockConnection,
|
||||
enableMetaHeader: false
|
||||
})
|
||||
|
||||
const scrollSearch = client.helpers.scrollSearch({
|
||||
|
||||
Reference in New Issue
Block a user