From afd7cee74f2d6848dc309ffa612f27f2447d7405 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 9 May 2024 14:43:24 -0400 Subject: [PATCH] mgr/smb: add unit tests for custom_options funcs Signed-off-by: John Mulligan --- src/pybind/mgr/smb/tests/test_validation.py | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 -- 2.47.3