-
Notifications
You must be signed in to change notification settings - Fork 38
fix: validate domain is present when calling set_provider on registry
#561
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
federicobond
merged 2 commits into
open-feature:main
from
keelerm84:feat/require-domain
Jan 15, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| from unittest.mock import Mock | ||
|
|
||
| from openfeature.exception import GeneralError | ||
| from openfeature.provider._registry import ProviderRegistry | ||
| from openfeature.provider.no_op_provider import NoOpProvider | ||
|
|
||
|
|
||
| def test_registry_serves_noop_as_default(): | ||
| registry = ProviderRegistry() | ||
|
|
||
| assert isinstance(registry.get_default_provider(), NoOpProvider) | ||
| assert isinstance(registry.get_provider("unknown domain"), NoOpProvider) | ||
|
|
||
|
|
||
| def test_setting_provider_requires_domain(): | ||
| registry = ProviderRegistry() | ||
|
|
||
| try: | ||
| registry.set_provider(None, NoOpProvider()) # type: ignore[reportArgumentType] | ||
| raise AssertionError( | ||
| "Expected an exception when setting provider with None domain" | ||
| ) | ||
| except GeneralError as e: | ||
| assert e.error_message == "No domain" | ||
| except Exception as e: | ||
| raise AssertionError("Expected GeneralError, got {type(e)}") from e | ||
|
|
||
|
|
||
| def test_setting_provider_requires_provider(): | ||
| registry = ProviderRegistry() | ||
|
|
||
| try: | ||
| registry.set_provider("domain", None) # type: ignore[reportArgumentType] | ||
| raise AssertionError("Expected an exception when setting provider to None") | ||
| except GeneralError as e: | ||
| assert e.error_message == "No provider" | ||
| except Exception as e: | ||
| raise AssertionError("Expected GeneralError, got {type(e)}") from e | ||
|
keelerm84 marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_can_register_provider_to_multiple_domains(): | ||
| registry = ProviderRegistry() | ||
| provider = NoOpProvider() | ||
|
|
||
| registry.set_provider("domain1", provider) | ||
| registry.set_provider("domain2", provider) | ||
|
|
||
| assert registry.get_provider("domain1") is provider | ||
| assert registry.get_provider("domain2") is provider | ||
|
|
||
|
|
||
| def test_registering_provider_replaces_previous_provider(): | ||
| """Test that registering a provider replaces the previous provider and calls shutdown on the old one.""" | ||
|
|
||
| registry = ProviderRegistry() | ||
| provider1 = Mock() | ||
| provider2 = Mock() | ||
|
|
||
| registry.set_provider("domain", provider1) | ||
| assert registry.get_provider("domain") is provider1 | ||
|
|
||
| registry.set_provider("domain", provider2) | ||
| assert registry.get_provider("domain") is provider2 | ||
|
|
||
| provider1.shutdown.assert_called_once() | ||
| provider2.shutdown.assert_not_called() | ||
|
|
||
|
|
||
| def test_registering_provider_for_first_time_initializes_it(): | ||
| """Test that registering a provider for the first time calls its initialize method.""" | ||
|
|
||
| registry = ProviderRegistry() | ||
| provider = Mock() | ||
|
|
||
| registry.set_provider("domain1", provider) | ||
| registry.set_provider("domain2", provider) | ||
|
|
||
| provider.initialize.assert_called_once() | ||
|
|
||
|
|
||
| def test_setting_default_provider_requires_provider(): | ||
| registry = ProviderRegistry() | ||
|
|
||
| try: | ||
| registry.set_default_provider(None) # type: ignore[reportArgumentType] | ||
| raise AssertionError( | ||
| "Expected an exception when setting default provider to None" | ||
| ) | ||
| except GeneralError as e: | ||
| assert e.error_message == "No provider" | ||
| except Exception as e: | ||
| raise AssertionError("Expected GeneralError, got {type(e)}") from e | ||
|
keelerm84 marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def test_replacing_default_provider_shuts_down_old_one(): | ||
| """Test that replacing the default provider shuts down the old default provider.""" | ||
|
|
||
| registry = ProviderRegistry() | ||
| default_provider1 = Mock() | ||
| default_provider2 = Mock() | ||
|
|
||
| registry.set_default_provider(default_provider1) | ||
| assert registry.get_default_provider() is default_provider1 | ||
|
|
||
| registry.set_default_provider(default_provider2) | ||
| assert registry.get_default_provider() is default_provider2 | ||
|
|
||
| default_provider1.shutdown.assert_called_once() | ||
| default_provider2.shutdown.assert_not_called() | ||
|
|
||
|
|
||
| def test_setting_default_provider_initializes_it(): | ||
| registry = ProviderRegistry() | ||
| provider = Mock() | ||
|
|
||
| registry.set_default_provider(provider) | ||
|
|
||
| provider.initialize.assert_called_once() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.