mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #2753 from serverless/add-environment-variables-integration-test
Add environment variables integration test
This commit is contained in:
commit
2f5adfb35a
@ -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
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports.hello = (event, context, callback) => {
|
||||
callback(null, {
|
||||
environment_variables: process.env,
|
||||
});
|
||||
};
|
||||
@ -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
|
||||
35
tests/integration/aws/general/environment-variables/tests.js
Normal file
35
tests/integration/aws/general/environment-variables/tests.js
Normal 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();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user