Skip to content

Wrap inside array ndjson bodies in integration test #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/integration/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const assert = require('assert')
const semver = require('semver')
const helper = require('./helper')
const deepEqual = require('fast-deep-equal')
const { join } = require('path')
const { locations } = require('../../scripts/download-artifacts')
const { ConfigurationError } = require('../../lib/errors')

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

// ndjson apis should always send the body as an array
if (isNDJson(cmd.api) && !Array.isArray(cmd.params.body)) {
cmd.params.body = [cmd.params.body]
}

const [err, result] = await to(api(cmd.params, options))
let warnings = result ? result.warnings : null
const body = result ? result.body : null
Expand Down Expand Up @@ -696,6 +703,7 @@ function parseDo (action) {
// converts underscore to camelCase
// eg: put_mapping => putMapping
acc.method = val.replace(/_([a-z])/g, g => g[1].toUpperCase())
acc.api = val
acc.params = camelify(action[val])
}
return acc
Expand Down Expand Up @@ -848,6 +856,12 @@ function shouldSkip (esVersion, action) {
return false
}

function isNDJson (api) {
const spec = require(join(locations.specFolder, `${api}.json`))
const { content_type } = spec[Object.keys(spec)[0]].headers
return Boolean(content_type && content_type.includes('application/x-ndjson'))
}

/**
* Updates the array syntax of keys and values
* eg: 'hits.hits.1.stuff' to 'hits.hits[1].stuff'
Expand Down