-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow response payload to reference variables. (#471)
Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
12 changed files
with
218 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
$schema: ../../../json_schemas/test_story.schema.yaml | ||
|
||
description: Get index_state_management node info settings. | ||
prologues: | ||
- path: /_cat/nodes | ||
id: node | ||
method: GET | ||
parameters: | ||
full_id: true | ||
size: 1 | ||
format: json | ||
h: id | ||
output: | ||
id: payload[0].id | ||
chapters: | ||
- synopsis: Get node info. | ||
path: /_nodes/{node_id_or_metric} | ||
method: GET | ||
parameters: | ||
node_id_or_metric: ${node.id} | ||
response: | ||
status: 200 | ||
payload: | ||
nodes: | ||
${node.id}: | ||
settings: | ||
plugins: | ||
index_state_management: | ||
job_interval: '1' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import { ChapterOutput } from 'tester/ChapterOutput' | ||
import { EvaluationWithOutput, Result } from 'tester/types/eval.types' | ||
import { ActualResponse } from 'tester/types/story.types' | ||
|
||
function create_response(payload: any): ActualResponse { | ||
return { | ||
status: 200, | ||
content_type: 'application/json', | ||
payload | ||
} | ||
} | ||
|
||
function passed_output(output: Record<string, any>): EvaluationWithOutput { | ||
return { | ||
evaluation: { result: Result.PASSED }, | ||
output: new ChapterOutput(output) | ||
} | ||
} | ||
|
||
describe('with an object response', () => { | ||
const response: ActualResponse = create_response({ | ||
a: { | ||
b: { | ||
c: 1 | ||
}, | ||
arr: [ | ||
{ d: 2 }, | ||
{ e: 3 } | ||
] | ||
} | ||
}) | ||
|
||
test('returns nested values', () => { | ||
const output = { | ||
c: 'payload.a.b.c', | ||
d: 'payload.a.arr[0].d', | ||
e: 'payload.a.arr[1].e' | ||
} | ||
|
||
expect(ChapterOutput.extract_output_values(response, output)).toEqual(passed_output({ | ||
c: 1, | ||
d: 2, | ||
e: 3 | ||
})) | ||
}) | ||
|
||
test('extracts complete payload', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'payload' })).toEqual( | ||
passed_output({ x: response.payload }) | ||
) | ||
}) | ||
|
||
test('errors on undefined value', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'payload.a.b.x[0]' })).toEqual({ | ||
evaluation: { | ||
result: Result.ERROR, | ||
message: 'Expected to find non undefined value at `payload.a.b.x[0]`.' | ||
} | ||
}) | ||
}) | ||
|
||
test('errors on invalid source', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'foobar' })).toEqual({ | ||
evaluation: { | ||
result: Result.ERROR, | ||
message: 'Unknown output source: foobar.' | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('with an array response', () => { | ||
const response: ActualResponse = create_response([ | ||
{ | ||
a: { | ||
b: { | ||
c: 1 | ||
}, | ||
arr: [ | ||
{ d: 2 }, | ||
{ e: 3 } | ||
] | ||
} | ||
},{ | ||
a: { | ||
b: { | ||
c: 2 | ||
}, | ||
arr: [ | ||
{ d: 3 }, | ||
{ e: 4 } | ||
] | ||
} | ||
}, | ||
]) | ||
|
||
test('returns nested values', () => { | ||
const output = { | ||
c1: 'payload[0].a.b.c', | ||
d1: 'payload[0].a.arr[0].d', | ||
e1: 'payload[0].a.arr[1].e', | ||
c2: 'payload[1].a.b.c', | ||
d2: 'payload[1].a.arr[0].d', | ||
e2: 'payload[1].a.arr[1].e' | ||
} | ||
|
||
expect(ChapterOutput.extract_output_values(response, output)).toEqual(passed_output({ | ||
c1: 1, | ||
d1: 2, | ||
e1: 3, | ||
c2: 2, | ||
d2: 3, | ||
e2: 4 | ||
})) | ||
}) | ||
|
||
test('extracts complete payload', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'payload' })).toEqual( | ||
passed_output({ x: response.payload }) | ||
) | ||
}) | ||
|
||
test('errors on undefined value', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'payload[0].a.b.x[0]' })).toEqual({ | ||
evaluation: { | ||
result: Result.ERROR, | ||
message: 'Expected to find non undefined value at `payload[0].a.b.x[0]`.' | ||
} | ||
}) | ||
}) | ||
|
||
test('errors on invalid source', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'foobar' })).toEqual({ | ||
evaluation: { | ||
result: Result.ERROR, | ||
message: 'Unknown output source: foobar.' | ||
} | ||
}) | ||
}) | ||
|
||
test('errors on invalid index', () => { | ||
expect(ChapterOutput.extract_output_values(response, { x: 'payload[2]' })).toEqual({ | ||
evaluation: { | ||
result: Result.ERROR, | ||
message: 'Expected to find non undefined value at `payload[2]`.' | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.