From 2d08a63e603d53ec2a949405cdccbbf809bcad37 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Tue, 28 Mar 2023 22:14:50 +0530 Subject: [PATCH 1/3] fix: make check repositories work with dict and str repositories --- borgmatic/config/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index abcfe3d..96025b3 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -69,7 +69,7 @@ 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, ( From ce22d2d30252a23ff8aea0c9afb0491d618aca75 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Tue, 28 Mar 2023 22:29:21 +0530 Subject: [PATCH 2/3] reformat --- borgmatic/config/validate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index 96025b3..fcf29d3 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -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 not any(repositories_match(repository, config_repository) for config_repository in location_repositories): + if not any( + repositories_match(repository, config_repository) + for config_repository in location_repositories + ): raise Validation_error( config_filename, ( From 08e358e27f09b84f08e932973ddf666356c889d4 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Tue, 28 Mar 2023 22:51:35 +0530 Subject: [PATCH 3/3] add and update tests --- tests/unit/config/test_validate.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/unit/config/test_validate.py b/tests/unit/config/test_validate.py index 327a2b4..d5606bd 100644 --- a/tests/unit/config/test_validate.py +++ b/tests/unit/config/test_validate.py @@ -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',