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

Validation for test csv formats #980

Merged
merged 8 commits into from
Aug 23, 2023
Merged
Prev Previous commit
Next Next commit
add check for consistent columns count in CSVs
  • Loading branch information
gnarf committed Aug 16, 2023
commit 69473881312aa16e3a93bab7469ffb26c4c9fdc2
12 changes: 10 additions & 2 deletions lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,26 @@ ${rows}
const rawCSV = await readCSV(testPlanRecord.find(filePath));
let index = 0;
function printError(message) {
// line number is index+2
log.warning(
`WARNING: Error parsing ${path.join(testPlanDirectory, filePath)} row ${
index + 1
`WARNING: Error parsing ${path.join(testPlanDirectory, filePath)} line ${
index + 2
}: ${message}`
);
}
try {
const firstRowKeysLength = Object.keys(rawCSV[0]).length;
for (; index < rawCSV.length; index++) {
if (!rowValidator(rawCSV[index])) {
printError('validator returned false result');
Copy link
Contributor

Choose a reason for hiding this comment

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

The validators signal failure by throwing errors, so this branch seems unreachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this was a secondary idea to catch any other validation situation, then I made it throw errors for better output. I still think an undefined or falsy result from this "validator" should be an error, though none of our code is using this path currently

return;
}
const keysLength = Object.keys(rawCSV[index]).length;
if (keysLength != firstRowKeysLength) {
gnarf marked this conversation as resolved.
Show resolved Hide resolved
printError(
`column number mismatch, please include empty commas to match headers. Expected ${firstRowKeysLength} columns, found ${keysLength}`
);
}
}
} catch (err) {
printError(err);
Expand Down