more unit tests

This commit is contained in:
Klemek
2021-04-04 23:24:33 +02:00
parent 404b02830d
commit c3e53c7df8
2 changed files with 70 additions and 23 deletions
+11 -9
View File
@@ -16,21 +16,23 @@ module.exports = (config) => {
};
const fetchList = (cb) => {
const file = fs.createWriteStream(config['robots']['list_file']);
https.get(config['robots']['list_url'], (res) => {
res.pipe(file);
file.on('finish', () => {
file.close(cb);
});
if (res.statusCode !== 200) {
cb(res.statusCode);
} else {
const file = fs.createWriteStream(config['robots']['list_file']);
res.pipe(file);
file.on('finish', () => {
file.close(cb);
});
}
}).on('error', (err) => {
file.close(() => {
cb(err.message);
});
cb(err.message);
});
};
const readFile = (cb) => {
fs.readFile(config['robots']['list_file'], (err, data) => {
fs.readFile(config['robots']['list_file'], { encoding: 'utf-8' }, (err, data) => {
if (err) {
cb(err, undefined);
} else {