Skip to content

Commit

Permalink
Fix: /{index}/_open can return a task.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jul 3, 2024
1 parent cbc0b08 commit 6cc3082
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed `text/plain` response in `/_cat` ([#357](https://github.com/opensearch-project/opensearch-api-specification/pull/357))
- Fixed `/_cat/cluster_manager`, `/_cat/allocation`, `/_cat/shards`, and `/_cat/thread_pool` ([#373](https://github.com/opensearch-project/opensearch-api-specification/pull/373))
- Fixed optional field in `/_nodes` ([#365](https://github.com/opensearch-project/opensearch-api-specification/pull/365))

- Fixed `/{index}/_open` can return a `task` ([#376](https://github.com/opensearch-project/opensearch-api-specification/pull/376))

### Security

[Unreleased]: https://github.com/opensearch-project/opensearch-api-specification/commits/main/
2 changes: 1 addition & 1 deletion SPECIFICATION_TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Note: Remember to set the `OPENSEARCH_PASSWORD` environment variable everytime y
## Writing Spec Tests
The spec tests reside in the [tests/](tests) directory. 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`).
The spec tests reside in the [tests/](tests) directory. 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`).
Each yaml file in the tests directory represents a test story that tests a collection of related operations.
Expand Down
25 changes: 16 additions & 9 deletions spec/namespaces/indices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2393,15 +2393,22 @@ components:
content:
application/json:
schema:
type: object
properties:
acknowledged:
type: boolean
shards_acknowledged:
type: boolean
required:
- acknowledged
- shards_acknowledged
oneOf:
- type: object
properties:
task:
$ref: '../schemas/_common.yaml#/components/schemas/TaskId'
additionalProperties: false
- type: object
properties:
acknowledged:
type: boolean
shards_acknowledged:
type: boolean
required:
- acknowledged
- shards_acknowledged
additionalProperties: false
indices.put_alias@200:
description: ''
content:
Expand Down
38 changes: 38 additions & 0 deletions tests/indices/close.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test closing an index.
prologues:
- path: /movies
method: PUT
status: [200]
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
chapters:
- synopsis: Close an index.
path: /{index}/_close
method: POST
parameters:
index: movies
allow_no_indices: true
expand_wildcards: all
ignore_unavailable: true
wait_for_active_shards: 0
cluster_manager_timeout: 30s
timeout: 30s
response:
status: 200
payload:
indices:
movies:
closed: true
- synopsis: Close an already closed index.
path: /{index}/_close
method: POST
parameters:
index: movies
response:
status: 200
payload:
indices: {}
File renamed without changes.
63 changes: 63 additions & 0 deletions tests/indices/open.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test opening an index.
prologues:
- path: /movies
method: PUT
status: [200]
- path: /games
method: PUT
status: [200]
- path: /movies/_close
method: POST
status: [200]
- path: /games/_close
method: POST
status: [200]
epilogues:
- path: /movies,games
method: DELETE
status: [200, 404]
chapters:
- synopsis: Open a closed index.
path: /{index}/_open
method: POST
parameters:
index: movies
allow_no_indices: true
expand_wildcards: all
ignore_unavailable: true
wait_for_active_shards: 0
cluster_manager_timeout: 30s
timeout: 30s
wait_for_completion: true
response:
status: 200
payload:
shards_acknowledged: true
acknowledged: true
- synopsis: Open a closed index (wait_for_completion=false).
path: /{index}/_open
method: POST
parameters:
index: movies
allow_no_indices: true
expand_wildcards: all
ignore_unavailable: true
wait_for_active_shards: 0
cluster_manager_timeout: 30s
timeout: 30s
wait_for_completion: false
task_execution_timeout: 1m
response:
status: 200
- synopsis: Open an already opened index.
path: /{index}/_open
method: POST
parameters:
index: movies
response:
status: 200
payload:
shards_acknowledged: true
acknowledged: true
2 changes: 1 addition & 1 deletion tools/src/tester/ChapterReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class ChapterReader {
response.message = payload.error?.reason ?? e.response.statusText
response.error = e

this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload ?? response.message}`)
this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload ? to_json(response.payload) : response.message}`)

Check failure on line 64 in tools/src/tester/ChapterReader.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any value in conditional. An explicit comparison or type cast is required
})
return response as ActualResponse
}
Expand Down

0 comments on commit 6cc3082

Please sign in to comment.