test_mount.py 3.8 KB

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