Skip to content

Commit 8f03171

Browse files
authored
Merge pull request #351 from serverless-operations/feature/handle_empty_tag_values
fix: handle empty tag values
2 parents 9cb9272 + 8c0426b commit 8f03171

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/deploy/stepFunctions/compileStateMachines.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function toTags(obj) {
2222
return tags;
2323
}
2424

25-
_.forEach(obj, (Value, Key) => tags.push({ Key, Value: Value.toString() }));
25+
_.forEach(obj, (Value, Key) => {
26+
tags.push({ Key, Value: (Value || '').toString() });
27+
});
2628

2729
return tags;
2830
}

lib/deploy/stepFunctions/compileStateMachines.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,45 @@ describe('#compileStateMachines', () => {
630630
expect(() => serverlessStepFunctions.compileStateMachines()).to.throw(Error);
631631
});
632632

633+
it('should leave empty tag values as empty string', () => {
634+
serverless.service.provider.tags = {
635+
team: undefined,
636+
};
637+
638+
serverless.service.stepFunctions = {
639+
stateMachines: {
640+
myStateMachine1: {
641+
definition: 'definition1',
642+
name: 'stateMachineBeta1',
643+
tags: {
644+
score: undefined,
645+
},
646+
},
647+
myStateMachine2: {
648+
definition: 'definition2',
649+
name: 'stateMachineBeta2',
650+
tags: {
651+
score: undefined,
652+
},
653+
},
654+
},
655+
};
656+
657+
serverlessStepFunctions.compileStateMachines();
658+
const stateMachineBeta1 = serverlessStepFunctions.serverless.service
659+
.provider.compiledCloudFormationTemplate.Resources
660+
.StateMachineBeta1;
661+
const stateMachineBeta2 = serverlessStepFunctions.serverless.service
662+
.provider.compiledCloudFormationTemplate.Resources
663+
.StateMachineBeta2;
664+
expect(stateMachineBeta1.Properties.Tags).to.have.lengthOf(2);
665+
expect(stateMachineBeta2.Properties.Tags).to.have.lengthOf(2);
666+
expect(stateMachineBeta1.Properties.Tags)
667+
.to.deep.eq([{ Key: 'team', Value: '' }, { Key: 'score', Value: '' }]);
668+
expect(stateMachineBeta2.Properties.Tags)
669+
.to.deep.eq([{ Key: 'team', Value: '' }, { Key: 'score', Value: '' }]);
670+
});
671+
633672
it('should respect CloudFormation intrinsic functions', () => {
634673
serverless.service.stepFunctions = {
635674
stateMachines: {

0 commit comments

Comments
 (0)