test_normalize.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. ({'location': None}, {'location': None}, False,),
  22. (
  23. {'storage': {'compression': 'yes_please'}},
  24. {'storage': {'compression': 'yes_please'}},
  25. False,
  26. ),
  27. ({'storage': None}, {'storage': None}, False,),
  28. (
  29. {'hooks': {'healthchecks': 'https://example.com'}},
  30. {'hooks': {'healthchecks': {'ping_url': 'https://example.com'}}},
  31. False,
  32. ),
  33. (
  34. {'hooks': {'cronitor': 'https://example.com'}},
  35. {'hooks': {'cronitor': {'ping_url': 'https://example.com'}}},
  36. False,
  37. ),
  38. (
  39. {'hooks': {'pagerduty': 'https://example.com'}},
  40. {'hooks': {'pagerduty': {'integration_key': 'https://example.com'}}},
  41. False,
  42. ),
  43. (
  44. {'hooks': {'cronhub': 'https://example.com'}},
  45. {'hooks': {'cronhub': {'ping_url': 'https://example.com'}}},
  46. False,
  47. ),
  48. ({'hooks': None}, {'hooks': None}, False,),
  49. (
  50. {'consistency': {'checks': ['archives']}},
  51. {'consistency': {'checks': [{'name': 'archives'}]}},
  52. False,
  53. ),
  54. (
  55. {'consistency': {'checks': ['archives']}},
  56. {'consistency': {'checks': [{'name': 'archives'}]}},
  57. False,
  58. ),
  59. ({'consistency': None}, {'consistency': None}, False,),
  60. ({'location': {'numeric_owner': False}}, {'location': {'numeric_ids': False}}, False,),
  61. ({'location': {'bsd_flags': False}}, {'location': {'flags': False}}, False,),
  62. (
  63. {'storage': {'remote_rate_limit': False}},
  64. {'storage': {'upload_rate_limit': False}},
  65. False,
  66. ),
  67. (
  68. {'location': {'repositories': ['foo@bar:/repo']}},
  69. {'location': {'repositories': ['ssh://foo@bar/repo']}},
  70. True,
  71. ),
  72. (
  73. {'location': {'repositories': ['foo@bar:repo']}},
  74. {'location': {'repositories': ['ssh://foo@bar/./repo']}},
  75. True,
  76. ),
  77. (
  78. {'location': {'repositories': ['foo@bar:~/repo']}},
  79. {'location': {'repositories': ['ssh://foo@bar/~/repo']}},
  80. True,
  81. ),
  82. (
  83. {'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
  84. {'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
  85. False,
  86. ),
  87. ),
  88. )
  89. def test_normalize_applies_hard_coded_normalization_to_config(
  90. config, expected_config, produces_logs
  91. ):
  92. logs = module.normalize('test.yaml', config)
  93. assert config == expected_config
  94. if produces_logs:
  95. assert logs
  96. else:
  97. assert logs == []