-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for application/x-ndjson and tests for _bulk.
Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
10 changed files
with
144 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ Lovins | |
Lucene | ||
Millis | ||
Multisearch | ||
Moneyball | ||
Nanos | ||
Nori | ||
ONNX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$schema: ../../json_schemas/test_story.schema.yaml | ||
|
||
skip: false | ||
description: Test bulk endpoint. | ||
epilogues: | ||
- path: /movies | ||
method: DELETE | ||
status: [200, 404] | ||
chapters: | ||
- synopsis: Create an index. | ||
path: /_bulk | ||
method: POST | ||
request_body: | ||
content_type: application/x-ndjson | ||
payload: | ||
- {create: {_index: movies}} | ||
- {director: Bennett Miller, title: Moneyball, year: 2011} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import { Logger } from 'Logger'; | ||
import { OpenSearchHttpClient } from 'OpenSearchHttpClient'; | ||
import axios from 'axios'; | ||
import ChapterReader from 'tester/ChapterReader'; | ||
import { StoryOutputs } from 'tester/StoryOutputs'; | ||
|
||
jest.mock('axios'); | ||
const mocked_axios = axios as jest.Mocked<typeof axios>; | ||
|
||
describe('ChapterReader', () => { | ||
var reader: ChapterReader | ||
|
||
beforeEach(() => { | ||
mocked_axios.create.mockReturnThis() | ||
|
||
mocked_axios.request.mockResolvedValue({ | ||
status: 200, | ||
headers: { | ||
'content-type': 'application/json' | ||
} | ||
}); | ||
|
||
reader = new ChapterReader(new OpenSearchHttpClient(), new Logger()) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('sends a GET request', async () => { | ||
const result = await reader.read({ | ||
id: 'id', | ||
path: 'path', | ||
method: 'GET', | ||
parameters: undefined, | ||
request_body: undefined, | ||
output: undefined | ||
}, new StoryOutputs()) | ||
|
||
expect(result).toEqual({ status: 200, content_type: 'application/json', payload: undefined }) | ||
expect(mocked_axios.request.mock.calls).toEqual([ | ||
[{ url: 'path', method: 'GET', headers: { 'Content-Type': 'application/json' }, params: {}, data: undefined }] | ||
]) | ||
}) | ||
|
||
it('sends a POST request', async () => { | ||
const result = await reader.read({ | ||
id: 'id', | ||
path: 'path', | ||
method: 'POST', | ||
parameters: { 'x': 1 }, | ||
request_body: { payload: { "body": "present" } }, | ||
output: undefined | ||
}, new StoryOutputs()) | ||
|
||
expect(result).toEqual({ status: 200, content_type: 'application/json', payload: undefined }) | ||
expect(mocked_axios.request.mock.calls).toEqual([ | ||
[{ url: 'path', method: 'POST', headers: { 'Content-Type': 'application/json' }, params: { 'x': 1 }, data: { 'body': 'present' } }] | ||
]) | ||
}) | ||
|
||
it('sends an nd-json POST request', async () => { | ||
const result = await reader.read({ | ||
id: 'id', | ||
path: 'path', | ||
method: 'POST', | ||
parameters: { 'x': 1 }, | ||
request_body: { | ||
content_type: 'application/x-ndjson', | ||
payload: [{ "body": "present" }] | ||
}, | ||
output: undefined | ||
}, new StoryOutputs()) | ||
|
||
expect(result).toEqual({ status: 200, content_type: 'application/json', payload: undefined }) | ||
expect(mocked_axios.request.mock.calls).toEqual([ | ||
[{ url: 'path', method: 'POST', headers: { 'Content-Type': 'application/x-ndjson' }, params: { 'x': 1 }, data: "{\"body\":\"present\"}\n"}] | ||
]) | ||
}) | ||
}) | ||
|