From 94dd6f2d88710cba365bac9ec73b98ab4deae527 Mon Sep 17 00:00:00 2001 From: himetani_cafe Date: Thu, 4 Feb 2016 04:16:24 +0900 Subject: [PATCH 1/1] [TEST] eos execution parameter check done. --- server/class/Eos.js | 69 ++++++--------------------------------------- test/mocha/Eos.test.js | 43 ++++++++++++++++------------ test/mocha/testCommand.json | 44 +++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 78 deletions(-) create mode 100644 test/mocha/testCommand.json diff --git a/server/class/Eos.js b/server/class/Eos.js index 202b00a..2e6fb10 100644 --- a/server/class/Eos.js +++ b/server/class/Eos.js @@ -42,6 +42,8 @@ function hasOneProperty(options) { if(options.length === 0) { var errorMsg = 'At least one option is required.'; throw new Error(errorMsg); + } else { + resolve(); } }); } @@ -182,67 +184,14 @@ function validate(command, options, workspaceId) { // 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(); + }) }); - */ } /** diff --git a/test/mocha/Eos.test.js b/test/mocha/Eos.test.js index 48fce03..0ec03a7 100644 --- a/test/mocha/Eos.test.js +++ b/test/mocha/Eos.test.js @@ -8,6 +8,7 @@ chai.should(); var db = require('../../server/class/DB').instance; + var testCommand = require('./testCommand.json'); var test1 = ` /** @@ -83,31 +84,37 @@ 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'; }); }); }); diff --git a/test/mocha/testCommand.json b/test/mocha/testCommand.json new file mode 100644 index 0000000..4ac1150 --- /dev/null +++ b/test/mocha/testCommand.json @@ -0,0 +1,44 @@ +{ + "command": "dcdFilePrint", + "workspace": "1f83f620-c1ed-11e5-9657-7942989daa00", + "options": [ + { + "name": "-i", + "arguments": [ + "debugRest.mrc" + ] + }, + { + "name": "-o", + "arguments": [ + "fsdafsadfasd" + ] + }, + { + "name": "-r", + "arguments": [ + 10, + 100, + 10 + ] + }, + { + "name": "-s", + "arguments": [ + 10 + ] + }, + { + "name": "-e", + "arguments": [ + 100 + ] + }, + { + "name": "-d", + "arguments": [ + 10 + ] + } + ] +} -- 2.11.0