Updated test

This commit is contained in:
delvedor
2018-12-10 20:14:51 +01:00
parent a9e621721e
commit 230b08ab86
5 changed files with 264 additions and 9 deletions

View File

@ -2,7 +2,8 @@
const { test } = require('tap')
const { URL } = require('url')
const { Client } = require('../../index')
const { Client, ConnectionPool } = require('../../index')
const { buildServer } = require('../utils')
test('Configure host', t => {
t.test('Single string', t => {
@ -165,3 +166,64 @@ test('Configure host', t => {
t.end()
})
test('Node with auth data in the url', t => {
t.plan(3)
function handler (req, res) {
t.match(req.headers, {
authorization: 'Basic Zm9vOmJhcg=='
})
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://foo:bar@localhost:${port}`
})
client.info((err, { body }) => {
t.error(err)
t.deepEqual(body, { hello: 'world' })
server.stop()
})
})
})
test('Client close', t => {
t.plan(2)
class MyConnectionPool extends ConnectionPool {
empty () {
t.ok('called')
super.empty()
}
}
const client = new Client({
node: 'http://localhost:9200',
ConnectionPool: MyConnectionPool
})
client.close(() => t.pass('Closed'))
})
test('Client close (promise)', t => {
t.plan(2)
class MyConnectionPool extends ConnectionPool {
empty () {
t.ok('called')
super.empty()
}
}
const client = new Client({
node: 'http://localhost:9200',
ConnectionPool: MyConnectionPool
})
client.close()
.then(() => t.pass('Closed'))
})