Skip to content

Commit

Permalink
adding not covered index api tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tokesh <[email protected]>
  • Loading branch information
Tokesh committed Nov 17, 2024
1 parent f847731 commit 42056a6
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/default/indices/explain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test _explain.
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
prologues:
- id: doc
path: /movies/_doc
method: POST
request:
payload:
title: Beauty and the Beast
year: 1991
status: [201]
output:
id: payload._id
- path: /_refresh
method: POST
chapters:
- synopsis: Post explanation for a document with query.
path: /{index}/_explain/{id}
method: POST
parameters:
index: movies
id: ${doc.id}
request:
payload:
query:
match:
title: "Beauty and the Beast"

Check failure on line 32 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Must use plain style scalar

Check failure on line 32 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
response:
status: 200
payload:
matched: true
explanation:
value: 1.1507283
description: "sum of:"

Check failure on line 39 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
details: []
- synopsis: Get explanation for a document.
path: /{index}/_explain/{id}
method: GET
parameters:
index: movies
id: ${doc.id}
request:
payload:
query:
match:
title: "Beauty and the Beast"

Check failure on line 51 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Must use plain style scalar

Check failure on line 51 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
response:
status: 200
payload:
matched: true
explanation:
value: 1.1507283
description: "sum of:"

Check failure on line 58 in tests/default/indices/explain.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
details: []
37 changes: 37 additions & 0 deletions tests/default/indices/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,40 @@ chapters:
status: 200
payload:
acknowledged: true
- synopsis: Add new fields to index mapping.
path: /{index}/_mapping
method: POST
parameters:
index: movies
request:
payload:
properties:
genre:
type: text
rating:
type: float
response:
status: 200
payload:
acknowledged: true
- synopsis: Get specific field mappings for an index.
path: /{index}/_mapping/field/{fields}
method: GET
parameters:
index: movies
fields: director,year
response:
status: 200
payload:
movies:
mappings:
year:
full_name: "year"

Check failure on line 177 in tests/default/indices/mapping.yaml

View workflow job for this annotation

GitHub Actions / lint

Must use plain style scalar

Check failure on line 177 in tests/default/indices/mapping.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
mapping:
year:
type: integer
director:
full_name: "director"

Check failure on line 182 in tests/default/indices/mapping.yaml

View workflow job for this annotation

GitHub Actions / lint

Must use plain style scalar

Check failure on line 182 in tests/default/indices/mapping.yaml

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
mapping:
director:
type: text
124 changes: 124 additions & 0 deletions tests/default/indices/msearch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test endpoints relevant to the lifecycle of an index, including multi-get and multi-search operations.
epilogues:
- path: /books
method: DELETE
status: [200, 404]
- path: /games
method: DELETE
status: [200, 404]
chapters:
- synopsis: Create an index named `books` with mappings and settings.
path: /{index}
method: PUT
parameters:
index: books
request:
payload:
mappings:
properties:
name:
type: keyword
age:
type: integer
settings:
number_of_shards: 5
number_of_replicas: 2
response:
status: 200

- synopsis: Create an index named `games` with default settings.
path: /{index}
method: PUT
parameters:
index: games

- synopsis: Add documents to the `books` index.
path: /{index}/_doc/{id}
method: POST
parameters:
index: books
id: '1'
request:
payload:
name: "Book 1"
age: 10
response:
status: 201

- synopsis: Add more documents to the `books` index.
path: /{index}/_doc/{id}
method: POST
parameters:
index: books
id: '2'
request:
payload:
name: "Book 2"
age: 20
response:
status: 201

- synopsis: Add another document to the `books` index.
path: /{index}/_doc/{id}
method: POST
parameters:
index: books
id: '3'
request:
payload:
name: "Book 3"
age: 30
response:
status: 201

- synopsis: Perform a `_mget` request to retrieve documents by IDs.
path: /{index}/_mget
method: POST
parameters:
index: books
request:
payload:
ids: ['1', '2', '3']
response:
status: 200
payload:
docs:
- _index: "books"
_id: "1"
_source:
name: "Book 1"
age: 10
- _index: "books"
_id: "2"
_source:
name: "Book 2"
age: 20
- _index: "books"
_id: "3"
_source:
name: "Book 3"
age: 30

- synopsis: Perform a `_msearch` request to execute multiple search queries in a single call.
path: /{index}/_msearch
method: POST
parameters:
index: books
request:
content_type: application/x-ndjson
payload:
- { index: "books" }
- { "query": { "match": { "name": "Book 1" } } }
- { index: "books" }
- { "query": { "match": { "name": "Book 2" } } }
response:
status: 200
- synopsis: Delete the `books` and `games` indices.
path: /{index}
method: DELETE
parameters:
index: books,games
response:
status: 200
24 changes: 24 additions & 0 deletions tests/default/indices/refresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ chapters:
payload:
_shards:
failed: 0
- synopsis: Adding one more document.
path: /{index}/_doc
method: POST
parameters:
index: movies
request:
payload:
title: Margin call
year: 2011
response:
status: 201
- synopsis: Refresh an index.
path: /{index}/_refresh
method: GET
parameters:
index: movies
ignore_unavailable: true
allow_no_indices: false
expand_wildcards: all
response:
status: 200
payload:
_shards:
failed: 0

0 comments on commit 42056a6

Please sign in to comment.