A wrapper script for Borg backup software that creates and prunes backups
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_init.py 2.1KB

  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import init as module
  4. from ..test_verbosity import insert_logging_mock
  5. def insert_subprocess_mock(check_call_command, **kwargs):
  6. subprocess = flexmock(module.subprocess)
  7. subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
  8. INIT_COMMAND = ('borg', 'init', 'repo', '--encryption', 'repokey')
  9. def test_initialize_repository_calls_borg_with_parameters():
  10. insert_subprocess_mock(INIT_COMMAND)
  11. module.initialize_repository(repository='repo', encryption_mode='repokey')
  12. def test_initialize_repository_with_append_only_calls_borg_with_append_only_parameter():
  13. insert_subprocess_mock(INIT_COMMAND + ('--append-only',))
  14. module.initialize_repository(repository='repo', encryption_mode='repokey', append_only=True)
  15. def test_initialize_repository_with_storage_quota_calls_borg_with_storage_quota_parameter():
  16. insert_subprocess_mock(INIT_COMMAND + ('--storage-quota', '5G'))
  17. module.initialize_repository(repository='repo', encryption_mode='repokey', storage_quota='5G')
  18. def test_initialize_repository_with_log_info_calls_borg_with_info_parameter():
  19. insert_subprocess_mock(INIT_COMMAND + ('--info',))
  20. insert_logging_mock(logging.INFO)
  21. module.initialize_repository(repository='repo', encryption_mode='repokey')
  22. def test_initialize_repository_with_log_debug_calls_borg_with_debug_parameter():
  23. insert_subprocess_mock(INIT_COMMAND + ('--debug',))
  24. insert_logging_mock(logging.DEBUG)
  25. module.initialize_repository(repository='repo', encryption_mode='repokey')
  26. def test_initialize_repository_with_local_path_calls_borg_via_local_path():
  27. insert_subprocess_mock(('borg1',) + INIT_COMMAND[1:])
  28. module.initialize_repository(repository='repo', encryption_mode='repokey', local_path='borg1')
  29. def test_initialize_repository_with_remote_path_calls_borg_with_remote_path_parameter():
  30. insert_subprocess_mock(INIT_COMMAND + ('--remote-path', 'borg1'))
  31. module.initialize_repository(repository='repo', encryption_mode='repokey', remote_path='borg1')