From 962452cc1eb6398614c066bea5aabcd4149f7640 Mon Sep 17 00:00:00 2001 From: Niyazbek Torekeldi <78027392+Tokesh@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:51:05 +0500 Subject: [PATCH] Add missing Index API Spec Tests, Part 1 (#678) --- spec/namespaces/replication.yaml | 2 +- tests/default/indices/mapping/field.yaml | 61 +++++++++++++++++++ .../{mapping.yaml => mapping/index.yaml} | 4 +- tests/default/indices/msearch.yaml | 36 +++++++++++ tests/default/indices/refresh.yaml | 2 +- tests/default/indices/validate/query.yaml | 49 +++++++++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 tests/default/indices/mapping/field.yaml rename tests/default/indices/{mapping.yaml => mapping/index.yaml} (97%) create mode 100644 tests/default/indices/msearch.yaml create mode 100644 tests/default/indices/validate/query.yaml diff --git a/spec/namespaces/replication.yaml b/spec/namespaces/replication.yaml index db8e0c7b8..098dd6537 100644 --- a/spec/namespaces/replication.yaml +++ b/spec/namespaces/replication.yaml @@ -298,4 +298,4 @@ components: content: application/json: schema: - $ref: '../schemas/_common.yaml#/components/schemas/AcknowledgedResponseBase' \ No newline at end of file + $ref: '../schemas/_common.yaml#/components/schemas/AcknowledgedResponseBase' diff --git a/tests/default/indices/mapping/field.yaml b/tests/default/indices/mapping/field.yaml new file mode 100644 index 000000000..5037e2ec3 --- /dev/null +++ b/tests/default/indices/mapping/field.yaml @@ -0,0 +1,61 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test specific field mappings endpoints. +prologues: + - path: /{index} + method: PUT + parameters: + index: movies + request: + payload: + mappings: + properties: + director: + type: text + year: + type: integer + location: + type: ip + ignore_malformed: true +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - 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 + mapping: + year: + type: integer + director: + full_name: director + mapping: + director: + type: text diff --git a/tests/default/indices/mapping.yaml b/tests/default/indices/mapping/index.yaml similarity index 97% rename from tests/default/indices/mapping.yaml rename to tests/default/indices/mapping/index.yaml index ea0fce71b..35a74eeea 100644 --- a/tests/default/indices/mapping.yaml +++ b/tests/default/indices/mapping/index.yaml @@ -1,4 +1,4 @@ -$schema: ../../../json_schemas/test_story.schema.yaml +$schema: ../../../../json_schemas/test_story.schema.yaml description: Test mappings endpoints. prologues: @@ -145,4 +145,4 @@ chapters: response: status: 200 payload: - acknowledged: true + acknowledged: true \ No newline at end of file diff --git a/tests/default/indices/msearch.yaml b/tests/default/indices/msearch.yaml new file mode 100644 index 000000000..ba5cd97eb --- /dev/null +++ b/tests/default/indices/msearch.yaml @@ -0,0 +1,36 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test endpoints relevant to the lifecycle of an index, including multi-get and multi-search operations. +prologues: + - path: /_bulk + method: POST + parameters: + refresh: true + request: + content_type: application/x-ndjson + payload: + - {create: {_index: books, _id: book1}} + - {author: Harper Lee, title: To Kill a Mockingbird, year: 60} + - {create: {_index: books, _id: book2}} + - {director: Bennett Miller, title: The Cruise, year: 1998} + - {create: {_index: books, _id: book3}} + - {director: Nicolas Winding Refn, title: Drive, year: 1960} +epilogues: + - path: /books + method: DELETE + status: [200, 404] +chapters: + - 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: {title: To Kill a Mockingbird}}} + - {index: books} + - {query: {match: {title: The Cruise}}} + response: + status: 200 \ No newline at end of file diff --git a/tests/default/indices/refresh.yaml b/tests/default/indices/refresh.yaml index a17644e53..55b171e23 100644 --- a/tests/default/indices/refresh.yaml +++ b/tests/default/indices/refresh.yaml @@ -36,4 +36,4 @@ chapters: status: 200 payload: _shards: - failed: 0 + failed: 0 \ No newline at end of file diff --git a/tests/default/indices/validate/query.yaml b/tests/default/indices/validate/query.yaml new file mode 100644 index 000000000..264579058 --- /dev/null +++ b/tests/default/indices/validate/query.yaml @@ -0,0 +1,49 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test validating queries for a specific index using both GET and POST methods. +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +prologues: + - path: /_bulk + method: POST + parameters: + refresh: true + request: + content_type: application/x-ndjson + payload: + - {create: {_index: movies, _id: movie1}} + - {director: Bennett Miller, title: The Cruise, year: 1998} + - {create: {_index: movies, _id: movie2}} + - {director: Nicolas Winding Refn, title: Drive, year: 1960} +chapters: + - synopsis: Validate a match query (GET). + path: /{index}/_validate/query + method: GET + parameters: + index: movies + request: + payload: + query: + match: + year: 1998 + response: + status: 200 + payload: + valid: true + + - synopsis: Validate a match query (POST). + path: /{index}/_validate/query + method: POST + parameters: + index: movies + request: + payload: + query: + match: + title: Drive + response: + status: 200 + payload: + valid: true \ No newline at end of file