res.send(info);
})
.then(function() {
- return eos.toExecString(command, options, workspace);
- })
- .then(function(execStr) {
+ return eos.execute(command, options, workspace);
+ .then(function(result) {
console.log(execStr);
var info = {
status: 'success',
-
-/**
- * Eosコマンドをエミュレートするクラス
- * @varructor
- * @returns {object}
- * function execute(command, params) {
- */
-var eos = {
- validate: validate,
- toExecString: toExecString,
- execute: execute,
- getFiles: getFiles
-}
-
-
/**
*
* Class variables
commandList.forEach(function(c) {
ocfReference[c.name] = require(__dirname + '/../../user-specific-files/OptionControlFile/commands/' + c.name);
});
+var spawn = require('child_process').spawn;
-// for unit test
-
-
-/**
- *
- * Class variables
- */
-
function hasOneProperty(options) {
return new Promise(function(resolve, reject) {
if(options.length === 0) {
* @param params
* @returns {object}
*/
-function execute(command, options) {
- var result = validate(command, options);
- if(!result.hasDone) {
- } else {
- var str = toExecString(command, options);
- }
+function execute(str) {
+ return new Promise(function(resolve, reject) {
+ exec(str);
+
+ });
}
/**
});
}
+/**
+ * getUUID
+ * @param fileId
+ * @returns {object} key: filename, value: uuid
+ */
+function getUUIDs(fileId) {
+ return new Promise(function(resolve) {
+ db.getFiles(fileId)
+ .then(function(r) {
+ var uuids = {};
+ r.forEach(function(v) {
+ uuids[v.dataValues.name] = v.dataValues.fileId;
+ //console.log(uuids);
+ });
+ resolve(uuids);
+ });
+ });
+}
+
+/**
+ * Eosコマンドをエミュレートするクラス
+ * @varructor
+ * @returns {object}
+ * function execute(command, params) {
+ */
+var eos = {
+ validate: validate,
+ toExecString: toExecString,
+ execute: execute,
+ getFiles: getFiles,
+ getUUIDs: getUUIDs
+}
+
module.exports = { instance: eos };
*/
`;
- var test2 = `
- /**
- * 実行時文字列への変換
- *
- * @param command
- * @param options
- * @returns {string}
- * function toExecString(command, params) {
- */
- `;
-
+
describe('Eos クラス', function() {
before(function() {
});
});
});
+ var test2 = `
+ /**
+ * 実行時文字列への変換
+ *
+ * @param command
+ * @param options
+ * @returns {string}
+ * function toExecString(command, params) {
+ */
+ `;
+
+
+ describe('execute', 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';
+ });
+ });
+
describe('getFiles', function() {
before(function() {
process.env.NODE_ENV = '';
process.env.NODE_ENV = 'test';
});
});
+
+ var getUUIDs = `
+ /**
+ * function getUUIDs(fileId)
+ * uuidとファイル名のkey-valueを取得
+ *
+ * @param fileId
+ * @returns {object} key: filename, value: uuid
+ */
+ `;
+
+ describe(getUUIDs, 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', function() {
+ return eos.getUUIDs('1f83f620-c1ed-11e5-9657-7942989daa00').should.eventually.have.property("hoge.txt");
+ });
+ });
});
})();
--- /dev/null
+var options = require('./testCommand.json').options;
+
+var array = options.reduce(function(a,b) {
+ a.push(b.name);
+ b.arguments.forEach(function(v) {
+ return a.push(v);
+ });
+ return a;
+},[]);
+
+console.log(array);