test_mount.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import mount as module
  4. from ..test_verbosity import insert_logging_mock
  5. def insert_execute_command_mock(command):
  6. flexmock(module.environment).should_receive('make_environment')
  7. flexmock(module).should_receive('execute_command').with_args(
  8. command, borg_local_path='borg', extra_environment=None,
  9. ).once()
  10. def test_mount_archive_calls_borg_with_required_parameters():
  11. insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
  12. module.mount_archive(
  13. repository='repo',
  14. archive='archive',
  15. mount_point='/mnt',
  16. paths=None,
  17. foreground=False,
  18. options=None,
  19. storage_config={},
  20. )
  21. def test_mount_archive_calls_borg_with_path_parameters():
  22. insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
  23. module.mount_archive(
  24. repository='repo',
  25. archive='archive',
  26. mount_point='/mnt',
  27. paths=['path1', 'path2'],
  28. foreground=False,
  29. options=None,
  30. storage_config={},
  31. )
  32. def test_mount_archive_calls_borg_with_remote_path_parameters():
  33. insert_execute_command_mock(
  34. ('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt')
  35. )
  36. module.mount_archive(
  37. repository='repo',
  38. archive='archive',
  39. mount_point='/mnt',
  40. paths=None,
  41. foreground=False,
  42. options=None,
  43. storage_config={},
  44. remote_path='borg1',
  45. )
  46. def test_mount_archive_calls_borg_with_umask_parameters():
  47. insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
  48. module.mount_archive(
  49. repository='repo',
  50. archive='archive',
  51. mount_point='/mnt',
  52. paths=None,
  53. foreground=False,
  54. options=None,
  55. storage_config={'umask': '0770'},
  56. )
  57. def test_mount_archive_calls_borg_with_lock_wait_parameters():
  58. insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt'))
  59. module.mount_archive(
  60. repository='repo',
  61. archive='archive',
  62. mount_point='/mnt',
  63. paths=None,
  64. foreground=False,
  65. options=None,
  66. storage_config={'lock_wait': '5'},
  67. )
  68. def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
  69. insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
  70. insert_logging_mock(logging.INFO)
  71. module.mount_archive(
  72. repository='repo',
  73. archive='archive',
  74. mount_point='/mnt',
  75. paths=None,
  76. foreground=False,
  77. options=None,
  78. storage_config={},
  79. )
  80. def test_mount_archive_with_log_debug_calls_borg_with_debug_parameters():
  81. insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
  82. insert_logging_mock(logging.DEBUG)
  83. module.mount_archive(
  84. repository='repo',
  85. archive='archive',
  86. mount_point='/mnt',
  87. paths=None,
  88. foreground=False,
  89. options=None,
  90. storage_config={},
  91. )
  92. def test_mount_archive_calls_borg_with_foreground_parameter():
  93. flexmock(module.environment).should_receive('make_environment')
  94. flexmock(module).should_receive('execute_command').with_args(
  95. ('borg', 'mount', '--foreground', 'repo::archive', '/mnt'),
  96. output_file=module.DO_NOT_CAPTURE,
  97. borg_local_path='borg',
  98. extra_environment=None,
  99. ).once()
  100. module.mount_archive(
  101. repository='repo',
  102. archive='archive',
  103. mount_point='/mnt',
  104. paths=None,
  105. foreground=True,
  106. options=None,
  107. storage_config={},
  108. )
  109. def test_mount_archive_calls_borg_with_options_parameters():
  110. insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
  111. module.mount_archive(
  112. repository='repo',
  113. archive='archive',
  114. mount_point='/mnt',
  115. paths=None,
  116. foreground=False,
  117. options='super_mount',
  118. storage_config={},
  119. )