Browse Source

review changes

Vandal 2 months ago
parent
commit
d17aa3e7cc
2 changed files with 20 additions and 8 deletions
  1. 16 8
      tests/unit/borg/test_compact.py
  2. 4 0
      tests/unit/borg/test_environment.py

+ 16 - 8
tests/unit/borg/test_compact.py

@@ -68,26 +68,34 @@ def test_compact_segments_with_log_debug_calls_borg_with_debug_flag():
     )
     )
 
 
 
 
-def test_compact_segments_with_dry_run_skips_borg_call():
-    # Test borg version supports dry run.
-    logger_mock = flexmock(logging)
-    flexmock(module).should_receive('execute_command').once()
+def test_compact_segments_with_dry_run_skips_borg_call_when_feature_unavailable():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
+    flexmock(module.feature).should_receive('available').with_args(
+        module.feature.Feature.DRY_RUN_COMPACT, '1.2.3'
+    ).and_return(False)
+    flexmock(module).should_receive('execute_command').never()
+    flexmock(logging).should_receive('info').with_args('Skipping compact (dry run)').once()
 
 
     module.compact_segments(
     module.compact_segments(
         repository_path='repo',
         repository_path='repo',
         config={},
         config={},
-        local_borg_version='1.4.1',
+        local_borg_version='1.2.3',
         global_arguments=flexmock(),
         global_arguments=flexmock(),
         dry_run=True,
         dry_run=True,
     )
     )
 
 
-    # Test borg version that does not support dry run.
-    logger_mock.should_receive('info').with_args('Skipping compact (dry run)').once()
+
+def test_compact_segments_with_dry_run_executes_borg_call_when_feature_available():
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
+    flexmock(module.feature).should_receive('available').with_args(
+        module.feature.Feature.DRY_RUN_COMPACT, '1.4.1'
+    ).and_return(True)
+    flexmock(module).should_receive('execute_command').once()
 
 
     module.compact_segments(
     module.compact_segments(
         repository_path='repo',
         repository_path='repo',
         config={},
         config={},
-        local_borg_version='1.2.3',
+        local_borg_version='1.4.1',
         global_arguments=flexmock(),
         global_arguments=flexmock(),
         dry_run=True,
         dry_run=True,
     )
     )

+ 4 - 0
tests/unit/borg/test_environment.py

@@ -177,6 +177,10 @@ def test_make_environment_with_integer_variable_value():
 
 
 def test_make_environment_with_use_chunks_archive_should_set_correct_environment_value():
 def test_make_environment_with_use_chunks_archive_should_set_correct_environment_value():
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.hooks.credential.parse).should_receive(
+        'resolve_credential'
+    ).and_return(None)
+    flexmock(module.os).should_receive('pipe').never()
 
 
     environment = module.make_environment({'use_chunks_archive': True})
     environment = module.make_environment({'use_chunks_archive': True})
     assert environment.get('BORG_USE_CHUNKS_ARCHIVE') == 'yes'
     assert environment.get('BORG_USE_CHUNKS_ARCHIVE') == 'yes'