Add support for a global context option (#1256)

This commit is contained in:
Tomas Della Vedova
2020-07-13 14:36:53 +02:00
committed by GitHub
parent 1a7727588e
commit 39cf023426
16 changed files with 2971 additions and 2851 deletions

View File

@ -192,6 +192,50 @@ test('Request context', t => {
client.info({}, { context: { winter: 'is coming' } }, t.error)
})
t.test('global value', t => {
t.plan(5)
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection,
context: { winter: 'is coming' }
})
client.on('request', (err, { meta }) => {
t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' })
})
client.on('response', (err, { meta }) => {
t.error(err)
t.deepEqual(meta.context, { winter: 'is coming' })
})
client.info(t.error)
})
t.test('override global', t => {
t.plan(5)
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection,
context: { winter: 'is coming' }
})
client.on('request', (err, { meta }) => {
t.error(err)
t.deepEqual(meta.context, { winter: 'has come' })
})
client.on('response', (err, { meta }) => {
t.error(err)
t.deepEqual(meta.context, { winter: 'has come' })
})
client.info({}, { context: { winter: 'has come' } }, t.error)
})
t.end()
})