Updated test
This commit is contained in:
@ -79,7 +79,7 @@ test('Configure host', t => {
|
||||
})
|
||||
const pool = client[kConnectionPool]
|
||||
t.match(pool.connections.get('node'), {
|
||||
url: new URL('http://user@passwordlocalhost:9200'),
|
||||
url: new URL('http://localhost:9200'),
|
||||
id: 'node',
|
||||
ssl: 'ssl',
|
||||
deadCount: 0,
|
||||
@ -114,7 +114,7 @@ test('Configure host', t => {
|
||||
})
|
||||
const pool = client[kConnectionPool]
|
||||
t.match(pool.connections.get('node1'), {
|
||||
url: new URL('http://user@passwordlocalhost:9200'),
|
||||
url: new URL('http://localhost:9200'),
|
||||
id: 'node1',
|
||||
ssl: 'ssl',
|
||||
deadCount: 0,
|
||||
@ -125,7 +125,7 @@ test('Configure host', t => {
|
||||
}
|
||||
})
|
||||
t.match(pool.connections.get('node2'), {
|
||||
url: new URL('http://user@passwordlocalhost:9200'),
|
||||
url: new URL('http://localhost:9200'),
|
||||
id: 'node2',
|
||||
ssl: 'ssl',
|
||||
deadCount: 0,
|
||||
@ -148,7 +148,7 @@ test('Configure host', t => {
|
||||
})
|
||||
const pool = client[kConnectionPool]
|
||||
t.match(pool.connections.get('node'), {
|
||||
url: new URL('http://user@passwordlocalhost:9200'),
|
||||
url: new URL('http://localhost:9200'),
|
||||
headers: { 'x-foo': 'bar' }
|
||||
})
|
||||
t.end()
|
||||
|
||||
@ -463,3 +463,34 @@ test('Custom headers for connection', t => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: add a check that the response is not decompressed
|
||||
test('asStream set to true', t => {
|
||||
t.plan(2)
|
||||
|
||||
function handler (req, res) {
|
||||
res.end('ok')
|
||||
}
|
||||
|
||||
buildServer(handler, ({ port }, server) => {
|
||||
const connection = new Connection({
|
||||
url: new URL(`http://localhost:${port}`)
|
||||
})
|
||||
connection.request({
|
||||
path: '/hello',
|
||||
method: 'GET',
|
||||
asStream: true
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
|
||||
var payload = ''
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', chunk => { payload += chunk })
|
||||
res.on('error', err => t.fail(err))
|
||||
res.on('end', () => {
|
||||
t.strictEqual(payload, 'ok')
|
||||
server.stop()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1376,7 +1376,7 @@ test('Warning header', t => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('asHttpResponse enabled', t => {
|
||||
test('asStream set to true', t => {
|
||||
t.plan(3)
|
||||
function handler (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;utf=8')
|
||||
@ -1400,19 +1400,19 @@ test('asHttpResponse enabled', t => {
|
||||
transport.request({
|
||||
method: 'GET',
|
||||
path: '/hello',
|
||||
asHttpResponse: true
|
||||
}, (err, response) => {
|
||||
asStream: true
|
||||
}, (err, { body, headers }) => {
|
||||
t.error(err)
|
||||
t.match(response.headers, {
|
||||
t.match(headers, {
|
||||
connection: 'keep-alive',
|
||||
'content-type': 'application/json;utf=8'
|
||||
})
|
||||
|
||||
var payload = ''
|
||||
response.setEncoding('utf8')
|
||||
response.on('data', chunk => { payload += chunk })
|
||||
response.on('error', err => t.fail(err))
|
||||
response.on('end', () => {
|
||||
body.setEncoding('utf8')
|
||||
body.on('data', chunk => { payload += chunk })
|
||||
body.on('error', err => t.fail(err))
|
||||
body.on('end', () => {
|
||||
t.deepEqual(JSON.parse(payload), { hello: 'world' })
|
||||
server.stop()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user