-
Notifications
You must be signed in to change notification settings - Fork 61
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
174 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,30 @@ | ||
$schema: ../../json_schemas/test_story.schema.yaml | ||
|
||
skip: false | ||
description: Test bulk endpoint. | ||
epilogues: | ||
- path: /books,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} | ||
- synopsis: Bulk document CRUD. | ||
path: /_bulk | ||
method: POST | ||
request_body: | ||
content_type: application/x-ndjson | ||
payload: | ||
- {create: {_index: books, _id: book_1392214}} | ||
- {author: Harper Lee, title: To Kill a Mockingbird, year: 1960} | ||
- {update: {_index: books, _id: book_1392214}} | ||
- {doc: {pages: 376}} | ||
- {update: {_index: books, _id: book_1392214}} | ||
- {script: {source: 'ctx._source.pages = 376;'}} | ||
- {delete: {_index: books, _id: book_1392214}} |
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,106 @@ | ||
/* | ||
* 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('resolves path parameters', async () => { | ||
const result = await reader.read({ | ||
id: 'id', | ||
path: '{index}/path', | ||
method: 'GET', | ||
parameters: { index: 'books' }, | ||
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: 'books/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"}] | ||
]) | ||
}) | ||
}) | ||
|