Skip to content

Commit

Permalink
feat(helpers): Throw an explicit error when asStream is used with bul…
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMock committed Nov 16, 2023
1 parent ad61cc3 commit 9ee3a11
Show file tree
Hide file tree
Showing 2 changed files with 33 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 @@ -524,6 +524,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
31 changes: 31 additions & 0 deletions test/unit/helpers/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { AssertionError } from 'assert'
import * as http from 'http'
import { createReadStream } from 'fs'
import { join } from 'path'
Expand Down Expand Up @@ -1161,6 +1162,36 @@ 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')
},
}, {
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 9ee3a11

Please sign in to comment.