11import { expect } from "chai" ;
22import * as build from "../../../deploy/functions/build" ;
33import { ParamValue } from "../../../deploy/functions/params" ;
4+ import { FirebaseError } from "../../../error" ;
45
56describe ( "toBackend" , ( ) => {
67 it ( "populates backend info from Build" , ( ) => {
@@ -124,8 +125,8 @@ describe("toBackend", () => {
124125 minInstances : "{{ params.mininstances }}" ,
125126 serviceAccount : "{{ params.serviceaccount }}" ,
126127 vpc : {
127- connector : "projects/project/locations/region/connectors/ connector" ,
128- egressSettings : "PRIVATE_RANGES_ONLY " ,
128+ connector : "{{ params. connector }} " ,
129+ egressSettings : "{{ params.egressSettings }} " ,
129130 } ,
130131 ingressSettings : "ALLOW_ALL" ,
131132 labels : {
@@ -140,6 +141,8 @@ describe("toBackend", () => {
140141 maxinstances : new ParamValue ( "42" , false , { number : true } ) ,
141142 mininstances : new ParamValue ( "1" , false , { number : true } ) ,
142143 serviceaccount : new ParamValue ( "service-account-1@" , false , { string : true } ) ,
144+ connector : new ParamValue ( "connector" , false , { string : true } ) ,
145+ egressSettings : new ParamValue ( "ALL_TRAFFIC" , false , { string : true } ) ,
143146 } ) ;
144147 expect ( Object . keys ( backend . endpoints ) . length ) . to . equal ( 1 ) ;
145148 const endpointDef = Object . values ( backend . endpoints ) [ 0 ] ;
@@ -154,6 +157,32 @@ describe("toBackend", () => {
154157 expect (
155158 "httpsTrigger" in endpointDef . func ? endpointDef . func . httpsTrigger . invoker : [ ] ,
156159 ) . to . have . members ( [ "service-account-2@" , "service-account-3@" ] ) ;
160+ expect ( endpointDef . func . vpc ?. connector ) . to . equal (
161+ "projects/project/locations/us-central1/connectors/connector" ,
162+ ) ;
163+ expect ( endpointDef . func . vpc ?. egressSettings ) . to . equal ( "ALL_TRAFFIC" ) ;
157164 }
158165 } ) ;
166+
167+ it ( "enforces enum correctness for VPC egress settings" , ( ) => {
168+ const desiredBuild : build . Build = build . of ( {
169+ func : {
170+ platform : "gcfv2" ,
171+ region : [ "us-central1" ] ,
172+ project : "project" ,
173+ runtime : "nodejs16" ,
174+ entryPoint : "func" ,
175+ vpc : {
176+ connector : "connector" ,
177+ egressSettings : "{{ params.egressSettings }}" ,
178+ } ,
179+ httpsTrigger : { } ,
180+ } ,
181+ } ) ;
182+ expect ( ( ) => {
183+ build . toBackend ( desiredBuild , {
184+ egressSettings : new ParamValue ( "INVALID" , false , { string : true } ) ,
185+ } ) ;
186+ } ) . to . throw ( FirebaseError , / V a l u e " I N V A L I D " i s a n i n v a l i d e g r e s s s e t t i n g ./ ) ;
187+ } ) ;
159188} ) ;
0 commit comments