From 494902ae8387ea503bf9459cc98843e3ef786004 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 21 Nov 2016 10:17:47 +0100 Subject: [PATCH 1/2] Add environment variables integration test --- tests/integration/all.js | 1 + .../environment-variables/service/handler.js | 8 +++++ .../service/serverless.yml | 14 +++++++++ .../general/environment-variables/tests.js | 29 +++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 tests/integration/aws/general/environment-variables/service/handler.js create mode 100644 tests/integration/aws/general/environment-variables/service/serverless.yml create mode 100644 tests/integration/aws/general/environment-variables/tests.js 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..f37f22e33 --- /dev/null +++ b/tests/integration/aws/general/environment-variables/service/handler.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports.hello = (event, context, callback) => { + callback(null, { + provider_level_variable: process.env.provider_level_variable, + function_level_variable: process.env.function_level_variable, + }); +}; 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..2f006e000 --- /dev/null +++ b/tests/integration/aws/general/environment-variables/service/serverless.yml @@ -0,0 +1,14 @@ +service: aws-nodejs # NOTE: update this with your service name + +provider: + name: aws + runtime: nodejs4.3 + cfLogs: true + environment: + provider_level_variable: provider_level + +functions: + hello: + handler: handler.hello + environment: + function_level_variable: function_level 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..a68c06d55 --- /dev/null +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -0,0 +1,29 @@ +'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.provider_level_variable).to.be.equal('provider_level'); + expect(result.function_level_variable).to.be.equal('function_level'); + }); + + after(() => { + Utils.removeService(); + }); +}); From 01f5f943e7d2b8fad89397eed47373bfb253defd Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 21 Nov 2016 10:38:12 +0100 Subject: [PATCH 2/2] Add tests for overwriting environment variables --- .../general/environment-variables/service/handler.js | 3 +-- .../environment-variables/service/serverless.yml | 7 +++++-- .../aws/general/environment-variables/tests.js | 10 ++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/integration/aws/general/environment-variables/service/handler.js b/tests/integration/aws/general/environment-variables/service/handler.js index f37f22e33..6f5d68a82 100644 --- a/tests/integration/aws/general/environment-variables/service/handler.js +++ b/tests/integration/aws/general/environment-variables/service/handler.js @@ -2,7 +2,6 @@ module.exports.hello = (event, context, callback) => { callback(null, { - provider_level_variable: process.env.provider_level_variable, - function_level_variable: process.env.function_level_variable, + 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 index 2f006e000..727523218 100644 --- a/tests/integration/aws/general/environment-variables/service/serverless.yml +++ b/tests/integration/aws/general/environment-variables/service/serverless.yml @@ -5,10 +5,13 @@ provider: runtime: nodejs4.3 cfLogs: true environment: - provider_level_variable: provider_level + provider_level_variable_1: provider_level_1 + provider_level_variable_2: provider_level_2 functions: hello: handler: handler.hello environment: - function_level_variable: function_level + 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 index a68c06d55..21d94a73f 100644 --- a/tests/integration/aws/general/environment-variables/tests.js +++ b/tests/integration/aws/general/environment-variables/tests.js @@ -19,8 +19,14 @@ describe('AWS - General: Environment variables test', function () { const result = JSON.parse(new Buffer(invoked, 'base64').toString()); - expect(result.provider_level_variable).to.be.equal('provider_level'); - expect(result.function_level_variable).to.be.equal('function_level'); + 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(() => {