Skip to content

Commit

Permalink
Throw an explicit error when asStream is used with bulk helper (#2078)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4269197)
  • Loading branch information
JoshMock authored and github-actions[bot] committed Nov 16, 2023
1 parent a6cae9f commit 89b87e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ export default class Helpers {
* @return {object} The possible operations to run with the datasource.
*/
bulk<TDocument = unknown> (options: BulkHelperOptions<TDocument>, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
assert(!(reqOptions.asStream ?? false), 'bulk helper: the asStream request option is not supported')

const client = this[kClient]
const { serializer } = client
if (this[kMetaHeader] !== null) {
Expand Down
32 changes: 32 additions & 0 deletions test/unit/helpers/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import FakeTimers from '@sinonjs/fake-timers'
import { AssertionError } from 'assert'
import { createReadStream } from 'fs'
import * as http from 'http'
import { join } from 'path'
Expand Down Expand Up @@ -1336,6 +1337,37 @@ test('transport options', t => {
})
})

t.test('Should not allow asStream request option', async t => {
t.plan(2)

const client = new Client({
node: 'http://localhost:9200',
})

try {
await client.helpers.bulk({
datasource: dataset.slice(),
flushBytes: 1,
concurrency: 1,
onDocument (doc) {
return { index: { _index: 'test' } }
},
onDrop (doc) {
t.fail('This should never be called')
},
refreshOnCompletion: true
}, {
headers: {
foo: 'bar'
},
asStream: true,
})
} catch (err: any) {
t.ok(err instanceof AssertionError)
t.equal(err.message, 'bulk helper: the asStream request option is not supported')
}
})

t.end()
})

Expand Down

0 comments on commit 89b87e6

Please sign in to comment.