Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added StoryValidator #362

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

nhtruong
Copy link
Collaborator

Validating stories before running them.

Issues Resolved

closes #354

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

github-actions bot commented Jun 26, 2024

Changes Analysis

Commit SHA: f1d6d85
Comparing To SHA: 35f3a5c

API Changes

Summary

NO CHANGES

Report

The full API changes report is available at: https://github.com/opensearch-project/opensearch-api-specification/actions/runs/9686292855/artifacts/1642073848

API Coverage

Before After Δ
Covered (%) 483 (47.31 %) 483 (47.31 %) 0 (0 %)
Uncovered (%) 538 (52.69 %) 538 (52.69 %) 0 (0 %)
Unknown 24 24 0

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have some questions.

I have a general concern for lack of unit tests. I understand that we're testing the end-to-end flow, but for any new given class like StoryValidator I'd expect to see a StoryValidator.test.ts that checks the basics at the very least.

@@ -12,8 +11,7 @@ prologues:
director: Bennett Miller
title: Moneyball
year: 2011
response:
status: 201
status: [201]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this return an array?

Copy link
Collaborator Author

@nhtruong nhtruong Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prologues and epilogues, we don't evaluate any spec but rather simply run the HTTP requests to setup and tear down. By default, the framework accepts status: [200, 201] as okay and other codes will make the prologue or epilogue return an error. So in this case in particular, we could have omitted status. Specifying status is usually for when cleanup where we want to delete a resource created in one of the chapters but we want to account for 404 where the resource was not created successfully. In this case, it's usually status: [200, 404]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added unit tests for StoryValidator

@@ -29,15 +29,17 @@ export class ConsoleResultLogger implements ResultLogger {
}

log (evaluation: StoryEvaluation): void {
const with_padding = [Result.FAILED, Result.ERROR].includes(evaluation.result) || this._verbose
if(with_padding) console.log()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of space after if looks suspicious, missing linter?

Copy link
Collaborator Author

@nhtruong nhtruong Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue with the previous PR: the rule was moved into a plugin.
I've resolved it.

@@ -32,7 +32,7 @@ export default class SchemaValidator {
validate (schema: OpenAPIV3.SchemaObject, data: any): Evaluation {
const validate = this.ajv.compile(schema)
const valid = validate(data)
if (! valid) {
if (!valid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing lint?

Copy link
Collaborator Author

@nhtruong nhtruong Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue with the previous PR: the rule was moved into a plugin.
I've resolved it.

private readonly validate_schema: ValidateFunction

constructor() {
this.ajv = new Ajv2019({ allErrors: true, strict: false })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use plain ajv elsewhere, why is this using a different one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the use of unevaluatedProperties, which is a new feature in JSON Schema draft 2019-09. We use this in test_story.schema to enable additionalProperties: false for allOf objects. This was how I caught this infraction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we upgrade all schema checks?

Validating stories before running them.

Signed-off-by: Theo Truong <[email protected]>
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it to green and it’s good to go.

Whitesource hmmm?

@dblock dblock merged commit 6081d1a into opensearch-project:main Jun 26, 2024
8 of 9 checks passed
@nhtruong nhtruong deleted the validate_stories branch June 26, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Validate test story schema.
2 participants