mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
fix(Variables): Support empty string environment variables (#11629)
This commit is contained in:
parent
968ddd5994
commit
022db9c8a3
@ -21,8 +21,11 @@ module.exports = {
|
||||
errorCode: 'INVALID_ENV_SOURCE_ADDRESS',
|
||||
});
|
||||
|
||||
if (!process.env[address]) missingEnvVariables.add(address);
|
||||
return { value: process.env[address] || null, isPending: !isSourceFulfilled };
|
||||
if (process.env[address] == null) missingEnvVariables.add(address);
|
||||
return {
|
||||
value: process.env[address] == null ? null : process.env[address],
|
||||
isPending: !isSourceFulfilled,
|
||||
};
|
||||
},
|
||||
missingEnvVariables,
|
||||
};
|
||||
|
||||
@ -12,9 +12,11 @@ describe('test/unit/lib/configuration/variables/sources/env.test.js', () => {
|
||||
let variablesMeta;
|
||||
before(async () => {
|
||||
process.env.ENV_SOURCE_TEST = 'foobar';
|
||||
process.env.ENV_SOURCE_TEST_EMPTY = '';
|
||||
configuration = {
|
||||
env: '${env:ENV_SOURCE_TEST}',
|
||||
envMissing: "${env:ENV_SOURCE_TEST_MISSING, 'fallback'}",
|
||||
envEmpty: '${env:ENV_SOURCE_TEST_EMPTY}',
|
||||
noAddress: '${env:}',
|
||||
nonStringAddress: '${env:${self:someObject}}',
|
||||
someObject: {},
|
||||
@ -34,6 +36,9 @@ describe('test/unit/lib/configuration/variables/sources/env.test.js', () => {
|
||||
it('should resolve null on missing environment variable', () =>
|
||||
expect(configuration.envMissing).to.equal('fallback'));
|
||||
|
||||
it('should resolve environment variable that is empty', () =>
|
||||
expect(configuration.envEmpty).to.equal(''));
|
||||
|
||||
it('should report with an error missing address argument', () =>
|
||||
expect(variablesMeta.get('noAddress').error.code).to.equal('VARIABLE_RESOLUTION_ERROR'));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user