test_environment.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from flexmock import flexmock
  2. from borgmatic.borg import environment as module
  3. def test_make_environment_with_passcommand_should_set_environment():
  4. environment = module.make_environment({'encryption_passcommand': 'command'})
  5. assert environment.get('BORG_PASSCOMMAND') == 'command'
  6. def test_make_environment_with_passphrase_should_set_environment():
  7. flexmock(module.os.environ).should_receive('get').and_return(None)
  8. environment = module.make_environment({'encryption_passphrase': 'pass'})
  9. assert environment.get('BORG_PASSPHRASE') == 'pass'
  10. def test_make_environment_with_ssh_command_should_set_environment():
  11. flexmock(module.os.environ).should_receive('get').and_return(None)
  12. environment = module.make_environment({'ssh_command': 'ssh -C'})
  13. assert environment.get('BORG_RSH') == 'ssh -C'
  14. def test_make_environment_without_configuration_sets_certain_environment_variables():
  15. flexmock(module.os.environ).should_receive('get').and_return(None)
  16. environment = module.make_environment({})
  17. # Default environment variables.
  18. assert environment == {
  19. 'BORG_EXIT_CODES': 'modern',
  20. 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no',
  21. 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no',
  22. }
  23. def test_make_environment_without_configuration_does_not_set_certain_environment_variables_if_already_set():
  24. flexmock(module.os.environ).should_receive('get').with_args(
  25. 'BORG_RELOCATED_REPO_ACCESS_IS_OK'
  26. ).and_return('yup')
  27. flexmock(module.os.environ).should_receive('get').with_args(
  28. 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK'
  29. ).and_return('nah')
  30. environment = module.make_environment({})
  31. assert environment == {'BORG_EXIT_CODES': 'modern'}
  32. def test_make_environment_with_relocated_repo_access_true_should_set_environment_yes():
  33. flexmock(module.os.environ).should_receive('get').and_return(None)
  34. environment = module.make_environment({'relocated_repo_access_is_ok': True})
  35. assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes'
  36. def test_make_environment_with_relocated_repo_access_false_should_set_environment_no():
  37. flexmock(module.os.environ).should_receive('get').and_return(None)
  38. environment = module.make_environment({'relocated_repo_access_is_ok': False})
  39. assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'no'
  40. def test_make_environment_check_i_know_what_i_am_doing_true_should_set_environment_YES():
  41. flexmock(module.os.environ).should_receive('get').and_return(None)
  42. environment = module.make_environment({'check_i_know_what_i_am_doing': True})
  43. assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'YES'
  44. def test_make_environment_check_i_know_what_i_am_doing_false_should_set_environment_NO():
  45. flexmock(module.os.environ).should_receive('get').and_return(None)
  46. environment = module.make_environment({'check_i_know_what_i_am_doing': False})
  47. assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'NO'
  48. def test_make_environment_with_integer_variable_value():
  49. flexmock(module.os.environ).should_receive('get').and_return(None)
  50. environment = module.make_environment({'borg_files_cache_ttl': 40})
  51. assert environment.get('BORG_FILES_CACHE_TTL') == '40'