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
special error for numeric key format
  • Loading branch information
gnarf committed Aug 23, 2023
commit 7b671cee651e396f9c9cf90420ba5978e8ded4f9
19 changes: 13 additions & 6 deletions lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,16 @@ ${rows}
try {
const firstRowKeysLength = Object.keys(rawCSV[0]).length;
for (; index < rawCSV.length; index++) {
if (!rowValidator(rawCSV[index])) {
printError('validator returned false result');
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 cells to match headers. Expected ${firstRowKeysLength} columns, found ${keysLength}`
);
}
if (!rowValidator(rawCSV[index])) {
printError('validator returned false result');
return;
}
}
} catch (err) {
printError(err);
Expand All @@ -635,12 +635,16 @@ ${rows}
}

const validCommandKeys = /^(?:testId|task|mode|at|command[A-Z])$/;
const numericKeyFormat = /^_(\d+)$/;
function validateCommandsKeys(row) {
// example header:
// testId,task,mode,at,commandA,commandB,commandC,commandD,commandE,commandF
for (const key of Object.keys(row)) {
if (!validCommandKeys.test(key))
if (numericKeyFormat.test(key)) {
throw new Error(`Column found without header row, ${+key.substring(1) + 1}`);
} else if (!validCommandKeys.test(key)) {
throw new Error(`Unknown commands.csv key: ${key} - check header row?`);
}
}
if (
!(
Expand All @@ -662,8 +666,11 @@ ${rows}
// example header:
// testId,title,appliesTo,mode,task,setupScript,setupScriptDescription,refs,instructions,assertion1,assertion2,assertion3,assertion4,assertion5,assertion6,assertion7
for (const key of Object.keys(row)) {
if (!validTestsKeys.test(key))
if (numericKeyFormat.test(key)) {
throw new Error(`Column found without header row, ${+key.substring(1) + 1}`);
} else if (!validTestsKeys.test(key)) {
throw new Error(`Unknown tests.csv key: ${key} - check header row?`);
}
}
if (
!(
Expand Down