浏览代码

Validate the configured action names in the "skip_actions" option (#804).

Dan Helfman 1 年之前
父节点
当前提交
9d6025e902
共有 3 个文件被更改,包括 47 次插入0 次删除
  1. 1 0
      NEWS
  2. 20 0
      borgmatic/config/schema.yaml
  3. 26 0
      tests/integration/config/test_schema.py

+ 1 - 0
NEWS

@@ -5,6 +5,7 @@
  * #794: Fix a traceback when the "repositories" option contains both strings and key/value pairs.
  * #794: Fix a traceback when the "repositories" option contains both strings and key/value pairs.
  * #800: Add configured repository labels to the JSON output for all actions.
  * #800: Add configured repository labels to the JSON output for all actions.
  * #802: The "check --force" flag now runs checks even if "check" is in "skip_actions".
  * #802: The "check --force" flag now runs checks even if "check" is in "skip_actions".
+ * #804: Validate the configured action names in the "skip_actions" option.
  * When logging commands that borgmatic executes, log the environment variables that
  * When logging commands that borgmatic executes, log the environment variables that
    borgmatic sets for those commands. (But don't log their values, since they often contain
    borgmatic sets for those commands. (But don't log their values, since they often contain
    passwords.)
    passwords.)

+ 20 - 0
borgmatic/config/schema.yaml

@@ -535,6 +535,26 @@ properties:
         type: array
         type: array
         items:
         items:
             type: string
             type: string
+            enum:
+                - rcreate
+                - transfer
+                - prune
+                - compact
+                - create
+                - check
+                - extract
+                - config
+                - export-tar
+                - mount
+                - umount
+                - restore
+                - rlist
+                - list
+                - rinfo
+                - info
+                - break-lock
+                - key
+                - borg
         description: |
         description: |
             List of one or more actions to skip running for this configuration
             List of one or more actions to skip running for this configuration
             file, even if specified on the command-line (explicitly or
             file, even if specified on the command-line (explicitly or

+ 26 - 0
tests/integration/config/test_schema.py

@@ -1,3 +1,9 @@
+import pkgutil
+
+import borgmatic.actions
+import borgmatic.config.load
+import borgmatic.config.validate
+
 MAXIMUM_LINE_LENGTH = 80
 MAXIMUM_LINE_LENGTH = 80
 
 
 
 
@@ -6,3 +12,23 @@ def test_schema_line_length_stays_under_limit():
 
 
     for line in schema_file.readlines():
     for line in schema_file.readlines():
         assert len(line.rstrip('\n')) <= MAXIMUM_LINE_LENGTH
         assert len(line.rstrip('\n')) <= MAXIMUM_LINE_LENGTH
+
+
+ACTIONS_MODULE_NAMES_TO_OMIT = {'arguments', 'export_key', 'json'}
+ACTIONS_MODULE_NAMES_TO_ADD = {'key', 'umount'}
+
+
+def test_schema_skip_actions_correspond_to_supported_actions():
+    '''
+    Ensure that the allowed actions in the schema's "skip_actions" option don't drift from
+    borgmatic's actual supported actions.
+    '''
+    schema = borgmatic.config.load.load_configuration(borgmatic.config.validate.schema_filename())
+    schema_skip_actions = set(schema['properties']['skip_actions']['items']['enum'])
+    supported_actions = {
+        module.name.replace('_', '-')
+        for module in pkgutil.iter_modules(borgmatic.actions.__path__)
+        if module.name not in ACTIONS_MODULE_NAMES_TO_OMIT
+    }.union(ACTIONS_MODULE_NAMES_TO_ADD)
+
+    assert schema_skip_actions == supported_actions