fixed issue 2500

This commit is contained in:
horike37 2016-10-23 19:19:14 +09:00
parent 866ae8d01d
commit bdc5170d43
2 changed files with 9 additions and 9 deletions

View File

@ -75,9 +75,10 @@ class Variables {
populateVariable(propertyParam, matchedString, valueToPopulate) {
let property = propertyParam;
if (typeof valueToPopulate === 'string') {
property = replaceall(matchedString, valueToPopulate, property);
} else if (typeof valueToPopulate === 'number') {
property = replaceall(matchedString, String(valueToPopulate), property);
} else {
if (property !== matchedString) {
const errorMessage = [

View File

@ -155,22 +155,21 @@ describe('Variables', () => {
expect(newProperty).to.equal('my stage is dev');
});
it('should populate non string variables', () => {
it('should populate number variables as sub string', () => {
const serverless = new Serverless();
const valueToPopulate = 5;
const matchedString = '${opt:number}';
const property = '${opt:number}';
const property = 'your account number is ${opt:number}';
const newProperty = serverless.variables
.populateVariable(property, matchedString, valueToPopulate);
expect(newProperty).to.equal(5);
expect(newProperty).to.equal('your account number is 5');
});
it('should throw error if populating non string variable as sub string', () => {
it('should throw error if populating non string or non number variable as sub string', () => {
const serverless = new Serverless();
const valueToPopulate = 5;
const matchedString = '${opt:number}';
const property = 'hello ${opt:number}';
const valueToPopulate = {};
const matchedString = '${opt:object}';
const property = 'your account number is ${opt:object}';
expect(() => serverless.variables
.populateVariable(property, matchedString, valueToPopulate))
.to.throw(Error);