OSDN Git Service

[TEST] eos execution parameter check done. v0.3.0p0034
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Wed, 3 Feb 2016 19:16:24 +0000 (04:16 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Wed, 3 Feb 2016 19:16:24 +0000 (04:16 +0900)
server/class/Eos.js
test/mocha/Eos.test.js
test/mocha/testCommand.json [new file with mode: 0644]

index 202b00a..2e6fb10 100644 (file)
@@ -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();
+        })
     });
-    */
 }
 
 /**
index 48fce03..0ec03a7 100644 (file)
@@ -8,6 +8,7 @@
     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';
             });
         });
     });
diff --git a/test/mocha/testCommand.json b/test/mocha/testCommand.json
new file mode 100644 (file)
index 0000000..4ac1150
--- /dev/null
@@ -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
+            ]
+        }
+    ]
+}