Merge pull request #2753 from serverless/add-environment-variables-integration-test

Add environment variables integration test
This commit is contained in:
Philipp Muens 2016-11-21 11:01:44 +01:00 committed by GitHub
commit 2f5adfb35a
4 changed files with 60 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
'use strict';
module.exports.hello = (event, context, callback) => {
callback(null, {
environment_variables: process.env,
});
};

View File

@ -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

View File

@ -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();
});
});