Skip to content
Open
6 changes: 3 additions & 3 deletions src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class RuntimeOptions:
to the value "gcf_gen1"
"""

vpc_connector: str | _util.Sentinel | None = None
vpc_connector: str | Expression[str] | _util.Sentinel | None = None
Comment thread
cabljac marked this conversation as resolved.
"""
Connect function to specified VPC connector.
A value of ``RESET_VALUE`` removes the VPC connector.
Expand Down Expand Up @@ -1232,8 +1232,8 @@ def set_global_options(
max_instances: int | Expression[int] | _util.Sentinel | None = None,
concurrency: int | Expression[int] | _util.Sentinel | None = None,
cpu: int | _typing.Literal["gcf_gen1"] | _util.Sentinel = "gcf_gen1",
vpc_connector: str | None = None,
vpc_connector_egress_settings: VpcEgressSetting | None = None,
vpc_connector: str | Expression[str] | _util.Sentinel | None = None,
vpc_connector_egress_settings: VpcEgressSetting | _util.Sentinel | None = None,
service_account: str | _util.Sentinel | None = None,
ingress: IngressSetting | _util.Sentinel | None = None,
labels: dict[str, str] | None = None,
Expand Down
33 changes: 33 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Options unit tests.
"""

import pytest
from pytest import raises

from firebase_functions import https_fn, options, params
Expand All @@ -23,6 +24,14 @@
# pylint: disable=protected-access


@pytest.fixture(autouse=True)
def _cleanup_params():
"""Clear the global params registry so each test runs with a clean state."""
params._params.clear()
yield
params._params.clear()

Comment thread
HassanBahati marked this conversation as resolved.
Outdated

@https_fn.on_call()
def asamplefunction(_):
return "hello world"
Expand Down Expand Up @@ -196,3 +205,27 @@ def test_invoker_with_no_element_throws():
AssertionError, match="HttpsOptions: Invalid option for invoker - must be a non-empty list."
):
options.HttpsOptions(invoker=[])._endpoint(func_name="test")


@pytest.mark.parametrize(
"vpc_connector_expr",
[
params.StringParam("VPC_CONNECTOR"),
params.BoolParam("USE_VPC").equals(True).then("my-vpc", ""),
],
)
def test_vpc_connector_accepts_expression(vpc_connector_expr):
Comment thread
HassanBahati marked this conversation as resolved.
https_options = options.HttpsOptions(vpc_connector=vpc_connector_expr)
https_options_dict = https_options._asdict_with_global_options()

# The options dict should contain the CEL string representation for the expression.
assert https_options_dict["vpc_connector"] == str(vpc_connector_expr), (
"vpc_connector expression was not converted to CEL string"
)

# The generated endpoint should map the resolved vpc_connector into the vpc block.
endpoint = https_options._endpoint(func_name="test_vpc")
assert endpoint.vpc is not None, "vpc block was not set on endpoint"
assert endpoint.vpc["connector"] == str(vpc_connector_expr), (
"vpc connector was not set from vpc_connector Expression[str]"
)
Loading