From: John Mulligan Date: Thu, 9 May 2024 18:43:24 +0000 (-0400) Subject: mgr/smb: add unit tests for custom_options funcs X-Git-Tag: v20.0.0~1709^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F57294%2Fhead;p=ceph.git mgr/smb: add unit tests for custom_options funcs Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/tests/test_validation.py b/src/pybind/mgr/smb/tests/test_validation.py index 6210c179c88a..f44c03097986 100644 --- a/src/pybind/mgr/smb/tests/test_validation.py +++ b/src/pybind/mgr/smb/tests/test_validation.py @@ -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