Skip to content

Commit

Permalink
fix: make check repositories work with dict and str repositories (#662).
Browse files Browse the repository at this point in the history
Merge pull request #63 from diivi/fix/check-repositories-by-label
  • Loading branch information
witten authored Mar 28, 2023
2 parents 67a349a + 08e358e commit 9d71bf9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion borgmatic/config/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def apply_logical_validation(config_filename, parsed_configuration):
location_repositories = parsed_configuration.get('location', {}).get('repositories')
check_repositories = parsed_configuration.get('consistency', {}).get('check_repositories', [])
for repository in check_repositories:
if repository not in location_repositories:
if not any(
repositories_match(repository, config_repository)
for config_repository in location_repositories
):
raise Validation_error(
config_filename,
(
Expand Down
20 changes: 18 additions & 2 deletions tests/unit/config/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,33 @@ def test_apply_locical_validation_raises_if_unknown_repository_in_check_reposito
)


def test_apply_locical_validation_does_not_raise_if_known_repository_in_check_repositories():
def test_apply_locical_validation_does_not_raise_if_known_repository_path_in_check_repositories():
module.apply_logical_validation(
'config.yaml',
{
'location': {'repositories': ['repo.borg', 'other.borg']},
'location': {'repositories': [{'path': 'repo.borg'}, {'path': 'other.borg'}]},
'retention': {'keep_secondly': 1000},
'consistency': {'check_repositories': ['repo.borg']},
},
)


def test_apply_locical_validation_does_not_raise_if_known_repository_label_in_check_repositories():
module.apply_logical_validation(
'config.yaml',
{
'location': {
'repositories': [
{'path': 'repo.borg', 'label': 'my_repo'},
{'path': 'other.borg', 'label': 'other_repo'},
]
},
'retention': {'keep_secondly': 1000},
'consistency': {'check_repositories': ['my_repo']},
},
)


def test_apply_logical_validation_does_not_raise_if_archive_name_format_and_prefix_present():
module.apply_logical_validation(
'config.yaml',
Expand Down

0 comments on commit 9d71bf9

Please sign in to comment.