if(options.length === 0) {
var errorMsg = 'At least one option is required.';
throw new Error(errorMsg);
+ } else {
+ resolve();
}
});
}
// do validation
return Promise.all(promises)
- .then(function() {
- resolve('Success');
- })
- .catch(function(error) {
- reject(error);
- });
- });
- });
- /*
- var invalidArgumentType = [];
- var invalidOutputFileName = [];
-
- // output file Regexp
- var outRegExp = /out|append/;
-
- options.forEach(function(o) {
- // outFile name
- if(outRegExp.test(ocfObj[o.name].arg[i].argType)) {
- if(workspace.indexOf(o.arguments[i]) > -1) {
- invalidOutputFileName.push({name: o.name, file: arg});
- }
- }
- });
- });
-
- // check arguments number value
- if(invalidArgumentsNumber.length > 0) {
- errorMsg = '"arguments" properties is invalid number.\n';
- invalidArgumentsNumber.forEach(function(i) {
- errorMsg += i.name + ' expect to ' + i.expect + ', but actual ' + i.actual + '.\n';
- });
- throw new Error(errorMsg);
- }
-
- // check arguments type
- if(invalidArgumentType.length > 0) {
- errorMsg = '"arguments" type is invalid.\n';
- invalidArgumentType.forEach(function(i) {
- if(i.file) {
- errorMsg += i.name + ' ' + i.file + ' does not exist.\n';
- } else {
- errorMsg += i.name + ' expect to ' + i.expect + ', but actual ' + i.actual + '.\n';
- }
- });
- throw new Error(errorMsg);
- }
-
- // check outFile name
- if(invalidOutputFileName.length > 0) {
- errorMsg = 'output file name is invalid.\n';
- invalidOutputFileName.forEach(function(i) {
- errorMsg += i.name + ' ' + i.file + ' has already existed.\n';
- });
- throw new Error(errorMsg);
- }
- } catch(e) {
- result.message = e.message;
- return result;
- }
+ })
+ .catch(function(error) {
+ reject(error);
+ })
+ .then(function(r) {
+ resolve();
+ })
});
- */
}
/**
chai.should();
var db = require('../../server/class/DB').instance;
+ var testCommand = require('./testCommand.json');
var test1 = `
/**
return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file1.txt']} ]).should.be.rejectedWith(Error, 'Invalid outfile name.');
});
- /*
- describe(test2, function() {
+ });
+ describe(test2, function() {
it('should return true when all options is proper.', function() {
var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ]);
expect(result).to.equal('dcdFilePrint -r 1 2 3 -s 10 -e 100 -d 10 -m 0 -i file1.txt -o file3.txt');
});
- */
});
- describe('getFiles', function() {
- before(function() {
- process.env.NODE_ENV = '';
- return db.init()
- .then(function() {
- return Promise.all([db.test1(), db.test2(), db.testRest()])
- });
- });
-
- it('should be resolved with length 4', function() {
- return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
- });
-
- after(function() {
- process.env.NODE_ENV = 'test';
+ describe('getFiles', function() {
+ before(function() {
+ process.env.NODE_ENV = '';
+ return db.init()
+ .then(function() {
+ return Promise.all([db.test1(), db.test2(), db.testRest()])
+ });
+ });
+
+ it('should be resolved with length 4', function() {
+ return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
+ });
+
+ it('should be resolved about testCommand', function() {
+ var command = testCommand.command;
+ var options = testCommand.options;
+ var workspace = testCommand.workspace;
+ return eos.validate(command, options, workspace).should.be.fulfilled;
+ });
+
+ after(function() {
+ process.env.NODE_ENV = 'test';
});
});
});