|
@@ -7,22 +7,34 @@ from borgmatic.hooks import command as module
|
|
|
|
|
|
|
|
|
def test_interpolate_context_passes_through_command_without_variable():
|
|
|
- assert module.interpolate_context('ls', {'foo': 'bar'}) == 'ls'
|
|
|
+ assert module.interpolate_context('test.yaml', 'pre-backup', 'ls', {'foo': 'bar'}) == 'ls'
|
|
|
|
|
|
|
|
|
def test_interpolate_context_passes_through_command_with_unknown_variable():
|
|
|
- assert module.interpolate_context('ls {baz}', {'foo': 'bar'}) == 'ls {baz}'
|
|
|
+ assert (
|
|
|
+ module.interpolate_context('test.yaml', 'pre-backup', 'ls {baz}', {'foo': 'bar'})
|
|
|
+ == 'ls {baz}'
|
|
|
+ )
|
|
|
|
|
|
|
|
|
def test_interpolate_context_interpolates_variables():
|
|
|
context = {'foo': 'bar', 'baz': 'quux'}
|
|
|
|
|
|
- assert module.interpolate_context('ls {foo}{baz} {baz}', context) == 'ls barquux quux'
|
|
|
+ assert (
|
|
|
+ module.interpolate_context('test.yaml', 'pre-backup', 'ls {foo}{baz} {baz}', context)
|
|
|
+ == 'ls barquux quux'
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_interpolate_context_does_not_touch_unknown_variables():
|
|
|
+ context = {'foo': 'bar', 'baz': 'quux'}
|
|
|
+
|
|
|
+ assert module.interpolate_context('test.yaml', 'pre-backup', 'ls {wtf}', context) == 'ls {wtf}'
|
|
|
|
|
|
|
|
|
def test_execute_hook_invokes_each_command():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
- lambda command, context: command
|
|
|
+ lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
[':'], output_log_level=logging.WARNING, shell=True
|
|
@@ -33,7 +45,7 @@ def test_execute_hook_invokes_each_command():
|
|
|
|
|
|
def test_execute_hook_with_multiple_commands_invokes_each_command():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
- lambda command, context: command
|
|
|
+ lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
[':'], output_log_level=logging.WARNING, shell=True
|
|
@@ -47,7 +59,7 @@ def test_execute_hook_with_multiple_commands_invokes_each_command():
|
|
|
|
|
|
def test_execute_hook_with_umask_sets_that_umask():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
- lambda command, context: command
|
|
|
+ lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
flexmock(module.os).should_receive('umask').with_args(0o77).and_return(0o22).once()
|
|
|
flexmock(module.os).should_receive('umask').with_args(0o22).once()
|
|
@@ -60,7 +72,7 @@ def test_execute_hook_with_umask_sets_that_umask():
|
|
|
|
|
|
def test_execute_hook_with_dry_run_skips_commands():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
- lambda command, context: command
|
|
|
+ lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
flexmock(module.execute).should_receive('execute_command').never()
|
|
|
|
|
@@ -73,7 +85,7 @@ def test_execute_hook_with_empty_commands_does_not_raise():
|
|
|
|
|
|
def test_execute_hook_on_error_logs_as_error():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
- lambda command, context: command
|
|
|
+ lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
[':'], output_log_level=logging.ERROR, shell=True
|