From 772b1c89e20afa52ccc3fa3449ae9152aefa4394 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Wed, 21 Aug 2024 14:20:32 -0400 Subject: [PATCH] Complete variations of /{index}/alias/{name} tests, add tests for HEAD, bulk, analyzers. (#519) * Added HEAD / tests. * Detailed where to start adding tests by using the test coverage report. * Complete alias tests. * Added tests for PUT /_bulk and /{index}/_bulk. * Added tests for /_analyze and /{index}/_analyze. Signed-off-by: dblock --- CHANGELOG.md | 1 + TESTING_GUIDE.md | 8 +- spec/namespaces/indices.yaml | 18 ++++ tests/default/_core/alias.yaml | 84 ++++++++++++++++++ tests/default/_core/aliases.yaml | 59 +++++++++++++ tests/default/_core/analyze.yaml | 92 ++++++++++++++++++++ tests/default/_core/bulk.yaml | 17 ++++ tests/default/_core/info.yaml | 5 ++ tests/default/indices/alias/alias.yaml | 20 ++++- tests/default/indices/aliases/aliases.yaml | 21 +---- tests/default/indices/aliases/put_alias.yaml | 79 ----------------- tests/default/indices/analyze.yaml | 51 +++++++++++ tests/default/indices/bulk.yaml | 57 ++++++++++++ 13 files changed, 409 insertions(+), 103 deletions(-) create mode 100644 tests/default/_core/alias.yaml create mode 100644 tests/default/_core/aliases.yaml create mode 100644 tests/default/_core/analyze.yaml delete mode 100644 tests/default/indices/aliases/put_alias.yaml create mode 100644 tests/default/indices/analyze.yaml create mode 100644 tests/default/indices/bulk.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 679e570e6..c5a91329c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `total_rejections_breakup` to `ShardIndexingPressureStats` ([#483](https://github.com/opensearch-project/opensearch-api-specification/pull/483)) - Added `cancelled_task_percentage` and `current_cancellation_eligible_tasks_count` to `ShardSearchBackpressureTaskCancellationStats` ([#483](https://github.com/opensearch-project/opensearch-api-specification/pull/483)) - Added detailed test coverage report ([#513](https://github.com/opensearch-project/opensearch-api-specification/pull/513)) +- Added 404 responses to `/_alias/{name}` and `/{index}/_alias/{name}` ([#519](https://github.com/opensearch-project/opensearch-api-specification/pull/519)) ### Changed diff --git a/TESTING_GUIDE.md b/TESTING_GUIDE.md index 9aa53fca2..852d3844b 100644 --- a/TESTING_GUIDE.md +++ b/TESTING_GUIDE.md @@ -40,6 +40,7 @@ docker compose up -d Run the tests (use `--opensearch-insecure` for a local cluster running in Docker that does not have a valid SSL certificate): ```bash +export OPENSEARCH_PASSWORD=<> npm run test:spec -- --opensearch-insecure ``` @@ -53,6 +54,11 @@ Verbose output: npm run test:spec -- --opensearch-insecure --verbose ``` +Want to help with some missing tests? Choose from the remaining paths in the test coverage report: +```bash +npm run test:spec -- --opensearch-insecure --coverage-report +``` + ### Running Spec Tests with Amazon OpenSearch Use an Amazon OpenSearch service instance. @@ -340,7 +346,7 @@ The report is then used by the [test-spec.yml](.github/workflows/test-spec.yml) ### Coverage Report -The test tool can display detailed and hierarchal test coverage with `--coverage-report`. This is useful to identify untested paths. For example, the [put_alias.yaml](tests/default/indices/aliases/put_alias.yaml) test exercises `PUT /_alias/{name}`, but not the other verbs. The report produces the following output with the missing ones. +The test tool can display detailed and hierarchal test coverage with `--coverage-report`. This is useful to identify untested paths. The report produces the following output with the missing ones. ``` /_alias (4) diff --git a/spec/namespaces/indices.yaml b/spec/namespaces/indices.yaml index d5e13e558..3db14ce5a 100644 --- a/spec/namespaces/indices.yaml +++ b/spec/namespaces/indices.yaml @@ -20,6 +20,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.get_alias@200' + '404': + $ref: '#/components/responses/indices.get_alias@404' put: operationId: indices.put_alias.0 x-operation-group: indices.put_alias @@ -53,6 +55,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.get_alias@200' + '404': + $ref: '#/components/responses/indices.get_alias@404' head: operationId: indices.exists_alias.0 x-operation-group: indices.exists_alias @@ -69,6 +73,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.exists_alias@200' + '404': + $ref: '#/components/responses/indices.exists_alias@404' post: operationId: indices.put_alias.1 x-operation-group: indices.put_alias @@ -1055,6 +1061,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.get_alias@200' + '404': + $ref: '#/components/responses/indices.get_alias@404' put: operationId: indices.put_alias.5 x-operation-group: indices.put_alias @@ -1090,6 +1098,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.get_alias@200' + '404': + $ref: '#/components/responses/indices.get_alias@404' head: operationId: indices.exists_alias.1 x-operation-group: indices.exists_alias @@ -1107,6 +1117,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.exists_alias@200' + '404': + $ref: '#/components/responses/indices.exists_alias@404' post: operationId: indices.put_alias.6 x-operation-group: indices.put_alias @@ -2417,6 +2429,9 @@ components: indices.exists_alias@200: content: application/json: {} + indices.exists_alias@404: + content: + application/json: {} indices.exists_index_template@200: content: application/json: {} @@ -2455,6 +2470,9 @@ components: type: object additionalProperties: $ref: '../schemas/indices.get_alias.yaml#/components/schemas/IndexAliases' + indices.get_alias@404: + content: + application/json: {} indices.get_data_stream@200: content: application/json: diff --git a/tests/default/_core/alias.yaml b/tests/default/_core/alias.yaml new file mode 100644 index 000000000..2cb9e7840 --- /dev/null +++ b/tests/default/_core/alias.yaml @@ -0,0 +1,84 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test /_alias variants. +epilogues: + - path: /movies/_alias/film* + method: DELETE + status: [200, 404] + - path: /movies + method: DELETE + status: [200, 404] +prologues: + - path: /{index} + method: PUT + parameters: + index: movies +chapters: + - synopsis: Create an alias (index in body). + path: /_alias/{name} + method: PUT + parameters: + name: film1 + request: + payload: + index: movies + response: + status: 200 + payload: + acknowledged: true + - synopsis: Create an alias (index in body). + path: /_alias/{name} + method: POST + parameters: + name: film2 + request: + payload: + index: movies + response: + status: 200 + payload: + acknowledged: true + - synopsis: Create an alias (index & alias in body). + path: /_alias + method: PUT + request: + payload: + index: movies + alias: film3 + response: + status: 200 + payload: + acknowledged: true + - synopsis: Get all aliases. + path: /_alias + method: GET + response: + status: 200 + - synopsis: Get an alias by name. + path: /_alias/{name} + parameters: + name: film1 + method: GET + response: + status: 200 + - synopsis: Get an alias by name. + path: /_alias/{name} + parameters: + name: invalid + method: GET + response: + status: 404 + - synopsis: Check that an alias exists. + path: /_alias/{name} + parameters: + name: film1 + method: HEAD + response: + status: 200 + - synopsis: Check that an alias exists. + path: /_alias/{name} + parameters: + name: invalid + method: HEAD + response: + status: 404 diff --git a/tests/default/_core/aliases.yaml b/tests/default/_core/aliases.yaml new file mode 100644 index 000000000..9f1cee73f --- /dev/null +++ b/tests/default/_core/aliases.yaml @@ -0,0 +1,59 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test aliases endpoints. +epilogues: + - path: /games/_alias/* + method: DELETE + status: [200, 404] + - path: /games + method: DELETE + status: [200, 404] +prologues: + - path: games + method: PUT + - path: /games/_aliases/jeux + method: PUT +chapters: + - synopsis: Multiple alias operations. + path: /_aliases + method: POST + request: + payload: + actions: + - remove: + index: games + alias: jeux + - add: + index: games + alias: plays1 + - add: + index: games + alias: plays2 + response: + status: 200 + payload: + acknowledged: true + - synopsis: Create an alias. + path: /_aliases/{name} + method: POST + parameters: + name: plays3 + request: + payload: + index: games + response: + status: 200 + payload: + acknowledged: true + - synopsis: Update an alias. + path: /_aliases/{name} + method: PUT + parameters: + name: plays4 + request: + payload: + index: games + response: + status: 200 + payload: + acknowledged: true diff --git a/tests/default/_core/analyze.yaml b/tests/default/_core/analyze.yaml new file mode 100644 index 000000000..659ec9a96 --- /dev/null +++ b/tests/default/_core/analyze.yaml @@ -0,0 +1,92 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test /_analyze. +epilogues: [] +prologues: [] +chapters: + - synopsis: Analyze text. + path: /_analyze + method: POST + request: + payload: + analyzer: standard + text: Moneyball, directed by Bennett Miller + response: + status: 200 + payload: + tokens: + - token: moneyball + start_offset: 0 + end_offset: 9 + position: 0 + - synopsis: Analyze text as a multi-value field. + path: /_analyze + method: GET + request: + payload: + analyzer: standard + text: + - Drive, directed by Nicolas Winding Refn + - Moneyball, directed by Bennett Miller + response: + status: 200 + - synopsis: Apply a filter. + path: /_analyze + method: GET + request: + payload: + tokenizer: keyword + filter: + - uppercase + text: Moneyball + response: + status: 200 + payload: + tokens: + - token: MONEYBALL + type: word + start_offset: 0 + end_offset: 9 + position: 0 + - synopsis: Apply a character filter. + path: /_analyze + method: GET + request: + payload: + tokenizer: keyword + filter: + - lowercase + char_filter: + - html_strip + text: Moneyball + response: + status: 200 + payload: + tokens: + - token: moneyball + type: word + start_offset: 3 + end_offset: 16 + position: 0 + - synopsis: Combine a lowercase translation with a stop filter. + path: /_analyze + method: GET + request: + payload: + tokenizer: whitespace + filter: + - lowercase + - type: stop + stopwords: + - in + - to + text: Moneyball directed by Bennett Miller + response: + status: 200 + payload: + tokens: + - token: moneyball + type: word + start_offset: 0 + end_offset: 9 + position: 0 diff --git a/tests/default/_core/bulk.yaml b/tests/default/_core/bulk.yaml index 3ed172528..37104b2b7 100644 --- a/tests/default/_core/bulk.yaml +++ b/tests/default/_core/bulk.yaml @@ -14,6 +14,23 @@ chapters: payload: - {create: {_index: movies}} - {director: Bennett Miller, title: Moneyball, year: 2011} + - synopsis: Delete document in an index. + path: /_bulk + method: PUT + request: + content_type: application/x-ndjson + payload: + - {delete: {_index: movies, _id: invalid}} + response: + status: 200 + payload: + errors: false + items: + - delete: + _index: movies + _id: invalid + result: not_found + status: 404 - synopsis: Bulk document CRUD. path: /_bulk method: POST diff --git a/tests/default/_core/info.yaml b/tests/default/_core/info.yaml index f8a360360..813ef6ab6 100644 --- a/tests/default/_core/info.yaml +++ b/tests/default/_core/info.yaml @@ -6,6 +6,11 @@ distributions: excluded: - amazon-serverless chapters: + - synopsis: Head server info. + path: / + method: HEAD + response: + status: 200 - synopsis: Get server info. path: / method: GET diff --git a/tests/default/indices/alias/alias.yaml b/tests/default/indices/alias/alias.yaml index 2fbba5383..4000dbb13 100644 --- a/tests/default/indices/alias/alias.yaml +++ b/tests/default/indices/alias/alias.yaml @@ -36,13 +36,27 @@ chapters: parameters: index: games name: jeux - - synopsis: Create an alias by Create or Update alias endpoint. + - synopsis: Create an alias. path: /{index}/_alias/{name} method: PUT parameters: index: games name: jeux - - synopsis: Create an alias with custom settings by Create or Update alias endpoint. + - synopsis: Check if alias exists. + path: /{index}/_alias/{name} + method: HEAD + parameters: + index: games + name: jeux + - synopsis: Check if alias exists. + path: /{index}/_alias/{name} + method: HEAD + parameters: + index: games + name: invalid + response: + status: 404 + - synopsis: Create an alias with custom settings. path: /{index}/_alias/{name} method: PUT parameters: @@ -56,7 +70,7 @@ chapters: is_write_index: true filter: match_all: {} - - synopsis: Create an alias with is_hidden by Create or Update alias endpoint. + - synopsis: Create an alias with is_hidden. version: '>= 2.16' path: /{index}/_alias/{name} method: PUT diff --git a/tests/default/indices/aliases/aliases.yaml b/tests/default/indices/aliases/aliases.yaml index 805510ae4..75a1918c1 100644 --- a/tests/default/indices/aliases/aliases.yaml +++ b/tests/default/indices/aliases/aliases.yaml @@ -15,28 +15,9 @@ chapters: parameters: index: games name: jeux - - synopsis: Multiple alias operations. - path: /_aliases - method: POST - request: - payload: - actions: - - remove: - index: games - alias: jeux - - add: - index: games - alias: plays1 - - add: - index: games - alias: plays2 - response: - status: 200 - payload: - acknowledged: true - synopsis: Delete an alias. path: /{index}/_aliases/{name} method: DELETE parameters: index: games - name: plays1 + name: jeux diff --git a/tests/default/indices/aliases/put_alias.yaml b/tests/default/indices/aliases/put_alias.yaml deleted file mode 100644 index d7eaa5c99..000000000 --- a/tests/default/indices/aliases/put_alias.yaml +++ /dev/null @@ -1,79 +0,0 @@ -$schema: ../../../../json_schemas/test_story.schema.yaml - -description: Test put_alias variants. -epilogues: - - path: /test_index/_alias/test_alias* - method: DELETE - status: [200, 404] - - path: /test_index - method: DELETE - status: [200, 404] -prologues: - - path: /{index} - method: PUT - parameters: - index: test_index -chapters: - - synopsis: Create an alias - specifying index & alias in path. - path: /{index}/_alias/{name} - method: PUT - parameters: - index: test_index - name: test_alias - response: - status: 200 - payload: - acknowledged: true - - - synopsis: Create an alias - specifying index in path & alias in body. - path: /{index}/_alias - method: PUT - parameters: - index: test_index - request: - payload: - alias: test_alias_1 - response: - status: 200 - payload: - acknowledged: true - - - synopsis: Create an alias - specifying index in body & alias in path. - path: /_alias/{name} - method: PUT - parameters: - name: test_alias_2 - request: - payload: - index: test_index - response: - status: 200 - payload: - acknowledged: true - - - synopsis: Create an alias - specifying index & alias in body. - path: /_alias - method: PUT - request: - payload: - index: test_index - alias: test_alias_3 - response: - status: 200 - payload: - acknowledged: true - - - synopsis: Retrieve aliases. - path: /{index}/_alias - method: GET - parameters: - index: test_index - response: - status: 200 - payload: - test_index: - aliases: - test_alias: {} - test_alias_1: {} - test_alias_2: {} - test_alias_3: {} \ No newline at end of file diff --git a/tests/default/indices/analyze.yaml b/tests/default/indices/analyze.yaml new file mode 100644 index 000000000..9e176a63e --- /dev/null +++ b/tests/default/indices/analyze.yaml @@ -0,0 +1,51 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test /{index}/_analyze. +prologues: + - path: /movies + method: PUT + request: + payload: + settings: + analysis: + analyzer: + default: + type: stop +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Analyze text. + path: /{index}/_analyze + method: POST + parameters: + index: movies + request: + payload: + text: a movie directed by Bennett Miller + response: + status: 200 + payload: + tokens: + - token: movie + start_offset: 2 + end_offset: 7 + position: 1 + - synopsis: Analyze text specifying an analyzer. + path: /{index}/_analyze + method: GET + parameters: + index: movies + request: + payload: + analyzer: standard + text: a movie directed by Bennett Miller + response: + status: 200 + payload: + tokens: + - token: a + start_offset: 0 + end_offset: 1 + position: 0 diff --git a/tests/default/indices/bulk.yaml b/tests/default/indices/bulk.yaml new file mode 100644 index 000000000..fda3b7554 --- /dev/null +++ b/tests/default/indices/bulk.yaml @@ -0,0 +1,57 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test bulk index endpoint. +epilogues: + - path: /books,movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Create an index. + path: /{index}/_bulk + method: POST + parameters: + index: movies + request: + content_type: application/x-ndjson + payload: + - {create: {}} + - {director: Bennett Miller, title: Moneyball, year: 2011} + - synopsis: Delete document in an index. + path: /{index}/_bulk + method: PUT + parameters: + index: movies + request: + content_type: application/x-ndjson + payload: + - {delete: {_id: invalid}} + response: + status: 200 + payload: + errors: false + items: + - delete: + _index: movies + _id: invalid + result: not_found + status: 404 + - synopsis: Bulk index document CRUD. + method: POST + path: /{index}/_bulk + parameters: + index: books + request: + content_type: application/x-ndjson + payload: + - {create: {_id: book_1392214}} + - {author: Harper Lee, title: To Kill a Mockingbird, year: 1960} + - {update: {_id: book_1392214}} + - {doc: {pages: 376}} + - {update: {_id: book_1392214}} + - {doc: {pages: 376}, _source: true} + - {update: {_id: book_1392214}} + - {script: {source: ctx._source.pages = 376;}} + - {update: {_id: does_not_exist}} + - {script: {source: 'ctx.op = "none";'}, scripted_upsert: true, upsert: {pages: 375}} + - {delete: {_id: book_1392214}} +