2022-02-09 23:33:12 +01:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import version as module
|
|
|
|
|
|
|
|
from ..test_verbosity import insert_logging_mock
|
|
|
|
|
|
|
|
VERSION = '1.2.3'
|
|
|
|
|
|
|
|
|
2022-10-15 01:19:26 +02:00
|
|
|
def insert_execute_command_and_capture_output_mock(
|
|
|
|
command, borg_local_path='borg', version_output=f'borg {VERSION}'
|
|
|
|
):
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
command, extra_environment=None,
|
2022-02-09 23:33:12 +01:00
|
|
|
).once().and_return(version_output)
|
|
|
|
|
|
|
|
|
|
|
|
def test_local_borg_version_calls_borg_with_required_parameters():
|
2022-10-15 01:19:26 +02:00
|
|
|
insert_execute_command_and_capture_output_mock(('borg', '--version'))
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-02-09 23:33:12 +01:00
|
|
|
|
2022-06-30 22:42:17 +02:00
|
|
|
assert module.local_borg_version({}) == VERSION
|
2022-02-09 23:33:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_borg_version_with_log_info_calls_borg_with_info_parameter():
|
2022-10-15 01:19:26 +02:00
|
|
|
insert_execute_command_and_capture_output_mock(('borg', '--version', '--info'))
|
2022-02-09 23:33:12 +01:00
|
|
|
insert_logging_mock(logging.INFO)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-02-09 23:33:12 +01:00
|
|
|
|
2022-06-30 22:42:17 +02:00
|
|
|
assert module.local_borg_version({}) == VERSION
|
2022-02-09 23:33:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_borg_version_with_log_debug_calls_borg_with_debug_parameters():
|
2022-10-15 01:19:26 +02:00
|
|
|
insert_execute_command_and_capture_output_mock(('borg', '--version', '--debug', '--show-rc'))
|
2022-02-09 23:33:12 +01:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-02-09 23:33:12 +01:00
|
|
|
|
2022-06-30 22:42:17 +02:00
|
|
|
assert module.local_borg_version({}) == VERSION
|
2022-02-09 23:33:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_borg_version_with_local_borg_path_calls_borg_with_it():
|
2022-10-15 01:19:26 +02:00
|
|
|
insert_execute_command_and_capture_output_mock(('borg1', '--version'), borg_local_path='borg1')
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-02-09 23:33:12 +01:00
|
|
|
|
2022-06-30 22:42:17 +02:00
|
|
|
assert module.local_borg_version({}, 'borg1') == VERSION
|
2022-02-09 23:33:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_borg_version_with_invalid_version_raises():
|
2022-10-15 01:19:26 +02:00
|
|
|
insert_execute_command_and_capture_output_mock(('borg', '--version'), version_output='wtf')
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-02-09 23:33:12 +01:00
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2022-06-30 22:42:17 +02:00
|
|
|
module.local_borg_version({})
|