|
15 | 15 | Options unit tests. |
16 | 16 | """ |
17 | 17 |
|
| 18 | +import pytest |
18 | 19 | from pytest import raises |
19 | 20 |
|
20 | 21 | from firebase_functions import https_fn, options, params |
@@ -198,20 +199,26 @@ def test_invoker_with_no_element_throws(): |
198 | 199 | options.HttpsOptions(invoker=[])._endpoint(func_name="test") |
199 | 200 |
|
200 | 201 |
|
201 | | -def test_vpc_connector_accepts_string_param(): |
202 | | - vpc_param = params.StringParam("VPC_CONNECTOR") |
| 202 | +@pytest.mark.parametrize( |
| 203 | + "vpc_connector_expr", |
| 204 | + [ |
| 205 | + params.StringParam("VPC_CONNECTOR"), |
| 206 | + params.BoolParam("USE_VPC").equals(True).then("my-vpc", ""), |
| 207 | + ], |
| 208 | +) |
203 | 209 |
|
204 | | - https_options = options.HttpsOptions(vpc_connector=vpc_param) |
| 210 | +def test_vpc_connector_accepts_expression(vpc_connector_expr): |
| 211 | + https_options = options.HttpsOptions(vpc_connector=vpc_connector_expr) |
205 | 212 | https_options_dict = https_options._asdict_with_global_options() |
206 | 213 |
|
207 | | - # The options dict should contain the CEL string representation for the param. |
208 | | - assert https_options_dict["vpc_connector"] == f"{vpc_param}", ( |
209 | | - "vpc_connector param was not converted to CEL string" |
| 214 | + # The options dict should contain the CEL string representation for the expression. |
| 215 | + assert https_options_dict["vpc_connector"] == str(vpc_connector_expr), ( |
| 216 | + "vpc_connector expression was not converted to CEL string" |
210 | 217 | ) |
211 | 218 |
|
212 | 219 | # The generated endpoint should map the resolved vpc_connector into the vpc block. |
213 | 220 | endpoint = https_options._endpoint(func_name="test_vpc") |
214 | 221 | assert endpoint.vpc is not None, "vpc block was not set on endpoint" |
215 | | - assert endpoint.vpc["connector"] == f"{vpc_param}", ( |
| 222 | + assert endpoint.vpc["connector"] == str(vpc_connector_expr), ( |
216 | 223 | "vpc connector was not set from vpc_connector Expression[str]" |
217 | 224 | ) |
0 commit comments