Skip to content

Commit

Permalink
Trim trailing whitespace in execution names. Fixes #1011 (#1012)
Browse files Browse the repository at this point in the history
* WIP #1011 Added tests for execution name creation

* WIP #1011 trim whitespace in execution name
  • Loading branch information
brollb committed Apr 16, 2017
1 parent 9fe83de commit 61fb3ca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/plugins/CreateExecution/CreateExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ define([
name,
i = 2;

basename = basename.replace(/[^\da-zA-Z_]/g, '_');
basename = basename
.replace(/^\s*/, '')
.replace(/\s*$/, '')
.replace(/[^\da-zA-Z_]/g, '_');
name = basename;

// Get a unique name wrt the tags and the other executions
Expand Down
51 changes: 37 additions & 14 deletions test/plugins/CreateExecution/CreateExecution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('CreateExecution', function () {
expect = testFixture.expect,
logger = testFixture.logger.fork('CreateExecution'),
PluginCliManager = testFixture.WebGME.PluginCliManager,
manager = new PluginCliManager(null, logger, gmeConfig),
projectName = 'testProject',
pluginName = 'CreateExecution',
project,
Expand All @@ -28,7 +29,7 @@ describe('CreateExecution', function () {
})
.then(function () {
var importParam = {
projectSeed: testFixture.path.join(testFixture.SEED_DIR, 'EmptyProject.webgmex'),
projectSeed: testFixture.path.join(testFixture.DF_SEED_DIR, 'devProject', 'devProject.webgmex'),
projectName: projectName,
branchName: 'master',
logger: logger,
Expand All @@ -53,27 +54,49 @@ describe('CreateExecution', function () {
.nodeify(done);
});

it.skip('should run plugin and update the branch', function (done) {
var manager = new PluginCliManager(null, logger, gmeConfig),
pluginConfig = {
},
context = {
var plugin,
node,
preparePlugin = function(done) {
var context = {
project: project,
commitHash: commitHash,
namespace: 'pipeline',
branchName: 'test',
activeNode: '/1'
activeNode: '/K/R/p' // hello world job
};

manager.executePlugin(pluginName, pluginConfig, context, function (err, pluginResult) {
expect(err).to.equal(null);
expect(typeof pluginResult).to.equal('object');
expect(pluginResult.success).to.equal(true);
return manager.initializePlugin(pluginName)
.then(plugin_ => {
plugin = plugin_;
return manager.configurePlugin(plugin, {}, context);
})
.then(() => node = plugin.activeNode)
.nodeify(done);
};

describe('getUniqueExecName', function() {

project.getBranchHash('test')
.then(function (branchHash) {
expect(branchHash).to.not.equal(commitHash);
before(preparePlugin);

it('should trim whitespace', function(done) {
var name = ' abc ';

plugin.getUniqueExecName(name)
.then(name => {
expect(name).to.equal('abc');
})
.nodeify(done);
});

it('should replace whitespace with _', function(done) {
var name = 'a b c';

plugin.getUniqueExecName(name)
.then(name => {
expect(name).to.equal('a_b_c');
})
.nodeify(done);
});

});
});

0 comments on commit 61fb3ca

Please sign in to comment.