test_borgmatic.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import json
  2. import sys
  3. from flexmock import flexmock
  4. from borgmatic.commands import borgmatic
  5. def test__run_commands_handles_multiple_json_outputs_in_array():
  6. (
  7. flexmock(borgmatic)
  8. .should_receive('_run_commands_on_repository')
  9. .times(3)
  10. .replace_with(
  11. lambda args, consistency, json_results, local_path, location, remote_path, retention, storage, unexpanded_repository: json_results.append(
  12. {"whatever": unexpanded_repository}
  13. )
  14. )
  15. )
  16. (
  17. flexmock(sys.stdout)
  18. .should_call("write")
  19. .with_args(
  20. json.dumps(
  21. json.loads(
  22. '''
  23. [
  24. {"whatever": "fake_repo1"},
  25. {"whatever": "fake_repo2"},
  26. {"whatever": "fake_repo3"}
  27. ]
  28. '''
  29. )
  30. )
  31. )
  32. )
  33. borgmatic._run_commands(
  34. args=flexmock(json=True),
  35. consistency=None,
  36. local_path=None,
  37. location={'repositories': ['fake_repo1', 'fake_repo2', 'fake_repo3']},
  38. remote_path=None,
  39. retention=None,
  40. storage=None,
  41. )