From e0bebb38b6ac189f2e23cf855a5d24dba17d8235 Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 10 Jun 2024 15:17:22 -0400 Subject: [PATCH 1/4] Reorganized tests to match spec layout. Signed-off-by: dblock --- tests/{ => _core}/index.yaml | 2 +- tests/{ => _core}/info.yaml | 2 +- .../pipeline/_common/processors.yaml} | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) rename tests/{ => _core}/index.yaml (97%) rename tests/{ => _core}/info.yaml (85%) rename tests/{text_embedding_processor.yaml => _ingest/pipeline/_common/processors.yaml} (57%) diff --git a/tests/index.yaml b/tests/_core/index.yaml similarity index 97% rename from tests/index.yaml rename to tests/_core/index.yaml index a2e955ad6..3873b0230 100644 --- a/tests/index.yaml +++ b/tests/_core/index.yaml @@ -1,4 +1,4 @@ -$schema: ../json_schemas/test_story.schema.yaml +$schema: ../../json_schemas/test_story.schema.yaml skip: false description: Test endpoints relevant the lifecycle of an index, from creation to deletion. diff --git a/tests/info.yaml b/tests/_core/info.yaml similarity index 85% rename from tests/info.yaml rename to tests/_core/info.yaml index 367ce3cd9..5a8e14f07 100644 --- a/tests/info.yaml +++ b/tests/_core/info.yaml @@ -1,5 +1,5 @@ -$schema: ../json_schemas/test_story.schema.yaml +$schema: ../../json_schemas/test_story.schema.yaml skip: false description: Test root endpoint. diff --git a/tests/text_embedding_processor.yaml b/tests/_ingest/pipeline/_common/processors.yaml similarity index 57% rename from tests/text_embedding_processor.yaml rename to tests/_ingest/pipeline/_common/processors.yaml index ac1a98550..214a27cb1 100644 --- a/tests/text_embedding_processor.yaml +++ b/tests/_ingest/pipeline/_common/processors.yaml @@ -1,32 +1,31 @@ -$schema: ../json_schemas/test_story.schema.yaml +$schema: ../../../../json_schemas/test_story.schema.yaml skip: false description: | - This test story checks that we can create an ingest pipeline with a text - embedding processor + Test the creation of an ingest pipeline with a text embedding processor. epilogues: - path: /_ingest/pipeline/books_pipeline method: DELETE status: [200, 404] chapters: - - synopsis: Create ingest pipeline for text embedding + - synopsis: Create ingest pipeline for text embedding. path: /_ingest/pipeline/{id} method: PUT parameters: id: books_pipeline request_body: payload: - description: "Extracts text from field and embeds it" + description: Extracts text from field and embeds it. processors: - text_embedding: - model_id: "text-embedding-model" + model_id: text-embedding-model field_map: - text: "passage_embedding" + text: passage_embedding response: status: 200 payload: acknowledged: true - - synopsis: Query created pipeline + - synopsis: Query created pipeline. path: /_ingest/pipeline/{id} method: GET parameters: From e4de66682920d5b13ffc82584081421a6b663794 Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 10 Jun 2024 15:42:02 -0400 Subject: [PATCH 2/4] Added tests for _doc. Signed-off-by: dblock --- CHANGELOG.md | 1 + DEVELOPER_GUIDE.md | 2 +- spec/namespaces/_core.yaml | 12 +++++++++ tests/_core/index/_doc.yaml | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/_core/index/_doc.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index ceae883de..b0907b673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fixed GitHub pages ([#215](https://github.com/opensearch-project/opensearch-api-specification/pull/215)) +- Fixed missing 201 response in `/{index}/_doc/{id}` ([#331](https://github.com/opensearch-project/opensearch-api-specification/pull/331)) ### Security diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 643f4506d..1a42372cd 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -155,7 +155,7 @@ To assure the correctness of the spec, you must add tests for the spec in the [t - chapters: These are the operations that are being tested. - epilogues: These are the operations that are executed after the test story is run. They are used to clean up the environment after the test story. -Below is the simplified version of the test story that tests the [index operations](tests/index.yaml): +Below is the simplified version of the test story that tests the [index operations](tests/_core/index.yaml): ```yaml $schema: ../json_schemas/test_story.schema.yaml # The schema of the test story. Include this line so that your editor can validate the test story on the fly. diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 2e1aeb6cb..a992acaed 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -1218,6 +1218,8 @@ paths: requestBody: $ref: '#/components/requestBodies/index' responses: + '201': + $ref: '#/components/responses/index@201' '200': $ref: '#/components/responses/index@200' /{index}/_doc/{id}: @@ -1291,6 +1293,8 @@ paths: requestBody: $ref: '#/components/requestBodies/index' responses: + '201': + $ref: '#/components/responses/index@201' '200': $ref: '#/components/responses/index@200' put: @@ -1317,6 +1321,8 @@ paths: requestBody: $ref: '#/components/requestBodies/index' responses: + '201': + $ref: '#/components/responses/index@201' '200': $ref: '#/components/responses/index@200' delete: @@ -2875,6 +2881,12 @@ components: application/json: schema: $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' + index@201: + description: '' + content: + application/json: + schema: + $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' info@200: description: '' content: diff --git a/tests/_core/index/_doc.yaml b/tests/_core/index/_doc.yaml new file mode 100644 index 000000000..6b21f687b --- /dev/null +++ b/tests/_core/index/_doc.yaml @@ -0,0 +1,49 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +skip: false +description: Test inserting and retrieving a doc. +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Create a document. + path: /{index}/_doc/{id} + method: POST + parameters: + index: movies + id: '1' + request_body: + payload: + title: Beauty and the Beast + year: 1991 + response: + status: 201 + - synopsis: Update a document. + path: /{index}/_doc/{id} + method: PUT + parameters: + index: movies + id: '1' + request_body: + payload: + title: Beauty and the Beast (Updated) + year: 1991 + response: + status: 200 + - synopsis: Retrieve a document. + path: /{index}/_doc/{id} + method: GET + parameters: + index: movies + id: '1' + response: + status: 200 + - synopsis: Delete a document. + path: /{index}/_doc/{id} + method: DELETE + parameters: + index: movies + id: '1' + response: + status: 200 From 7a694018a32410429950ce8cde15696ba23cebca Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 10 Jun 2024 15:52:35 -0400 Subject: [PATCH 3/4] Create a doc without an ID. Signed-off-by: dblock --- tests/_core/index/_doc.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/_core/index/_doc.yaml b/tests/_core/index/_doc.yaml index 6b21f687b..b85d72151 100644 --- a/tests/_core/index/_doc.yaml +++ b/tests/_core/index/_doc.yaml @@ -7,6 +7,17 @@ epilogues: method: DELETE status: [200, 404] chapters: + - synopsis: Create a document. + path: /{index}/_doc + method: POST + parameters: + index: movies + request_body: + payload: + title: Beauty and the Beast + year: 1991 + response: + status: 201 - synopsis: Create a document. path: /{index}/_doc/{id} method: POST @@ -15,7 +26,7 @@ chapters: id: '1' request_body: payload: - title: Beauty and the Beast + title: Beauty and the Beast (Id) year: 1991 response: status: 201 From cf8d6413dfe26c05a643458297dc030eaa6559b1 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 11 Jun 2024 07:51:46 -0400 Subject: [PATCH 4/4] Reorganize tests in namespaces. Signed-off-by: dblock --- DEVELOPER_GUIDE.md | 16 ++++++++++++++-- tests/{_core/index => indices}/_doc.yaml | 2 +- tests/{_core => indices}/index.yaml | 0 .../processors.yaml => ingest/pipeline.yaml} | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) rename tests/{_core/index => indices}/_doc.yaml (95%) rename tests/{_core => indices}/index.yaml (100%) rename tests/{_ingest/pipeline/_common/processors.yaml => ingest/pipeline.yaml} (93%) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 1a42372cd..76f19a1a4 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -9,6 +9,8 @@ - [Global Parameters](#global-parameters) - [OpenAPI Extensions](#openapi-extensions) - [Writing Spec Tests](#writing-spec-tests) + - [Test Stories](#test-stories) + - [Organizing Tests](#organizing-tests) - [Running Spec Tests Locally](#running-spec-tests-locally) - [Tools](#tools) - [Setup](#setup) @@ -150,12 +152,18 @@ This repository includes several OpenAPI Specification Extensions to fill in any ## Writing Spec Tests -To assure the correctness of the spec, you must add tests for the spec in the [tests/](tests) directory. Each yaml file in the tests directory represents a test story that tests a collection of related operations. A test story has 3 main components: +To assure the correctness of the spec, you must add tests for the spec in the [tests/](tests) directory. + +### Test Stories + +Each yaml file in the tests directory represents a test story that tests a collection of related operations. + +A test story has 3 main components: - prologues: These are the operations that are executed before the test story is run. They are used to set up the environment for the test story. - chapters: These are the operations that are being tested. - epilogues: These are the operations that are executed after the test story is run. They are used to clean up the environment after the test story. -Below is the simplified version of the test story that tests the [index operations](tests/_core/index.yaml): +Below is the simplified version of the test story that tests the [index operations](tests/indices/index.yaml): ```yaml $schema: ../json_schemas/test_story.schema.yaml # The schema of the test story. Include this line so that your editor can validate the test story on the fly. @@ -205,6 +213,10 @@ chapters: Check the [test_story JSON Schema](json_schemas/test_story.schema.yaml) for the complete structure of a test story. +### Organizing Tests + +Tests are organized in folders that match [namespaces](spec/namespaces). For example, tests for APIs defined in [spec/namespaces/indices.yaml](spec/namespaces/indices.yaml) can be found in [tests/indices/index.yaml](tests/indices/index.yaml) (for `/{index}`), and [tests/indices/_doc.yaml](tests/indices/_doc.yaml) (for `/{index}/_doc`). + ### Running Spec Tests Locally Set up an OpenSearch cluster with Docker using the default OPENSEARCH_PASSWORD (Recommended): diff --git a/tests/_core/index/_doc.yaml b/tests/indices/_doc.yaml similarity index 95% rename from tests/_core/index/_doc.yaml rename to tests/indices/_doc.yaml index b85d72151..b4789f0c7 100644 --- a/tests/_core/index/_doc.yaml +++ b/tests/indices/_doc.yaml @@ -1,4 +1,4 @@ -$schema: ../../../json_schemas/test_story.schema.yaml +$schema: ../../json_schemas/test_story.schema.yaml skip: false description: Test inserting and retrieving a doc. diff --git a/tests/_core/index.yaml b/tests/indices/index.yaml similarity index 100% rename from tests/_core/index.yaml rename to tests/indices/index.yaml diff --git a/tests/_ingest/pipeline/_common/processors.yaml b/tests/ingest/pipeline.yaml similarity index 93% rename from tests/_ingest/pipeline/_common/processors.yaml rename to tests/ingest/pipeline.yaml index 214a27cb1..2408d79d3 100644 --- a/tests/_ingest/pipeline/_common/processors.yaml +++ b/tests/ingest/pipeline.yaml @@ -1,4 +1,4 @@ -$schema: ../../../../json_schemas/test_story.schema.yaml +$schema: ../../json_schemas/test_story.schema.yaml skip: false description: |