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

Add schema validation support for tests #215

Closed
wants to merge 17 commits into from

Conversation

marchuffnagle
Copy link
Contributor

No description provided.

Copy link
Contributor

@scisco scisco left a comment

Choose a reason for hiding this comment

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

posted a question

"properties": {
"useQueue": {
"type": "boolean"
},
"provider": {
"type": "object",
"required": [ "protocol" ],
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also require the host?

* @returns {boolean} - whether the object is valid or not
*/
async function validateOutput(t, data) {
return validateJSON(t, './schemas/input.json', data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be output.json

* @returns {boolean} - whether the object is valid or not
*/
async function validateJSON(t, schemaFilename, data) {
const schema = await promisedReadFile(schemaFilename, 'utf8').then(JSON.parse);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the schema file does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assumption is that you would only add this check to your test if the schema file exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to just comment the expected behavior or spit out an error in that case. I don't love that the schema locations are assumed, but think it's fine for now and we can make updates if we run into a different scenario.

* @returns {boolean} - whether the object is valid or not
*/
async function validateOutput(t, data) {
return validateJSON(t, './schemas/input.json', data);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be './schemas/output.json'

Copy link
Contributor

Choose a reason for hiding this comment

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

jinx

const schema = await promisedReadFile(schemaFilename, 'utf8').then(JSON.parse);
const ajv = new Ajv();
const valid = (new Ajv()).validate(schema, data);
if (!valid) t.fail(`input validation failed: ${ajv.errorsText()}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

input validation failed: ${ajv.errorsText()} could be ${schemaFilename} validation failed: ${ajv.errorsText()}

@scisco
Copy link
Contributor

scisco commented Feb 23, 2018

please open this PR against the master branch

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.

4 participants