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