-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
There was a problem hiding this 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" ], |
There was a problem hiding this comment.
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
?
packages/common/test-utils.js
Outdated
* @returns {boolean} - whether the object is valid or not | ||
*/ | ||
async function validateOutput(t, data) { | ||
return validateJSON(t, './schemas/input.json', data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be output.json
packages/common/test-utils.js
Outdated
* @returns {boolean} - whether the object is valid or not | ||
*/ | ||
async function validateJSON(t, schemaFilename, data) { | ||
const schema = await promisedReadFile(schemaFilename, 'utf8').then(JSON.parse); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
packages/common/test-utils.js
Outdated
* @returns {boolean} - whether the object is valid or not | ||
*/ | ||
async function validateOutput(t, data) { | ||
return validateJSON(t, './schemas/input.json', data); |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jinx
…asa/cumulus into UpdateDiscoverGranules
packages/common/test-utils.js
Outdated
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()}`); |
There was a problem hiding this comment.
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()}
Also refactored granule ingestFile method
please open this PR against the master branch |
No description provided.