Skip to content
Permalink
Browse files

Merge 4eb3012 into bb54c3b

  • Loading branch information
horike37 committed Jul 29, 2018
2 parents bb54c3b + 4eb3012 commit 04cab15a9d433e0268e85954d3658f2eb1d3a9ce
@@ -164,9 +164,9 @@ class AwsDeployFunction {
const errorMessage = 'Invalid characters in environment variable';
throw new this.serverless.classes.Error(errorMessage);
}

if (!_.isString(params.Environment.Variables[key])) {
const errorMessage = `Environment variable ${key} must contain strings`;
throw new this.serverless.classes.Error(errorMessage);
params.Environment.Variables[key] = _.toString(params.Environment.Variables[key]);
}
});
}
@@ -353,19 +353,35 @@ describe('AwsDeployFunction', () => {
expect(() => awsDeployFunction.updateFunctionConfiguration()).to.throw(Error);
});

it('should fail when using non-string values as environment variables', () => {
options.functionObj = {
name: 'first',
description: 'change',
environment: {
COUNTER: 6,
},
};

awsDeployFunction.options = options;

expect(() => awsDeployFunction.updateFunctionConfiguration()).to.throw(Error);
});
it('should transform to string values when using non-string values as environment variables',
() => {
options.functionObj = {
name: 'first',
description: 'change',
environment: {
COUNTER: 6,
},
};

awsDeployFunction.options = options;
return expect(awsDeployFunction.updateFunctionConfiguration()).to.be.fulfilled
.then(() => {
expect(updateFunctionConfigurationStub.calledOnce).to.be.equal(true);
expect(updateFunctionConfigurationStub.calledWithExactly(
'Lambda',
'updateFunctionConfiguration',
{
FunctionName: 'first',
Description: 'change',
Environment: {
Variables: {
COUNTER: '6',
},
},
}
)).to.be.equal(true);
});
});

it('should inherit provider-level config', () => {
options.functionObj = {
@@ -260,11 +260,13 @@ class AwsCompileFunctions {
return false; // break loop with lodash
}
const value = newFunction.Properties.Environment.Variables[key];
const isCFRef = _.isObject(value) &&
!_.some(value, (v, k) => k !== 'Ref' && !_.startsWith(k, 'Fn::'));
if (!isCFRef && !_.isString(value)) {
invalidEnvVar = `Environment variable ${key} must contain string`;
return false;
if (_.isObject(value)) {
const isCFRef = _.isObject(value) &&
!_.some(value, (v, k) => k !== 'Ref' && !_.startsWith(k, 'Fn::'));
if (!isCFRef) {
invalidEnvVar = `Environment variable ${key} must contain string`;
return false;
}
}
}
);
@@ -1456,7 +1456,7 @@ describe('AwsCompileFunctions', () => {
return expect(awsCompileFunctions.compileFunctions()).to.be.rejectedWith(Error);
});

it('should throw an error if environment variable is not a string', () => {
it('should accept an environment variable with a not-string value', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
@@ -1467,7 +1467,13 @@ describe('AwsCompileFunctions', () => {
},
};

return expect(awsCompileFunctions.compileFunctions()).to.be.rejectedWith(Error);
return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled
.then(() => {
expect(awsCompileFunctions.serverless.service.provider
.compiledCloudFormationTemplate
.Resources.FuncLambdaFunction.Properties.Environment.Variables.counter
).to.equal(18);
});
});

it('should accept an environment variable with CF ref and functions', () => {

0 comments on commit 04cab15

Please sign in to comment.
You can’t perform that action at this time.