Skip to content

Commit a0d78eb

Browse files
committed
refactor(test): parameterize it to cover various types of Expression besides just StringParam
1 parent cff2ff4 commit a0d78eb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/test_options.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Options unit tests.
1616
"""
1717

18+
import pytest
1819
from pytest import raises
1920

2021
from firebase_functions import https_fn, options, params
@@ -198,20 +199,26 @@ def test_invoker_with_no_element_throws():
198199
options.HttpsOptions(invoker=[])._endpoint(func_name="test")
199200

200201

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+
)
203209

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)
205212
https_options_dict = https_options._asdict_with_global_options()
206213

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"
210217
)
211218

212219
# The generated endpoint should map the resolved vpc_connector into the vpc block.
213220
endpoint = https_options._endpoint(func_name="test_vpc")
214221
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), (
216223
"vpc connector was not set from vpc_connector Expression[str]"
217224
)

0 commit comments

Comments
 (0)