Updated test
This commit is contained in:
@ -46,7 +46,7 @@ Runner.prototype.start = function () {
|
|||||||
client.info((err, { body }) => {
|
client.info((err, { body }) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.log.fail(err.message)
|
this.log.fail(err.message)
|
||||||
return
|
process.exit(1)
|
||||||
}
|
}
|
||||||
const { number: version, build_hash: sha } = body.version
|
const { number: version, build_hash: sha } = body.version
|
||||||
|
|
||||||
|
|||||||
@ -252,7 +252,8 @@ TestRunner.prototype.set = function (key, name) {
|
|||||||
TestRunner.prototype.do = function (action, done) {
|
TestRunner.prototype.do = function (action, done) {
|
||||||
const cmd = this.parseDo(action)
|
const cmd = this.parseDo(action)
|
||||||
const api = delve(this.client, cmd.method).bind(this.client)
|
const api = delve(this.client, cmd.method).bind(this.client)
|
||||||
api(cmd.params, (err, { body, warnings }) => {
|
const options = { ignore: cmd.params.ignore }
|
||||||
|
api(cmd.params, options, (err, { body, warnings }) => {
|
||||||
if (action.warnings && warnings === null) {
|
if (action.warnings && warnings === null) {
|
||||||
this.tap.fail('We should get a warning header', action.warnings)
|
this.tap.fail('We should get a warning header', action.warnings)
|
||||||
} else if (!action.warnings && warnings !== null) {
|
} else if (!action.warnings && warnings !== null) {
|
||||||
|
|||||||
@ -26,6 +26,18 @@ client.index({
|
|||||||
body: { hello: 'world' }
|
body: { hello: 'world' }
|
||||||
}, (err: Error | null, result: ApiResponse) => {})
|
}, (err: Error | null, result: ApiResponse) => {})
|
||||||
|
|
||||||
|
// request options
|
||||||
|
client.index({
|
||||||
|
index: 'test',
|
||||||
|
type: 'test',
|
||||||
|
id: 'test',
|
||||||
|
body: { hello: 'world' }
|
||||||
|
}, {
|
||||||
|
maxRetries: 2,
|
||||||
|
ignore: [404],
|
||||||
|
requestTimeout: 2000
|
||||||
|
}, (err: Error | null, result: ApiResponse) => {})
|
||||||
|
|
||||||
// Promises
|
// Promises
|
||||||
client.info()
|
client.info()
|
||||||
.then((result: ApiResponse) => {})
|
.then((result: ApiResponse) => {})
|
||||||
@ -39,3 +51,17 @@ client.index({
|
|||||||
})
|
})
|
||||||
.then((result: ApiResponse) => {})
|
.then((result: ApiResponse) => {})
|
||||||
.catch((err: Error) => {})
|
.catch((err: Error) => {})
|
||||||
|
|
||||||
|
// request options
|
||||||
|
client.index({
|
||||||
|
index: 'test',
|
||||||
|
type: 'test',
|
||||||
|
id: 'test',
|
||||||
|
body: { hello: 'world' }
|
||||||
|
}, {
|
||||||
|
maxRetries: 2,
|
||||||
|
ignore: [404],
|
||||||
|
requestTimeout: 2000
|
||||||
|
})
|
||||||
|
.then((result: ApiResponse) => {})
|
||||||
|
.catch((err: Error) => {})
|
||||||
|
|||||||
@ -165,3 +165,59 @@ test('Abort is not supported in promises', t => {
|
|||||||
t.type(request.abort, 'undefined')
|
t.type(request.abort, 'undefined')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Basic (options and callback)', t => {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
function handler (req, res) {
|
||||||
|
res.setHeader('Content-Type', 'application/json;utf=8')
|
||||||
|
res.end(JSON.stringify({ hello: 'world' }))
|
||||||
|
}
|
||||||
|
|
||||||
|
buildServer(handler, ({ port }, server) => {
|
||||||
|
const client = new Client({
|
||||||
|
node: `http://localhost:${port}`
|
||||||
|
})
|
||||||
|
|
||||||
|
client.search({
|
||||||
|
index: 'test',
|
||||||
|
type: 'doc',
|
||||||
|
q: 'foo:bar'
|
||||||
|
}, {
|
||||||
|
requestTimeout: 10000
|
||||||
|
}, (err, { body }) => {
|
||||||
|
t.error(err)
|
||||||
|
t.deepEqual(body, { hello: 'world' })
|
||||||
|
server.stop()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Basic (options and promises)', t => {
|
||||||
|
t.plan(1)
|
||||||
|
|
||||||
|
function handler (req, res) {
|
||||||
|
res.setHeader('Content-Type', 'application/json;utf=8')
|
||||||
|
res.end(JSON.stringify({ hello: 'world' }))
|
||||||
|
}
|
||||||
|
|
||||||
|
buildServer(handler, ({ port }, server) => {
|
||||||
|
const client = new Client({
|
||||||
|
node: `http://localhost:${port}`
|
||||||
|
})
|
||||||
|
|
||||||
|
client
|
||||||
|
.search({
|
||||||
|
index: 'test',
|
||||||
|
type: 'doc',
|
||||||
|
q: 'foo:bar'
|
||||||
|
}, {
|
||||||
|
requestTimeout: 10000
|
||||||
|
})
|
||||||
|
.then(({ body }) => {
|
||||||
|
t.deepEqual(body, { hello: 'world' })
|
||||||
|
server.stop()
|
||||||
|
})
|
||||||
|
.catch(t.fail)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@ -509,7 +509,8 @@ test('Custom retry mechanism', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/hello',
|
path: '/hello'
|
||||||
|
}, {
|
||||||
maxRetries: 1
|
maxRetries: 1
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.error(err)
|
t.error(err)
|
||||||
@ -727,7 +728,8 @@ test('Override requestTimeout', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/hello',
|
path: '/hello'
|
||||||
|
}, {
|
||||||
requestTimeout: 2000
|
requestTimeout: 2000
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.error(err)
|
t.error(err)
|
||||||
@ -1028,7 +1030,8 @@ test('Ignore status code', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/404',
|
path: '/404'
|
||||||
|
}, {
|
||||||
ignore: [404]
|
ignore: [404]
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.error(err)
|
t.error(err)
|
||||||
@ -1044,7 +1047,8 @@ test('Ignore status code', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/404',
|
path: '/404'
|
||||||
|
}, {
|
||||||
ignore: [403, 405]
|
ignore: [403, 405]
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.ok(err instanceof ResponseError)
|
t.ok(err instanceof ResponseError)
|
||||||
@ -1148,7 +1152,8 @@ test('timeout option', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/hello',
|
path: '/hello'
|
||||||
|
}, {
|
||||||
requestTimeout: 500
|
requestTimeout: 500
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.ok(err instanceof TimeoutError)
|
t.ok(err instanceof TimeoutError)
|
||||||
@ -1213,7 +1218,8 @@ test('timeout option', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/hello',
|
path: '/hello'
|
||||||
|
}, {
|
||||||
requestTimeout: '0.5s'
|
requestTimeout: '0.5s'
|
||||||
}, (err, { body }) => {
|
}, (err, { body }) => {
|
||||||
t.ok(err instanceof TimeoutError)
|
t.ok(err instanceof TimeoutError)
|
||||||
@ -1499,7 +1505,8 @@ test('asStream set to true', t => {
|
|||||||
|
|
||||||
transport.request({
|
transport.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/hello',
|
path: '/hello'
|
||||||
|
}, {
|
||||||
asStream: true
|
asStream: true
|
||||||
}, (err, { body, headers }) => {
|
}, (err, { body, headers }) => {
|
||||||
t.error(err)
|
t.error(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user