[Backport 7.x] Allow the client name to be a symbol (#1257)
Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0dd5c3c186
commit
28f2be397c
@ -205,7 +205,7 @@ test('Client name', t => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
t.test('Is present in the event metadata', t => {
|
||||
t.test('Is present in the event metadata (as string)', t => {
|
||||
t.plan(6)
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
@ -229,6 +229,31 @@ test('Client name', t => {
|
||||
})
|
||||
})
|
||||
|
||||
t.test('Is present in the event metadata (as symbol)', t => {
|
||||
t.plan(6)
|
||||
const symbol = Symbol('cluster')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection,
|
||||
name: symbol
|
||||
})
|
||||
|
||||
client.on('request', (err, { meta }) => {
|
||||
t.error(err)
|
||||
t.strictEqual(meta.name, symbol)
|
||||
})
|
||||
|
||||
client.on('response', (err, { meta }) => {
|
||||
t.error(err)
|
||||
t.strictEqual(meta.name, symbol)
|
||||
})
|
||||
|
||||
client.info((err, { meta }) => {
|
||||
t.error(err)
|
||||
t.strictEqual(meta.name, symbol)
|
||||
})
|
||||
})
|
||||
|
||||
t.test('Sniff and client name', t => {
|
||||
t.test('sniffOnStart', t => {
|
||||
t.plan(2)
|
||||
|
||||
@ -300,6 +300,13 @@ expectType<Client>(
|
||||
})
|
||||
)
|
||||
|
||||
expectType<Client>(
|
||||
new Client({
|
||||
node: 'http://localhost:9200',
|
||||
name: Symbol('foo')
|
||||
})
|
||||
)
|
||||
|
||||
expectError<errors.ConfigurationError>(
|
||||
new Client({
|
||||
node: 'http://localhost:9200',
|
||||
|
||||
@ -1092,3 +1092,26 @@ test('Random selector', t => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('name property as string', t => {
|
||||
t.plan(1)
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
name: 'client-name'
|
||||
})
|
||||
|
||||
t.strictEqual(client.name, 'client-name')
|
||||
})
|
||||
|
||||
test('name property as symbol', t => {
|
||||
t.plan(1)
|
||||
|
||||
const symbol = Symbol('client-name')
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
name: symbol
|
||||
})
|
||||
|
||||
t.strictEqual(client.name, symbol)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user