diff --git a/tests/integration/all.js b/tests/integration/all.js index 07510c721..890912b2a 100644 --- a/tests/integration/all.js +++ b/tests/integration/all.js @@ -5,6 +5,7 @@ require('./aws/general/nested-handlers/tests'); require('./aws/general/custom-resources/tests'); require('./aws/general/overwrite-resources/tests'); +require('./aws/general/environment-variables/tests'); // API Gateway // Integration: Lambda diff --git a/tests/integration/aws/general/environment-variables/service/handler.js b/tests/integration/aws/general/environment-variables/service/handler.js new file mode 100644 index 000000000..6f5d68a82 --- /dev/null +++ b/tests/integration/aws/general/environment-variables/service/handler.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports.hello = (event, context, callback) => { + callback(null, { + environment_variables: process.env, + }); +}; diff --git a/tests/integration/aws/general/environment-variables/service/serverless.yml b/tests/integration/aws/general/environment-variables/service/serverless.yml new file mode 100644 index 000000000..727523218 --- /dev/null +++ b/tests/integration/aws/general/environment-variables/service/serverless.yml @@ -0,0 +1,17 @@ +service: aws-nodejs # NOTE: update this with your service name + +provider: + name: aws + runtime: nodejs4.3 + cfLogs: true + environment: + provider_level_variable_1: provider_level_1 + provider_level_variable_2: provider_level_2 + +functions: + hello: + handler: handler.hello + environment: + function_level_variable_1: function_level_1 + function_level_variable_2: function_level_2 + provider_level_variable_2: overwritten_by_function diff --git a/tests/integration/aws/general/environment-variables/tests.js b/tests/integration/aws/general/environment-variables/tests.js new file mode 100644 index 000000000..21d94a73f --- /dev/null +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -0,0 +1,35 @@ +'use strict'; + +const path = require('path'); +const expect = require('chai').expect; +const execSync = require('child_process').execSync; + +const Utils = require('../../../../utils/index'); + +describe('AWS - General: Environment variables test', function () { + this.timeout(0); + + before(() => { + Utils.createTestService('aws-nodejs', path.join(__dirname, 'service')); + Utils.deployService(); + }); + + it('should expose environment variables', () => { + const invoked = execSync(`${Utils.serverlessExec} invoke --function hello --noGreeting true`); + + const result = JSON.parse(new Buffer(invoked, 'base64').toString()); + + expect(result.environment_variables.provider_level_variable_1) + .to.be.equal('provider_level_1'); + expect(result.environment_variables.function_level_variable_1) + .to.be.equal('function_level_1'); + expect(result.environment_variables.function_level_variable_2) + .to.be.equal('function_level_2'); + expect(result.environment_variables.provider_level_variable_2) + .to.be.equal('overwritten_by_function'); + }); + + after(() => { + Utils.removeService(); + }); +});