Skip to content

Commit

Permalink
Added text/plain responses to cat APIs.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jun 26, 2024
1 parent feb3ea0 commit 175649b
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 9 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^9.1.1",
"@types/jest": "^29.5.12",
"@types/qs": "^6.9.15",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"ajv-errors": "^3.0.0",
"eslint": "^8.57.0",
Expand All @@ -50,6 +51,7 @@
"jest": "^29.7.0",
"json-diff-ts": "^4.0.1",
"json-schema-to-typescript": "^14.0.4",
"qs": "^6.12.1",
"ts-jest": "^29.1.2"
}
}
46 changes: 45 additions & 1 deletion spec/namespaces/cat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ components:
cat.aliases@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -797,6 +799,8 @@ components:
cat.all_pit_segments@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -805,6 +809,8 @@ components:
cat.allocation@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -815,6 +821,8 @@ components:
cat.count@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -823,6 +831,8 @@ components:
cat.fielddata@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -831,6 +841,8 @@ components:
cat.health@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -845,6 +857,8 @@ components:
cat.indices@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -853,6 +867,8 @@ components:
cat.master@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -861,6 +877,8 @@ components:
cat.nodeattrs@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -869,6 +887,8 @@ components:
cat.nodes@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -877,6 +897,8 @@ components:
cat.pending_tasks@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -885,6 +907,8 @@ components:
cat.pit_segments@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -893,6 +917,8 @@ components:
cat.plugins@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -901,6 +927,8 @@ components:
cat.recovery@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -909,6 +937,8 @@ components:
cat.repositories@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -917,6 +947,8 @@ components:
cat.segment_replication@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -925,6 +957,8 @@ components:
cat.segments@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -933,6 +967,8 @@ components:
cat.shards@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -941,6 +977,8 @@ components:
cat.snapshots@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -949,6 +987,8 @@ components:
cat.tasks@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -957,6 +997,8 @@ components:
cat.templates@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand All @@ -965,6 +1007,8 @@ components:
cat.thread_pool@200:
description: ''
content:
text/plain:
type: string
application/json:
schema:
type: array
Expand Down Expand Up @@ -1009,9 +1053,9 @@ components:
in: query
description: Return help information.
schema:
description: Return help information.
type: boolean
default: false
description: Return help information.
cat.aliases::query.local:
name: local
in: query
Expand Down
1 change: 0 additions & 1 deletion tests/_core/bulk.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$schema: ../../json_schemas/test_story.schema.yaml

skip: false
description: Test bulk endpoint.
epilogues:
- path: /books,movies
Expand Down
1 change: 0 additions & 1 deletion tests/_core/search.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$schema: ../../json_schemas/test_story.schema.yaml

skip: false
description: Test search endpoint.
prologues:
- path: /movies/_doc
Expand Down
19 changes: 19 additions & 0 deletions tests/cat/aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test cat/aliases endpoints.
chapters:
- synopsis: Cat with a text response.
path: /_cat/aliases
method: GET
response:
status: 200
content_type: text/plain
- synopsis: Cat with a json response.
path: /_cat/aliases
parameters:
format: json
method: GET
response:
status: 200
content_type: application/json
payload: []
58 changes: 58 additions & 0 deletions tests/cat/health.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test cat/health endpoints.
chapters:
- synopsis: Cat with a default text response.
method: GET
path: /_cat/health
response:
status: 200
content_type: text/plain
- synopsis: Cat with verbose output (v=true).
method: GET
path: /_cat/health
parameters:
v: true
response:
status: 200
content_type: text/plain
- synopsis: Cat with headers (h=header1,header2).
method: GET
path: /_cat/health
parameters:
h:
- status
- timestamp
response:
status: 200
content_type: text/plain
- synopsis: Cat displaying all available headers (help=true).
method: GET
path: /_cat/health
parameters:
help: true
response:
status: 200
content_type: text/plain
- synopsis: Cat with sorted results.
method: GET
path: /_cat/health
parameters:
s:
- status
response:
status: 200
content_type: text/plain
- synopsis: Cat with a json response.
method: GET
path: /_cat/health
parameters:
format: json
response:
status: 200
content_type: application/json
payload:
- node.total: '1'
status: yellow
node.data: '1'
discovered_cluster_manager: 'true'
1 change: 0 additions & 1 deletion tests/cat/index.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$schema: ../../json_schemas/test_story.schema.yaml

skip: false
description: Test cat endpoints.
chapters:
- synopsis: Cat with a json response.
Expand Down
6 changes: 5 additions & 1 deletion tools/src/tester/ChapterReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type OpenSearchHttpClient } from '../OpenSearchHttpClient'
import { type StoryOutputs } from './StoryOutputs'
import { Logger } from 'Logger'
import { to_json, to_ndjson } from '../helpers'
import qs from 'qs'

export default class ChapterReader {
private readonly _client: OpenSearchHttpClient
Expand All @@ -37,7 +38,10 @@ export default class ChapterReader {
method: chapter.method,
headers: { 'Content-Type' : content_type },
params,
data: request_data
data: request_data,
paramsSerializer: (params) => { // eslint-disable-line @typescript-eslint/naming-convention
return qs.stringify(params, { arrayFormat: 'comma' })
}
}).then(r => {
this.logger.info(`<= ${r.status} (${r.headers['content-type']}) | ${to_json(r.data)}`)
response.status = r.status
Expand Down
Loading

0 comments on commit 175649b

Please sign in to comment.