Skip to content

Commit 3a95369

Browse files
delvedorgithub-actions[bot]
authored andcommitted
Wrap inside array ndjson bodies in integration test (#1444)
* Wrap inside array ndjson bodies * Fix path * Use orignal api name
1 parent 8b946af commit 3a95369

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/integration/test-runner.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const assert = require('assert')
2525
const semver = require('semver')
2626
const helper = require('./helper')
2727
const deepEqual = require('fast-deep-equal')
28+
const { join } = require('path')
29+
const { locations } = require('../../scripts/download-artifacts')
2830
const { ConfigurationError } = require('../../lib/errors')
2931

3032
const { delve, to, isXPackTemplate, sleep } = helper
@@ -362,6 +364,11 @@ function build (opts = {}) {
362364
if (!Array.isArray(options.ignore)) options.ignore = [options.ignore]
363365
if (cmd.params.ignore) delete cmd.params.ignore
364366

367+
// ndjson apis should always send the body as an array
368+
if (isNDJson(cmd.api) && !Array.isArray(cmd.params.body)) {
369+
cmd.params.body = [cmd.params.body]
370+
}
371+
365372
const [err, result] = await to(api(cmd.params, options))
366373
let warnings = result ? result.warnings : null
367374
const body = result ? result.body : null
@@ -696,6 +703,7 @@ function parseDo (action) {
696703
// converts underscore to camelCase
697704
// eg: put_mapping => putMapping
698705
acc.method = val.replace(/_([a-z])/g, g => g[1].toUpperCase())
706+
acc.api = val
699707
acc.params = camelify(action[val])
700708
}
701709
return acc
@@ -848,6 +856,12 @@ function shouldSkip (esVersion, action) {
848856
return false
849857
}
850858

859+
function isNDJson (api) {
860+
const spec = require(join(locations.specFolder, `${api}.json`))
861+
const { content_type } = spec[Object.keys(spec)[0]].headers
862+
return Boolean(content_type && content_type.includes('application/x-ndjson'))
863+
}
864+
851865
/**
852866
* Updates the array syntax of keys and values
853867
* eg: 'hits.hits.1.stuff' to 'hits.hits[1].stuff'

0 commit comments

Comments
 (0)