test_environment.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from borgmatic.borg import environment as module
  2. def test_make_environment_with_passcommand_should_set_environment():
  3. environment = module.make_environment({'encryption_passcommand': 'command'})
  4. assert environment.get('BORG_PASSCOMMAND') == 'command'
  5. def test_make_environment_with_passphrase_should_set_environment():
  6. environment = module.make_environment({'encryption_passphrase': 'pass'})
  7. assert environment.get('BORG_PASSPHRASE') == 'pass'
  8. def test_make_environment_with_ssh_command_should_set_environment():
  9. environment = module.make_environment({'ssh_command': 'ssh -C'})
  10. assert environment.get('BORG_RSH') == 'ssh -C'
  11. def test_make_environment_without_configuration_sets_certain_environment_variables():
  12. environment = module.make_environment({})
  13. # borgmatic always sets this Borg environment variable.
  14. assert environment == {
  15. 'BORG_EXIT_CODES': 'modern',
  16. 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no',
  17. 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no',
  18. }
  19. def test_make_environment_with_relocated_repo_access_true_should_set_environment_yes():
  20. environment = module.make_environment({'relocated_repo_access_is_ok': True})
  21. assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes'
  22. def test_make_environment_with_relocated_repo_access_false_should_set_environment_no():
  23. environment = module.make_environment({'relocated_repo_access_is_ok': False})
  24. assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'no'
  25. def test_make_environment_check_i_know_what_i_am_doing_true_should_set_environment_YES():
  26. environment = module.make_environment({'check_i_know_what_i_am_doing': True})
  27. assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'YES'
  28. def test_make_environment_check_i_know_what_i_am_doing_false_should_set_environment_NO():
  29. environment = module.make_environment({'check_i_know_what_i_am_doing': False})
  30. assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'NO'
  31. def test_make_environment_with_integer_variable_value():
  32. environment = module.make_environment({'borg_files_cache_ttl': 40})
  33. assert environment.get('BORG_FILES_CACHE_TTL') == '40'