test_environment.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import os
  2. from borgmatic.borg import environment as module
  3. def test_initialize_with_passcommand_should_set_environment():
  4. orig_environ = os.environ
  5. try:
  6. os.environ = {}
  7. module.initialize({'encryption_passcommand': 'command'})
  8. assert os.environ.get('BORG_PASSCOMMAND') == 'command'
  9. finally:
  10. os.environ = orig_environ
  11. def test_initialize_with_passphrase_should_set_environment():
  12. orig_environ = os.environ
  13. try:
  14. os.environ = {}
  15. module.initialize({'encryption_passphrase': 'pass'})
  16. assert os.environ.get('BORG_PASSPHRASE') == 'pass'
  17. finally:
  18. os.environ = orig_environ
  19. def test_initialize_with_ssh_command_should_set_environment():
  20. orig_environ = os.environ
  21. try:
  22. os.environ = {}
  23. module.initialize({'ssh_command': 'ssh -C'})
  24. assert os.environ.get('BORG_RSH') == 'ssh -C'
  25. finally:
  26. os.environ = orig_environ
  27. def test_initialize_without_configuration_should_only_set_default_environment():
  28. orig_environ = os.environ
  29. try:
  30. os.environ = {}
  31. module.initialize({})
  32. assert {key: value for key, value in os.environ.items() if key.startswith('BORG_')} == {
  33. 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no',
  34. 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no',
  35. }
  36. finally:
  37. os.environ = orig_environ
  38. def test_initialize_with_relocated_repo_access_should_override_default():
  39. orig_environ = os.environ
  40. try:
  41. os.environ = {}
  42. module.initialize({'relocated_repo_access_is_ok': True})
  43. assert os.environ.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes'
  44. finally:
  45. os.environ = orig_environ
  46. def test_initialize_prefers_configuration_option_over_borg_environment_variable():
  47. orig_environ = os.environ
  48. try:
  49. os.environ = {'BORG_SSH': 'mosh'}
  50. module.initialize({'ssh_command': 'ssh -C'})
  51. assert os.environ.get('BORG_RSH') == 'ssh -C'
  52. finally:
  53. os.environ = orig_environ
  54. def test_initialize_passes_through_existing_borg_environment_variable():
  55. orig_environ = os.environ
  56. try:
  57. os.environ = {'BORG_PASSPHRASE': 'pass'}
  58. module.initialize({'ssh_command': 'ssh -C'})
  59. assert os.environ.get('BORG_PASSPHRASE') == 'pass'
  60. finally:
  61. os.environ = orig_environ