-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! Add config based feature flags
- Loading branch information
1 parent
5c72625
commit cbaaccb
Showing
8 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,65 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from click import ClickException | ||
from snowflake.cli.api.feature_flags import BooleanFlag, FeatureFlagMixin | ||
|
||
|
||
class _TestFlags(FeatureFlagMixin): | ||
# Intentional inconsistency between constant and the enum name to make sure there's no strict relation | ||
ENABLED_BY_DEFAULT = BooleanFlag("ENABLED_DEFAULT", True) | ||
DISABLED_BY_DEFAULT = BooleanFlag("DISABLED_DEFAULT", False) | ||
NON_BOOLEAN = BooleanFlag("NON_BOOLEAN", "xys") # type: ignore | ||
|
||
|
||
def test_flag_value_has_to_be_boolean(): | ||
with pytest.raises(ClickException): | ||
_TestFlags.NON_BOOLEAN.is_enabled() | ||
|
||
|
||
def test_flag_is_enabled(): | ||
assert _TestFlags.ENABLED_BY_DEFAULT.is_enabled() is True | ||
assert _TestFlags.ENABLED_BY_DEFAULT.is_disable() is False | ||
|
||
|
||
def test_flag_is_disabled(): | ||
assert _TestFlags.DISABLED_BY_DEFAULT.is_enabled() is False | ||
assert _TestFlags.DISABLED_BY_DEFAULT.is_disable() is True | ||
|
||
|
||
def test_flag_env_variable_value(): | ||
assert ( | ||
_TestFlags.ENABLED_BY_DEFAULT.env_variable() | ||
== "SNOWFLAKE_CLI_FEATURES_ENABLED_DEFAULT" | ||
) | ||
assert ( | ||
_TestFlags.DISABLED_BY_DEFAULT.env_variable() | ||
== "SNOWFLAKE_CLI_FEATURES_DISABLED_DEFAULT" | ||
) | ||
|
||
|
||
@mock.patch("snowflake.cli.api.config.get_config_value") | ||
@pytest.mark.parametrize("value_from_config", [True, False]) | ||
def test_flag_from_config_file(mock_get_config_value, value_from_config): | ||
mock_get_config_value.return_value = value_from_config | ||
|
||
assert _TestFlags.DISABLED_BY_DEFAULT.is_enabled() is value_from_config | ||
mock_get_config_value.assert_called_once_with( | ||
"cli", "features", key="disabled_default", default=False | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("value_from_env", ["1", "true", "True", "TRUE", "TruE"]) | ||
def test_flag_is_enabled_from_env_var(value_from_env): | ||
with mock.patch.dict( | ||
"os.environ", {"SNOWFLAKE_CLI_FEATURES_DISABLED_DEFAULT": value_from_env} | ||
): | ||
assert _TestFlags.DISABLED_BY_DEFAULT.is_enabled() is True | ||
|
||
|
||
@pytest.mark.parametrize("value_from_env", ["0", "false", "False", "FALSE", "FaLse"]) | ||
def test_flag_is_disabled_from_env_var(value_from_env): | ||
with mock.patch.dict( | ||
"os.environ", {"SNOWFLAKE_CLI_FEATURES_ENABLED_DEFAULT": value_from_env} | ||
): | ||
assert _TestFlags.ENABLED_BY_DEFAULT.is_enabled() is False |
19 changes: 19 additions & 0 deletions
19
tests/plugin/__snapshots__/test_override_by_external_plugins.ambr
This file contains 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,19 @@ | ||
# serializer version: 1 | ||
# name: test_corrupted_config_raises_human_friendly_error[[corrupted0] | ||
''' | ||
╭─ Error ──────────────────────────────────────────────────────────────────────╮ | ||
│ Configuration file seems to be corrupted. Unexpected end of file at line 1 │ | ||
│ col 10 │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
|
||
''' | ||
# --- | ||
# name: test_corrupted_config_raises_human_friendly_error[[corrupted1] | ||
''' | ||
╭─ Error ──────────────────────────────────────────────────────────────────────╮ | ||
│ Configuration file seems to be corrupted. Unexpected end of file at line 1 │ | ||
│ col 10 │ | ||
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
|
||
''' | ||
# --- |