From f60978c41a5773ad97f709f06bc852d3930be6e3 Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Tue, 7 Jul 2015 14:22:17 -0400 Subject: [PATCH 1/2] Update for capturing env vars without values. --- .../directives/service-definition-edit.js | 28 ++++++++++++------- .../directives/service-definition-edit.js | 23 +++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/scripts/directives/service-definition-edit.js b/app/scripts/directives/service-definition-edit.js index c194586..b22d98c 100644 --- a/app/scripts/directives/service-definition-edit.js +++ b/app/scripts/directives/service-definition-edit.js @@ -101,20 +101,28 @@ // favor the ':' syntax when mixed chars ae present if (item !== '') { var subval = '', subkey = ''; - var index = item.indexOf(':'); - // if incoming value has : syntax - if ( index !== -1) { - subkey = item.substring(0, index); - subval = item.substring(index+1, item.length); + // if incoming value has neither : nor = e.g. DOCKER_HOST + if (item.indexOf(':') === -1 && item.indexOf('=') === -1) { + obj[item] = null; } else { - // if incoming value has = syntax - subval = ''; subkey = ''; - index = item.indexOf('='); + // if incoming value has : syntax + var index = item.indexOf(':'); if ( index !== -1) { subkey = item.substring(0, index); subval = item.substring(index+1, item.length); - } } - obj[subkey] = subval; + subval = subval === 'null' ? null : subval; + } else { + // if incoming value has = syntax + subval = ''; subkey = ''; + index = item.indexOf('='); + if ( index !== -1) { + subkey = item.substring(0, index); + subval = item.substring(index+1, item.length); + subval = subval === 'null' ? null : subval; + } + } + obj[subkey] = subval; + } // If items for the environment key was marked for deletion // substitute the index no. by the actual key var envTracker = $rootScope.markAsDeletedTracker.environment; diff --git a/test/spec/directives/service-definition-edit.js b/test/spec/directives/service-definition-edit.js index 060d097..fb288f7 100644 --- a/test/spec/directives/service-definition-edit.js +++ b/test/spec/directives/service-definition-edit.js @@ -475,6 +475,29 @@ describe('Directive: serviceDefinitionEdit', function () { expect(result).toEqual(scope.fullJson[scope.sectionName]); }); + }); + describe('and has special seq values for environment key', function () { + var editableJson = [ + {name: 'build', value: 'foo'}, + {name: 'environment', value: ['DOCKER_HOST', 'flip=', 'dash:', 'constraint:node==swarm-master']} + ]; + beforeEach(function () { + scope.sectionName = 'adapter'; + scope.fullJson = { + 'adapter': { + 'build': 'foo', + 'environment': {'DOCKER_HOST': null, 'flip': '', 'dash': '', 'constraint': 'node==swarm-master'} + } + }; + element = compile('')(scope); + scope.$digest(); + }); + + it('returns valid yamlDocument fragment', function () { + var result = element.isolateScope().transformToYamlDocumentFragment(editableJson); + expect(result).toEqual(scope.fullJson[scope.sectionName]); + }); + }); describe('and environment key items are marked for deletion', function () { From c0dfdb8265e8e3a7cfc40ceeef48bada4a0547e2 Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Tue, 7 Jul 2015 14:25:50 -0400 Subject: [PATCH 2/2] Fix for capturing env vars with == like the constraint value. --- app/scripts/directives/service-definition-edit.js | 4 ++-- test/spec/directives/service-definition-edit.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/directives/service-definition-edit.js b/app/scripts/directives/service-definition-edit.js index b22d98c..ab54037 100644 --- a/app/scripts/directives/service-definition-edit.js +++ b/app/scripts/directives/service-definition-edit.js @@ -316,8 +316,8 @@ valueArr.push(lk+':'+lv); }); } else { - // ['ENV_KEY_1=some value'] -> ['ENV_KEY_1:some value'] - valueArr.push(lvalue.replace('=', ':')); + // ['ENV_KEY_1=some value'] -> don't change + valueArr.push(lvalue); } }); } diff --git a/test/spec/directives/service-definition-edit.js b/test/spec/directives/service-definition-edit.js index fb288f7..b491f89 100644 --- a/test/spec/directives/service-definition-edit.js +++ b/test/spec/directives/service-definition-edit.js @@ -372,7 +372,7 @@ describe('Directive: serviceDefinitionEdit', function () { describe('when yaml json has environment keys with seq values', function () { var editableJson = [ - { name: 'environment', value: ['foo:bar', 'flip:flop']}, + { name: 'environment', value: ['foo=bar', 'flip=flop']}, { name: 'build', value: 'bar'} ]; beforeEach(function () {