mirror of
https://github.com/tiennm99/open-domains.git
synced 2026-10-11 03:13:41 +00:00
feat: more validation testing
This commit is contained in:
1 parent
78a3809e0f
commit
53ce667502
3 files changed
+70
-2
No files matched your search
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const domainsDir = path.join(__dirname, '../domains');
|
||||
|
||||
function lowercaseFilenames() {
|
||||
fs.readdir(domainsDir, (err, files) => {
|
||||
if (err) {
|
||||
console.error(`Error reading directory: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
const currentPath = path.join(domainsDir, file);
|
||||
const lowerCaseFile = file.toLowerCase();
|
||||
const lowerCasePath = path.join(domainsDir, lowerCaseFile);
|
||||
|
||||
if (file !== lowerCaseFile) {
|
||||
fs.rename(currentPath, lowerCasePath, err => {
|
||||
if (err) {
|
||||
console.error(`Error renaming file ${file}: ${err.message}`);
|
||||
} else {
|
||||
console.log(`Renamed: ${file} → ${lowerCaseFile}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Run the renamer
|
||||
lowercaseFilenames();
|
||||
+36
-1
@@ -13,7 +13,8 @@ const sectionMap = {
|
||||
1: 'Non-JSON file detection',
|
||||
2: 'JSON syntax validation',
|
||||
3: 'Owner property validation',
|
||||
4: 'Filename format validation'
|
||||
4: 'Filename format validation',
|
||||
5: 'Filename content match validation'
|
||||
};
|
||||
|
||||
function askQuestion(query) {
|
||||
@@ -182,4 +183,38 @@ function askQuestion(query) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//==================== SECTION 5: FILENAME CONTENT MATCH VALIDATION ====================//
|
||||
if (selectedSections.includes(5)) {
|
||||
fs.readdir(domainsDir, (err, files) => {
|
||||
if (err) {
|
||||
console.error(`Error reading directory: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
files
|
||||
.filter(file => file.endsWith('.json'))
|
||||
.forEach(file => {
|
||||
const filePath = path.join(domainsDir, file);
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(`Error reading file ${file}: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
const expectedFileName = `${parsed.subdomain}.${parsed.domain}.json`;
|
||||
|
||||
if (file !== expectedFileName) {
|
||||
console.warn(`❌ Filename mismatch in: ${file}`);
|
||||
console.warn(` ↪ Expected: ${expectedFileName}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`❌ Cannot parse JSON in: ${file}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
"scripts": {
|
||||
"test": "npx ava tests/*.test.js",
|
||||
"lt": "node ./localtests/test.js",
|
||||
"format": "node ./localtests/format.js"
|
||||
"format": "node ./localtests/format.js",
|
||||
"lowercase": "node ./localtests/lowercase.js"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user