From 338b80903cd5f5a84913f48af8648d09e136a099 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 10 Jul 2017 10:09:06 -0700 Subject: [PATCH] Fixing tests broken by excludes merging. --- borgmatic/tests/unit/config/test_convert.py | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/borgmatic/tests/unit/config/test_convert.py b/borgmatic/tests/unit/config/test_convert.py index 39fc385..a88ed2f 100644 --- a/borgmatic/tests/unit/config/test_convert.py +++ b/borgmatic/tests/unit/config/test_convert.py @@ -1,5 +1,7 @@ from collections import defaultdict, OrderedDict, namedtuple +from flexmock import flexmock + from borgmatic.config import convert as module @@ -7,18 +9,27 @@ Parsed_config = namedtuple('Parsed_config', ('location', 'storage', 'retention', def test_convert_legacy_parsed_config_transforms_source_config_to_mapping(): + flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict) source_config = Parsed_config( location=OrderedDict([('source_directories', '/home'), ('repository', 'hostname.borg')]), storage=OrderedDict([('encryption_passphrase', 'supersecret')]), retention=OrderedDict([('keep_daily', 7)]), consistency=OrderedDict([('checks', 'repository')]), ) + source_excludes = ['/var'] schema = {'map': defaultdict(lambda: {'map': {}})} - destination_config = module.convert_legacy_parsed_config(source_config, schema) + destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema) assert destination_config == OrderedDict([ - ('location', OrderedDict([('source_directories', ['/home']), ('repository', 'hostname.borg')])), + ( + 'location', + OrderedDict([ + ('source_directories', ['/home']), + ('repository', 'hostname.borg'), + ('exclude_patterns', ['/var']), + ]), + ), ('storage', OrderedDict([('encryption_passphrase', 'supersecret')])), ('retention', OrderedDict([('keep_daily', 7)])), ('consistency', OrderedDict([('checks', ['repository'])])), @@ -26,18 +37,26 @@ def test_convert_legacy_parsed_config_transforms_source_config_to_mapping(): def test_convert_legacy_parsed_config_splits_space_separated_values(): + flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict) source_config = Parsed_config( location=OrderedDict([('source_directories', '/home /etc')]), storage=OrderedDict(), retention=OrderedDict(), consistency=OrderedDict([('checks', 'repository archives')]), ) + source_excludes = ['/var'] schema = {'map': defaultdict(lambda: {'map': {}})} - destination_config = module.convert_legacy_parsed_config(source_config, schema) + destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema) assert destination_config == OrderedDict([ - ('location', OrderedDict([('source_directories', ['/home', '/etc'])])), + ( + 'location', + OrderedDict([ + ('source_directories', ['/home', '/etc']), + ('exclude_patterns', ['/var']), + ]), + ), ('storage', OrderedDict()), ('retention', OrderedDict()), ('consistency', OrderedDict([('checks', ['repository', 'archives'])])),