test_environment.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_not_set_environment():
  28. orig_environ = os.environ
  29. try:
  30. os.environ = {}
  31. module.initialize({})
  32. assert sum(1 for key in os.environ.keys() if key.startswith('BORG_')) == 0
  33. finally:
  34. os.environ = orig_environ