Skip to content

fix: Off by one assertion for invoker property #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ def _endpoint(
invoker = [invoker]
assert len(
invoker
) > 1, "HttpsOptions: Invalid option for invoker - must be a non-empty list."
) >= 1, "HttpsOptions: Invalid option for invoker - must be a non-empty list."
assert "" not in invoker, (
"HttpsOptions: Invalid option for invoker - must be a non-empty string."
)
Expand Down
14 changes: 12 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from firebase_functions import options, https_fn
from firebase_functions import params
from firebase_functions.private.serving import functions_as_yaml, merge_required_apis
from pytest import raises
# pylint: disable=protected-access


Expand Down Expand Up @@ -44,7 +45,7 @@ def test_global_options_merged_with_provider_options():
Testing a global option is used when no provider option is set.
"""
options.set_global_options(max_instances=66)
pubsub_options = options.PubSubOptions(topic="foo") #pylint: disable=unexpected-keyword-arg
pubsub_options = options.PubSubOptions(topic="foo") # pylint: disable=unexpected-keyword-arg
pubsub_options_dict = pubsub_options._asdict_with_global_options()
assert (pubsub_options_dict["topic"] == "foo"
), "'topic' property missing from dict"
Expand Down Expand Up @@ -170,7 +171,7 @@ def test_merge_apis_duplicate_apis():
This test evaluates the merge_required_apis function when the
input list contains duplicate APIs with different reasons.
The desired outcome for this test is a list where the duplicate
APIs are merged properly and reasons are combined.
APIs are merged properly and reasons are combined.
This test ensures that the function correctly merges the duplicate
APIs and combines the reasons associated with them.
"""
Expand Down Expand Up @@ -217,3 +218,12 @@ def test_merge_apis_duplicate_apis():
for actual_item in merged_apis:
assert (actual_item in expected_output
), f"Unexpected item {actual_item} found in the merged list"


def test_invoker_with_one_element_doesnt_throw():
options.HttpsOptions(invoker=["public"])._endpoint(func_name="test")


def test_invoker_with_no_element_throws():
with raises(AssertionError, match="HttpsOptions: Invalid option for invoker - must be a non-empty list."):
options.HttpsOptions(invoker=[])._endpoint(func_name="test")
Loading