Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed tmp dir used for arch validation. Fixes #929 #930

Merged
merged 13 commits into from
Dec 20, 2016
11 changes: 7 additions & 4 deletions src/plugins/ValidateArchitecture/ValidateArchitecture.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ define([
'q',
'fs',
'path',
'child_process'
'child_process',
'rimraf'
], function (
PluginBase,
SimpleNodeConstants,
pluginMetadata,
Q,
fs,
path,
childProcess
childProcess,
rm_rf
) {
'use strict';

Expand Down Expand Up @@ -111,8 +113,9 @@ define([

ValidateArchitecture.prototype.validateLayers = function (layerTests) {
return Q.all(layerTests.map(layer => this.validateLayer(layer[0], layer[1])))
.then(results => results.filter(result => !!result));
// TODO: Remove tmp files
.then(results => Q.nfcall(rm_rf, this._tmpFileId)
.then(() => results.filter(result => !!result))
);
};

ValidateArchitecture.prototype.validateLayer = function (id, code) {
Expand Down
99 changes: 50 additions & 49 deletions test/cli/cli.spec.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
var mockery = require('mockery'),
assert = require('assert'),
path = require('path'),
nop = () => {},
cli;

var callRegister = {
childProcess: {
execSync: []
}
};

var mocks = {
childProcess: {},
rimraf: {}
};

var childProcess = {
execSync: function(cmd) {
callRegister.childProcess.execSync.push(cmd);
if (mocks.childProcess.execSync) {
return mocks.childProcess.execSync.apply(this, arguments);
describe('cli', function() {
var mockery = require('mockery'),
assert = require('assert'),
path = require('path'),
nop = () => {},
cli;

var callRegister = {
childProcess: {
execSync: []
}
},
spawnSync: function(cmd) {
if (cmd === 'luarocks') {
};

var mocks = {
childProcess: {},
rimraf: {}
};

var childProcess = {
execSync: function(cmd) {
callRegister.childProcess.execSync.push(cmd);
if (mocks.childProcess.execSync) {
return mocks.childProcess.execSync.apply(this, arguments);
}
},
spawnSync: function(cmd) {
if (cmd === 'luarocks') {
return {
stdout: 'rnn'
};
}
return {};
},
spawn: function() {
if (mocks.childProcess.spawn) {
mocks.childProcess.spawn.apply(this, arguments);
}
return {
stdout: 'rnn'
on: () => {},
stdout: {
on: () => {}
},
stderr: {
on: () => {}
}
};
}
return {};
},
spawn: function() {
if (mocks.childProcess.spawn) {
mocks.childProcess.spawn.apply(this, arguments);
};
var rimraf = {};
rimraf.sync = function() {
if (mocks.rimraf.sync) {
mocks.rimraf.sync.apply(this, arguments);
}
return {
on: () => {},
stdout: {
on: () => {}
},
stderr: {
on: () => {}
}
};
}
};
var rimraf = {};
rimraf.sync = function() {
if (mocks.rimraf.sync) {
mocks.rimraf.sync.apply(this, arguments);
}
};
};


describe('cli', function() {
before(function() {
// create the mocks
mockery.enable({
Expand Down
33 changes: 32 additions & 1 deletion test/plugins/ValidateArchitecture/ValidateArchitecture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var testFixture = require('../../globals');
describe('ValidateArchitecture', function () {
var gmeConfig = testFixture.getGmeConfig(),
expect = testFixture.expect,
fs = require('fs'),
rm_rf = require('rimraf'),
mockery = require('mockery'),
logger = testFixture.logger.fork('ValidateArchitecture'),
PluginCliManager = testFixture.WebGME.PluginCliManager,
manager = new PluginCliManager(null, logger, gmeConfig),
Expand Down Expand Up @@ -64,6 +67,7 @@ describe('ValidateArchitecture', function () {
return manager.initializePlugin(pluginName)
.then(plugin_ => {
plugin = plugin_;
plugin.setTorchInstalled(true);
return manager.configurePlugin(plugin, {}, context);
})
.nodeify(done);
Expand All @@ -85,6 +89,33 @@ describe('ValidateArchitecture', function () {
});
});

it('should make tmp dir', function(done) {
var oldMkdir = fs.mkdir;
fs.mkdir = (dir, cb) => {
expect(dir).to.equal(plugin._tmpFileId);
return oldMkdir(dir, cb);
};
plugin.main(() => {
fs.mkdir = oldMkdir;
done();
});
});

it('should rm tmp dir', function(done) {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
});
mockery.registerMock('rimraf', (dir, cb) => {
expect(dir).to.equal(plugin._tmpFileId);
return rm_rf(dir, cb);
});
plugin.main(() => {
mockery.disable();
done();
});
});

// check that errors are returned in the message
it('should return two error messages', function(done) {
plugin.validateLayer = (id, code) => {
Expand All @@ -99,7 +130,7 @@ describe('ValidateArchitecture', function () {
};
plugin.main((err, result) => {
var invalidLayers = result.messages[0].message.errors.map(msg => msg.id);
expect(invalidLayers.length).to.equal(2);
expect(result.messages[0]).to.not.equal(undefined);
done();
});
});
Expand Down