Skip to content

Commit

Permalink
Fix a traceback with "check --only spot" when the "spot" check is unc…
Browse files Browse the repository at this point in the history
…onfigured (#857).
  • Loading branch information
witten committed Apr 24, 2024
1 parent a690ea4 commit 7f735cb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* #851: Fix lack of file extraction when using "extract --strip-components all" on a path with a
leading slash.
* #854: Fix a traceback when the "data" consistency check is used.
# #857: Fix a traceback with "check --only spot" when the "spot" check is unconfigured.

1.8.10
* #656 (beta): Add a "spot" consistency check that compares file counts and contents between your
Expand Down
8 changes: 7 additions & 1 deletion borgmatic/actions/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,13 @@ def spot_check(
'''
log_label = f'{repository.get("label", repository["path"])}'
logger.debug(f'{log_label}: Running spot check')
spot_check_config = next(check for check in config['checks'] if check['name'] == 'spot')

try:
spot_check_config = next(
check for check in config.get('checks', ()) if check.get('name') == 'spot'
)
except StopIteration:
raise ValueError('Cannot run spot check because it is unconfigured')

if spot_check_config['data_tolerance_percentage'] > spot_check_config['data_sample_percentage']:
raise ValueError(
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/actions/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,36 @@ def test_compare_spot_check_hashes_considers_non_existent_path_as_not_matching()
) == ('/bar',)


def test_spot_check_without_spot_configuration_errors():
with pytest.raises(ValueError):
module.spot_check(
repository={'path': 'repo'},
config={
'checks': [
{
'name': 'archives',
},
]
},
local_borg_version=flexmock(),
global_arguments=flexmock(),
local_path=flexmock(),
remote_path=flexmock(),
)


def test_spot_check_without_any_configuration_errors():
with pytest.raises(ValueError):
module.spot_check(
repository={'path': 'repo'},
config={},
local_borg_version=flexmock(),
global_arguments=flexmock(),
local_path=flexmock(),
remote_path=flexmock(),
)


def test_spot_check_data_tolerance_percenatge_greater_than_data_sample_percentage_errors():
with pytest.raises(ValueError):
module.spot_check(
Expand Down

0 comments on commit 7f735cb

Please sign in to comment.