Skip to content

Commit

Permalink
Add verification;clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Weigel committed Jan 14, 2019
1 parent 73db518 commit 092ae0e
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions test/server-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
var fs = require('fs');
var path = require("path");
var clc = require('chalk');
var spawnSync = require('child_process').spawnSync;
const fs = require('fs');
const path = require("path");
const clc = require('chalk');
const spawnSync = require('child_process').spawnSync;

const nodeexe = process.execPath + " server.js";
const metadir = __dirname + '/../metadata';

const excludes =
[
Expand All @@ -12,32 +15,48 @@ const excludes =
"TestDataBad"
];

var exe = process.execPath + " server.js";

const metadir = __dirname + '/../metadata';
files = [];
fs.readdirSync(metadir).forEach(file => {
var ext = path.extname(file);
var basename = path.basename(file,'.json');
if (ext == ".json" && !excludes.includes(basename)) {
files.push(file);
}
})

var fails = 0;
for (var i = 0; i < files.length; i++) {
var com = exe + " --test --ignore -f " + metadir + "/" + files[i];
function execute(com) {
process.stdout.write(clc.blue("Testing: ") + com);
var child = spawnSync('bash', ['-c', com], {stdio: 'pipe'});
let child = spawnSync('bash', ['-c', com], {stdio: 'pipe'});
let status = 0;
if (child.status == 0) {
console.log(clc.green(" PASS"));
status = 0;
console.log(clc.green.bold(" PASS"));
} else {
fails = fails + 1;
console.log(clc.red(" FAIL"));
status = 1;
console.log(clc.red.bold(" FAIL"));
console.log("\n" + child.stdout.toString());
console.log("\n" + child.stderr.toString());
}
return status;
}

function filelist(metadir, excludes) {
let files = [];
fs.readdirSync(metadir).forEach(file => {
let ext = path.extname(file);
let basename = path.basename(file,'.json');
if (ext == ".json" && !excludes.includes(basename)) {
files.push(file);
}
})
return files;
}


files = filelist(metadir, excludes);

let fails = 0;
for (var i = 0; i < files.length; i++) {
// Run node server.js --test -f metadata/CATALOG.json
let comt = nodeexe + " --test -f " + metadir + "/" + files[i];
fails = fails + execute(comt);

// Run node server.js --verify -f metadata/CATALOG.json
let comv = nodeexe + " --verify -f " + metadir + "/" + files[i];
fails = fails + execute(comv);
}

if (fails == 0) {
process.exit(0);
} else {
Expand Down

0 comments on commit 092ae0e

Please sign in to comment.