@@ -507,6 +507,108 @@ describe('CompileFunctions', () => {
507507 } ) ;
508508 } ) ;
509509
510+ it ( 'should set the secret environment variables based on the function configuration' , ( ) => {
511+ googlePackage . serverless . service . functions = {
512+ func1 : {
513+ handler : 'func1' ,
514+ secrets : {
515+ TEST_SECRET : {
516+ secret : 'secret' ,
517+ version : 'latest' ,
518+ } ,
519+ } ,
520+ events : [ { http : 'foo' } ] ,
521+ } ,
522+ } ;
523+
524+ const compiledResources = [
525+ {
526+ type : 'gcp-types/cloudfunctions-v1:projects.locations.functions' ,
527+ name : 'my-service-dev-func1' ,
528+ properties : {
529+ parent : 'projects/myProject/locations/us-central1' ,
530+ runtime : 'nodejs10' ,
531+ function : 'my-service-dev-func1' ,
532+ entryPoint : 'func1' ,
533+ availableMemoryMb : 256 ,
534+ secretEnvironmentVariables : [
535+ {
536+ key : 'TEST_SECRET' ,
537+ secret : 'secret' ,
538+ version : 'latest' ,
539+ } ,
540+ ] ,
541+ timeout : '60s' ,
542+ sourceArchiveUrl : 'gs://sls-my-service-dev-12345678/some-path/artifact.zip' ,
543+ httpsTrigger : {
544+ url : 'foo' ,
545+ } ,
546+ labels : { } ,
547+ } ,
548+ } ,
549+ ] ;
550+
551+ return googlePackage . compileFunctions ( ) . then ( ( ) => {
552+ expect ( consoleLogStub . calledOnce ) . toEqual ( true ) ;
553+ expect (
554+ googlePackage . serverless . service . provider . compiledConfigurationTemplate . resources
555+ ) . toEqual ( compiledResources ) ;
556+ } ) ;
557+ } ) ;
558+
559+ it ( 'should merge the secret environment variables on the provider configuration and function definition' , ( ) => {
560+ googlePackage . serverless . service . functions = {
561+ func1 : {
562+ handler : 'func1' ,
563+ secrets : {
564+ TEST_SECRET : { secret : 'secret1' , version : 'latest' } ,
565+ TEST_SECRET2 : { secret : 'secret2' , version : 'latest' } ,
566+ } ,
567+ events : [ { http : 'foo' } ] ,
568+ } ,
569+ } ;
570+ googlePackage . serverless . service . provider . secrets = {
571+ TEST_SECRET : { secret : 'secretbase' , version : 'latest' } ,
572+ TEST_SECRET_PROVIDER : { secret : 'secretprovider' , version : 'latest' } ,
573+ } ;
574+
575+ const compiledResources = [
576+ {
577+ type : 'gcp-types/cloudfunctions-v1:projects.locations.functions' ,
578+ name : 'my-service-dev-func1' ,
579+ properties : {
580+ parent : 'projects/myProject/locations/us-central1' ,
581+ runtime : 'nodejs10' ,
582+ function : 'my-service-dev-func1' ,
583+ entryPoint : 'func1' ,
584+ availableMemoryMb : 256 ,
585+ secretEnvironmentVariables : [
586+ { key : 'TEST_SECRET' , secret : 'secret1' , version : 'latest' } ,
587+ { key : 'TEST_SECRET2' , secret : 'secret2' , version : 'latest' } ,
588+ { key : 'TEST_SECRET_PROVIDER' , secret : 'secretprovider' , version : 'latest' } ,
589+ ] ,
590+ timeout : '60s' ,
591+ sourceArchiveUrl : 'gs://sls-my-service-dev-12345678/some-path/artifact.zip' ,
592+ httpsTrigger : {
593+ url : 'foo' ,
594+ } ,
595+ labels : { } ,
596+ } ,
597+ } ,
598+ ] ;
599+
600+ return googlePackage . compileFunctions ( ) . then ( ( ) => {
601+ expect ( consoleLogStub . calledOnce ) . toEqual ( true ) ;
602+ expect (
603+ googlePackage . serverless . service . provider . compiledConfigurationTemplate . resources
604+ ) . toEqual ( compiledResources ) ;
605+ expect ( googlePackage . serverless . service . provider . secrets ) . toEqual ( {
606+ TEST_SECRET : { secret : 'secretbase' , version : 'latest' } ,
607+ TEST_SECRET_PROVIDER : { secret : 'secretprovider' , version : 'latest' } ,
608+ } ) ;
609+ } ) ;
610+ } ) ;
611+
510612 it ( 'should compile "http" events properly' , ( ) => {
511613 googlePackage . serverless . service . functions = {
512614 func1 : {
0 commit comments