test_normalize.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. ({'location': {'numeric_owner': False}}, {'location': {'numeric_ids': False}}, False,),
  52. ({'location': {'bsd_flags': False}}, {'location': {'flags': False}}, False,),
  53. (
  54. {'storage': {'remote_rate_limit': False}},
  55. {'storage': {'upload_rate_limit': False}},
  56. False,
  57. ),
  58. (
  59. {'location': {'repositories': ['foo@bar:/repo']}},
  60. {'location': {'repositories': ['ssh://foo@bar/repo']}},
  61. True,
  62. ),
  63. (
  64. {'location': {'repositories': ['foo@bar:repo']}},
  65. {'location': {'repositories': ['ssh://foo@bar/./repo']}},
  66. True,
  67. ),
  68. (
  69. {'location': {'repositories': ['foo@bar:~/repo']}},
  70. {'location': {'repositories': ['ssh://foo@bar/~/repo']}},
  71. True,
  72. ),
  73. (
  74. {'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
  75. {'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
  76. False,
  77. ),
  78. ),
  79. )
  80. def test_normalize_applies_hard_coded_normalization_to_config(
  81. config, expected_config, produces_logs
  82. ):
  83. logs = module.normalize('test.yaml', config)
  84. assert config == expected_config
  85. if produces_logs:
  86. assert logs
  87. else:
  88. assert logs == []