Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed May 21, 2024
1 parent 23d1ccc commit a6101ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/index_lifecycle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ chapters:
age:
type: integer
settings:
number_of_shards: 5
number_of_shard: 5
number_of_replicas: 2
response:
status: 200
Expand Down
8 changes: 5 additions & 3 deletions tools/src/tester/ChapterEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type ParsedOperation } from './types/spec.types'
export default class ChapterEvaluator {
chapter: Chapter
result: Result = Result.PASSED
skip_payload: boolean = false

constructor (chapter: Chapter) {
this.chapter = chapter
Expand Down Expand Up @@ -52,12 +53,13 @@ export default class ChapterEvaluator {

#evaluate_status (response: FullResponse): Evaluation {
const expected_status = this.chapter.response?.status ?? 200
return response.status === expected_status
? { result: Result.PASSED }
: { result: Result.FAILED, message: `Expected status ${expected_status}, but received ${response.status}` }
if (response.status === expected_status) return { result: Result.PASSED }
this.skip_payload = true
return { result: Result.FAILED, message: `Expected status ${expected_status}, but received ${response.status}` }
}

#evaluate_payload (operation: ParsedOperation, response: FullResponse): Evaluation {
if (this.skip_payload) return { result: Result.SKIPPED }
const schema = operation.responses[response.status]?.content[response.content_type]?.schema
if (schema == null) return { result: Result.FAILED, message: `Schema for "${response.status}: ${response.content_type}" response not found.` }
const evaluation = globalThis.schema_validator.validate(schema, response.payload)
Expand Down
2 changes: 2 additions & 0 deletions tools/src/tester/ResultsDisplayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Evaluation, Result, type StoryEvaluation } from './types/eval.types'
import YAML from 'yaml'

function b (text: string): string { return `\x1b[1m${text}\x1b[0m` }
function i (text: string): string { return `\x1b[3m${text}\x1b[0m` }
Expand All @@ -22,6 +23,7 @@ export default class ResultsDisplayer {
constructor (evaluation: StoryEvaluation) {
this.evaluation = evaluation
this.skip_components = [Result.PASSED, Result.SKIPPED].includes(evaluation.result)
console.log(YAML.stringify(evaluation, null, 2))
}

display (): void {
Expand Down

0 comments on commit a6101ed

Please sign in to comment.