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