Skip to content

Commit 75f7aa8

Browse files
author
Izaak Gough
committed
tests: update test and adding missing tests
1 parent f50b8fd commit 75f7aa8

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

tests/test_options.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def asamplefunctionpreserved(_):
3434
return "hello world"
3535

3636

37+
@pytest.fixture(autouse=True)
38+
def _cleanup_global_options():
39+
"""Reset global options so each test runs with a clean state."""
40+
original_options = options._GLOBAL_OPTIONS
41+
options._GLOBAL_OPTIONS = options.RuntimeOptions()
42+
yield
43+
options._GLOBAL_OPTIONS = original_options
44+
45+
3746
def test_set_global_options():
3847
"""
3948
Testing if setting a global option internally change the values.
@@ -57,6 +66,30 @@ def test_global_options_merged_with_provider_options():
5766
)
5867

5968

69+
@pytest.mark.parametrize(
70+
"vpc_connector_expr_factory",
71+
[
72+
lambda: params.StringParam("VPC_CONNECTOR"),
73+
lambda: params.BoolParam("USE_VPC").equals(True).then("my-vpc", ""),
74+
],
75+
)
76+
def test_set_global_options_accepts_vpc_connector_expression(vpc_connector_expr_factory):
77+
vpc_connector_expr = vpc_connector_expr_factory()
78+
options.set_global_options(vpc_connector=vpc_connector_expr)
79+
80+
assert options._GLOBAL_OPTIONS.vpc_connector == vpc_connector_expr, (
81+
"global vpc_connector expression was not stored"
82+
)
83+
84+
https_options = options.HttpsOptions()
85+
endpoint = https_options._endpoint(func_name="test_vpc_global")
86+
87+
assert endpoint.vpc is not None, "vpc block was not set on endpoint"
88+
assert endpoint.vpc["connector"] == str(vpc_connector_expr), (
89+
"global vpc_connector Expression[str] was not applied to the endpoint"
90+
)
91+
92+
6093
def test_https_options_removes_cors():
6194
"""
6295
Testing _HttpsOptions strips out the 'cors' property when converted to a dict.
@@ -200,13 +233,14 @@ def test_invoker_with_no_element_throws():
200233

201234

202235
@pytest.mark.parametrize(
203-
"vpc_connector_expr",
236+
"vpc_connector_expr_factory",
204237
[
205-
params.StringParam("VPC_CONNECTOR"),
206-
params.BoolParam("USE_VPC").equals(True).then("my-vpc", ""),
238+
lambda: params.StringParam("VPC_CONNECTOR"),
239+
lambda: params.BoolParam("USE_VPC").equals(True).then("my-vpc", ""),
207240
],
208241
)
209-
def test_vpc_connector_accepts_expression(vpc_connector_expr):
242+
def test_vpc_connector_accepts_expression(vpc_connector_expr_factory):
243+
vpc_connector_expr = vpc_connector_expr_factory()
210244
https_options = options.HttpsOptions(vpc_connector=vpc_connector_expr)
211245
https_options_dict = https_options._asdict_with_global_options()
212246

0 commit comments

Comments
 (0)