|
@@ -156,11 +156,26 @@ def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
+def test_borgmatic_source_directories_set_when_directory_exists():
|
|
|
+ flexmock(module.os.path).should_receive('exists').and_return(True)
|
|
|
+ flexmock(module.os.path).should_receive('expanduser')
|
|
|
+
|
|
|
+ assert module.borgmatic_source_directories() == [module.BORGMATIC_SOURCE_DIRECTORY]
|
|
|
+
|
|
|
+
|
|
|
+def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
|
|
|
+ flexmock(module.os.path).should_receive('exists').and_return(False)
|
|
|
+ flexmock(module.os.path).should_receive('expanduser')
|
|
|
+
|
|
|
+ assert module.borgmatic_source_directories() == []
|
|
|
+
|
|
|
+
|
|
|
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
|
|
|
ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
|
|
|
|
|
|
|
|
|
def test_create_archive_calls_borg_with_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -184,6 +199,7 @@ def test_create_archive_calls_borg_with_parameters():
|
|
|
|
|
|
def test_create_archive_with_patterns_calls_borg_with_patterns():
|
|
|
pattern_flags = ('--patterns-from', 'patterns')
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(
|
|
@@ -209,6 +225,7 @@ def test_create_archive_with_patterns_calls_borg_with_patterns():
|
|
|
|
|
|
def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
|
|
exclude_flags = ('--exclude-from', 'excludes')
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
|
|
@@ -233,6 +250,7 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -258,6 +276,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -283,6 +302,7 @@ def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -308,6 +328,7 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -332,6 +353,7 @@ def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -357,6 +379,7 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
|
|
def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
|
|
|
# --dry-run and --stats are mutually exclusive, see:
|
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -385,6 +408,7 @@ def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_param
|
|
|
def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
|
|
|
# --dry-run and --stats are mutually exclusive, see:
|
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -411,6 +435,7 @@ def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_para
|
|
|
|
|
|
|
|
|
def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -434,6 +459,7 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
|
|
|
|
|
|
|
|
|
def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -457,6 +483,7 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
|
|
|
|
|
|
|
|
|
def test_create_archive_with_compression_calls_borg_with_compression_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -480,6 +507,7 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
|
|
|
|
|
|
|
|
|
def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -503,6 +531,7 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
|
|
|
|
|
|
|
|
|
def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -526,6 +555,7 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
|
|
|
|
|
|
|
|
|
def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -549,6 +579,7 @@ def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_paramet
|
|
|
|
|
|
|
|
|
def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -573,6 +604,7 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter
|
|
|
|
|
|
@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
|
|
|
def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name):
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -597,6 +629,7 @@ def test_create_archive_with_option_true_calls_borg_without_corresponding_parame
|
|
|
|
|
|
@pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
|
|
|
def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name):
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -621,6 +654,7 @@ def test_create_archive_with_option_false_calls_borg_with_corresponding_paramete
|
|
|
|
|
|
|
|
|
def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -645,6 +679,7 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
|
|
|
|
|
|
|
|
|
def test_create_archive_with_local_path_calls_borg_via_local_path():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -668,6 +703,7 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -692,6 +728,7 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
|
|
|
|
|
|
|
|
|
def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -714,6 +751,7 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -736,6 +774,7 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stats_calls_borg_with_stats_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -759,6 +798,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_progress_calls_borg_with_progress_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -782,6 +822,7 @@ def test_create_archive_with_progress_calls_borg_with_progress_parameter():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -807,6 +848,7 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -833,6 +875,7 @@ def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter()
|
|
|
|
|
|
|
|
|
def test_create_archive_with_source_directories_glob_expands():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -857,6 +900,7 @@ def test_create_archive_with_source_directories_glob_expands():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_non_matching_source_directories_glob_passes_through():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo*',))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -881,6 +925,7 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
|
|
|
|
|
|
|
|
|
def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -904,6 +949,7 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
@@ -926,6 +972,7 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
|
|
|
|
|
|
|
|
def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
|
|
+ flexmock(module).should_receive('borgmatic_source_directories').and_return([])
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
|
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|