test_mount.py 3.7 KB

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