Fixing tests broken by excludes merging.

This commit is contained in:
Dan Helfman 2017-07-10 10:09:06 -07:00
parent fea97b5149
commit 338b80903c

View file

@ -1,5 +1,7 @@
from collections import defaultdict, OrderedDict, namedtuple from collections import defaultdict, OrderedDict, namedtuple
from flexmock import flexmock
from borgmatic.config import convert as module 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(): 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( source_config = Parsed_config(
location=OrderedDict([('source_directories', '/home'), ('repository', 'hostname.borg')]), location=OrderedDict([('source_directories', '/home'), ('repository', 'hostname.borg')]),
storage=OrderedDict([('encryption_passphrase', 'supersecret')]), storage=OrderedDict([('encryption_passphrase', 'supersecret')]),
retention=OrderedDict([('keep_daily', 7)]), retention=OrderedDict([('keep_daily', 7)]),
consistency=OrderedDict([('checks', 'repository')]), consistency=OrderedDict([('checks', 'repository')]),
) )
source_excludes = ['/var']
schema = {'map': defaultdict(lambda: {'map': {}})} 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([ 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')])), ('storage', OrderedDict([('encryption_passphrase', 'supersecret')])),
('retention', OrderedDict([('keep_daily', 7)])), ('retention', OrderedDict([('keep_daily', 7)])),
('consistency', OrderedDict([('checks', ['repository'])])), ('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(): def test_convert_legacy_parsed_config_splits_space_separated_values():
flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
source_config = Parsed_config( source_config = Parsed_config(
location=OrderedDict([('source_directories', '/home /etc')]), location=OrderedDict([('source_directories', '/home /etc')]),
storage=OrderedDict(), storage=OrderedDict(),
retention=OrderedDict(), retention=OrderedDict(),
consistency=OrderedDict([('checks', 'repository archives')]), consistency=OrderedDict([('checks', 'repository archives')]),
) )
source_excludes = ['/var']
schema = {'map': defaultdict(lambda: {'map': {}})} 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([ assert destination_config == OrderedDict([
('location', OrderedDict([('source_directories', ['/home', '/etc'])])), (
'location',
OrderedDict([
('source_directories', ['/home', '/etc']),
('exclude_patterns', ['/var']),
]),
),
('storage', OrderedDict()), ('storage', OrderedDict()),
('retention', OrderedDict()), ('retention', OrderedDict()),
('consistency', OrderedDict([('checks', ['repository', 'archives'])])), ('consistency', OrderedDict([('checks', ['repository', 'archives'])])),