]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add unit tests for custom_options funcs 57294/head
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 9 May 2024 18:43:24 +0000 (14:43 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 17 Jun 2024 15:17:00 +0000 (11:17 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_validation.py

index 6210c179c88ac4b797cc3a82eca9af9d8dd44b57..f44c03097986da0b51858480ac42f685a06e6ea2 100644 (file)
@@ -75,3 +75,38 @@ def test_valid_path(value, valid):
     else:
         with pytest.raises(ValueError):
             smb.validation.check_path(value)
+
+
+def _ovr(value):
+    value[
+        smb.validation.CUSTOM_CAUTION_KEY
+    ] = smb.validation.CUSTOM_CAUTION_VALUE
+    return value
+
+
+@pytest.mark.parametrize(
+    "value,errmatch",
+    [
+        ({"foo": "bar"}, "lack"),
+        (_ovr({"foo": "bar"}), ""),
+        (_ovr({"foo": "bar", "zip": "zap"}), ""),
+        (_ovr({"mod:foo": "bar", "zip": "zap"}), ""),
+        (_ovr({"foo\n": "bar"}), "newlines"),
+        (_ovr({"foo": "bar\n"}), "newlines"),
+        (_ovr({"[foo]": "bar\n"}), "brackets"),
+    ],
+)
+def test_check_custom_options(value, errmatch):
+    if not errmatch:
+        smb.validation.check_custom_options(value)
+    else:
+        with pytest.raises(ValueError, match=errmatch):
+            smb.validation.check_custom_options(value)
+
+
+def test_clean_custom_options():
+    orig = {'foo': 'bar', 'big': 'bad', 'bugs': 'bongo'}
+    updated = _ovr(dict(orig))
+    smb.validation.check_custom_options(updated)
+    assert smb.validation.clean_custom_options(updated) == orig
+    assert smb.validation.clean_custom_options(None) is None