test_schema.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pkgutil
  2. import borgmatic.actions
  3. import borgmatic.config.load
  4. import borgmatic.config.validate
  5. MAXIMUM_LINE_LENGTH = 80
  6. def test_schema_line_length_stays_under_limit():
  7. schema_file = open(borgmatic.config.validate.schema_filename())
  8. for line in schema_file.readlines():
  9. assert len(line.rstrip('\n')) <= MAXIMUM_LINE_LENGTH
  10. ACTIONS_MODULE_NAMES_TO_OMIT = {
  11. 'arguments',
  12. 'change_passphrase',
  13. 'export_key',
  14. 'import_key',
  15. 'json',
  16. 'pattern',
  17. }
  18. ACTIONS_MODULE_NAMES_TO_ADD = {'key', 'umount'}
  19. def test_schema_actions_correspond_to_supported_actions():
  20. '''
  21. Ensure that the allowed actions in the schema's various options don't drift from borgmatic's
  22. actual supported actions.
  23. '''
  24. schema = borgmatic.config.load.load_configuration(borgmatic.config.validate.schema_filename())
  25. supported_actions = {
  26. module.name.replace('_', '-')
  27. for module in pkgutil.iter_modules(borgmatic.actions.__path__)
  28. if module.name not in ACTIONS_MODULE_NAMES_TO_OMIT
  29. }.union(ACTIONS_MODULE_NAMES_TO_ADD)
  30. properties = schema['properties']
  31. commands_one_of = properties['commands']['items']['oneOf']
  32. for schema_actions in (
  33. set(properties['skip_actions']['items']['enum']),
  34. set(commands_one_of[0]['properties']['when']['items']['enum']),
  35. set(commands_one_of[1]['properties']['when']['items']['enum']),
  36. ):
  37. assert schema_actions == supported_actions