Skip to content

Commit

Permalink
Fix should_check_efs_utils_version scope
Browse files Browse the repository at this point in the history
Fixed should_check_efs_utils_version scope and added unit test to cover missing code coverage.
  • Loading branch information
RyanStan committed Jun 16, 2023
1 parent 3dd89ca commit 62fde08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/watchdog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,14 @@ def check_if_using_old_version(current_version_string):

EFSUtilsVersionChecker.update_version_check_file()

@staticmethod
def should_check_efs_utils_version(config):
"""Returns True if a customer has enabled the amazon-efs-utils version check,
and if the last version check occurred more than VERSION_CHECK_POLL_INTERVAL seconds ago."""
version_check_enabled = get_boolean_config_item_value(
config, CONFIG_SECTION, ENABLE_VERSION_CHECK, default_value=True
)
return (
version_check_enabled and EFSUtilsVersionChecker.version_check_ready()
)
@staticmethod
def should_check_efs_utils_version(config):
"""Returns True if a customer has enabled the amazon-efs-utils version check,
and if the last version check occurred more than VERSION_CHECK_POLL_INTERVAL seconds ago."""
version_check_enabled = get_boolean_config_item_value(
config, CONFIG_SECTION, ENABLE_VERSION_CHECK, default_value=True
)
return version_check_enabled and EFSUtilsVersionChecker.version_check_ready()


def fatal_error(user_message, log_message=None):
Expand Down
23 changes: 23 additions & 0 deletions test/watchdog_test/test_check_if_using_old_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

import watchdog

try:
import ConfigParser
except ImportError:
from configparser import ConfigParser

OLD_VERSION = "1.34.3"
GITHUB_VERSION = "1.35.9"
YUM_VERSION = "1.35.8"
Expand Down Expand Up @@ -171,3 +176,21 @@ def test_version_empty_version_str():
"""Assert that an Exception is thrown when we try to construct a Version instance with an empty string"""
with pytest.raises(Exception):
watchdog.Version("")


def test_should_check_efs_utils_version(mocker):
mocker.patch("watchdog.get_boolean_config_item_value", return_value=True)
mocker.patch(
"watchdog.EFSUtilsVersionChecker.version_check_ready", return_value=True
)
config = ConfigParser()
assert watchdog.EFSUtilsVersionChecker.should_check_efs_utils_version(config)

mocker.patch("watchdog.get_boolean_config_item_value", return_value=False)
assert not watchdog.EFSUtilsVersionChecker.should_check_efs_utils_version(config)

mocker.patch(
"watchdog.EFSUtilsVersionChecker.version_check_ready", return_value=False
)
mocker.patch("watchdog.get_boolean_config_item_value", return_value=True)
assert not watchdog.EFSUtilsVersionChecker.should_check_efs_utils_version(config)

0 comments on commit 62fde08

Please sign in to comment.