File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ module.exports = {
4343 funcTemplate . properties . timeout = _ . get ( funcObject , 'timeout' )
4444 || _ . get ( this , 'serverless.service.provider.timeout' )
4545 || '60s' ;
46+ funcTemplate . properties . environmentVariables = _ . get ( funcObject , 'environment' )
47+ || _ . get ( this , 'serverless.service.provider.environment' )
48+ || null ;
49+
50+ if ( funcTemplate . properties . environmentVariables === null ) {
51+ delete funcTemplate . properties . environmentVariables ;
52+ }
53+
4654 funcTemplate . properties . labels = _ . assign ( { } ,
4755 _ . get ( this , 'serverless.service.provider.labels' ) || { } ,
4856 _ . get ( funcObject , 'labels' ) || { } ,
Original file line number Diff line number Diff line change @@ -133,6 +133,46 @@ describe('CompileFunctions', () => {
133133 } ) ;
134134 } ) ;
135135
136+ it ( 'should set the environment variables based on the provider configuration' , ( ) => {
137+ googlePackage . serverless . service . functions = {
138+ func1 : {
139+ handler : 'func1' ,
140+ events : [
141+ { http : 'foo' } ,
142+ ] ,
143+ } ,
144+ } ;
145+ googlePackage . serverless . service . provider . environment = {
146+ TEST_VAR : 'test' ,
147+ } ;
148+
149+ const compiledResources = [ {
150+ type : 'cloudfunctions.v1beta2.function' ,
151+ name : 'my-service-dev-func1' ,
152+ properties : {
153+ location : 'us-central1' ,
154+ runtime : 'nodejs8' ,
155+ function : 'func1' ,
156+ availableMemoryMb : 256 ,
157+ environmentVariables : {
158+ TEST_VAR : 'test' ,
159+ } ,
160+ timeout : '60s' ,
161+ sourceArchiveUrl : 'gs://sls-my-service-dev-12345678/some-path/artifact.zip' ,
162+ httpsTrigger : {
163+ url : 'foo' ,
164+ } ,
165+ labels : { } ,
166+ } ,
167+ } ] ;
168+
169+ return googlePackage . compileFunctions ( ) . then ( ( ) => {
170+ expect ( consoleLogStub . calledOnce ) . toEqual ( true ) ;
171+ expect ( googlePackage . serverless . service . provider . compiledConfigurationTemplate . resources )
172+ . toEqual ( compiledResources ) ;
173+ } ) ;
174+ } ) ;
175+
136176 it ( 'should set the memory size based on the provider configuration' , ( ) => {
137177 googlePackage . serverless . service . functions = {
138178 func1 : {
You can’t perform that action at this time.
0 commit comments