test_normalize.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import pytest
  2. from borgmatic.config import normalize as module
  3. @pytest.mark.parametrize(
  4. 'config,expected_config,produces_logs',
  5. (
  6. (
  7. {'location': {'exclude_if_present': '.nobackup'}},
  8. {'location': {'exclude_if_present': ['.nobackup']}},
  9. False,
  10. ),
  11. (
  12. {'location': {'exclude_if_present': ['.nobackup']}},
  13. {'location': {'exclude_if_present': ['.nobackup']}},
  14. False,
  15. ),
  16. (
  17. {'location': {'source_directories': ['foo', 'bar']}},
  18. {'location': {'source_directories': ['foo', 'bar']}},
  19. False,
  20. ),
  21. (
  22. {'storage': {'compression': 'yes_please'}},
  23. {'storage': {'compression': 'yes_please'}},
  24. False,
  25. ),
  26. (
  27. {'hooks': {'healthchecks': 'https://example.com'}},
  28. {'hooks': {'healthchecks': {'ping_url': 'https://example.com'}}},
  29. False,
  30. ),
  31. (
  32. {'hooks': {'cronitor': 'https://example.com'}},
  33. {'hooks': {'cronitor': {'ping_url': 'https://example.com'}}},
  34. False,
  35. ),
  36. (
  37. {'hooks': {'pagerduty': 'https://example.com'}},
  38. {'hooks': {'pagerduty': {'integration_key': 'https://example.com'}}},
  39. False,
  40. ),
  41. (
  42. {'hooks': {'cronhub': 'https://example.com'}},
  43. {'hooks': {'cronhub': {'ping_url': 'https://example.com'}}},
  44. False,
  45. ),
  46. (
  47. {'consistency': {'checks': ['archives']}},
  48. {'consistency': {'checks': [{'name': 'archives'}]}},
  49. False,
  50. ),
  51. (
  52. {'location': {'repositories': ['foo@bar:/repo']}},
  53. {'location': {'repositories': ['ssh://foo@bar/repo']}},
  54. True,
  55. ),
  56. (
  57. {'location': {'repositories': ['foo@bar:repo']}},
  58. {'location': {'repositories': ['ssh://foo@bar/./repo']}},
  59. True,
  60. ),
  61. (
  62. {'location': {'repositories': ['foo@bar:~/repo']}},
  63. {'location': {'repositories': ['ssh://foo@bar/~/repo']}},
  64. True,
  65. ),
  66. (
  67. {'location': {'repositories': ['ssh://foo@bar/repo']}},
  68. {'location': {'repositories': ['ssh://foo@bar/repo']}},
  69. False,
  70. ),
  71. ),
  72. )
  73. def test_normalize_applies_hard_coded_normalization_to_config(
  74. config, expected_config, produces_logs
  75. ):
  76. logs = module.normalize('test.yaml', config)
  77. assert config == expected_config
  78. if produces_logs:
  79. assert logs
  80. else:
  81. assert logs == []