Skip to content

Commit afd7cee

Browse files
mgr/smb: add unit tests for custom_options funcs
Signed-off-by: John Mulligan <[email protected]>
1 parent a65ca9f commit afd7cee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/pybind/mgr/smb/tests/test_validation.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,38 @@ def test_valid_path(value, valid):
7575
else:
7676
with pytest.raises(ValueError):
7777
smb.validation.check_path(value)
78+
79+
80+
def _ovr(value):
81+
value[
82+
smb.validation.CUSTOM_CAUTION_KEY
83+
] = smb.validation.CUSTOM_CAUTION_VALUE
84+
return value
85+
86+
87+
@pytest.mark.parametrize(
88+
"value,errmatch",
89+
[
90+
({"foo": "bar"}, "lack"),
91+
(_ovr({"foo": "bar"}), ""),
92+
(_ovr({"foo": "bar", "zip": "zap"}), ""),
93+
(_ovr({"mod:foo": "bar", "zip": "zap"}), ""),
94+
(_ovr({"foo\n": "bar"}), "newlines"),
95+
(_ovr({"foo": "bar\n"}), "newlines"),
96+
(_ovr({"[foo]": "bar\n"}), "brackets"),
97+
],
98+
)
99+
def test_check_custom_options(value, errmatch):
100+
if not errmatch:
101+
smb.validation.check_custom_options(value)
102+
else:
103+
with pytest.raises(ValueError, match=errmatch):
104+
smb.validation.check_custom_options(value)
105+
106+
107+
def test_clean_custom_options():
108+
orig = {'foo': 'bar', 'big': 'bad', 'bugs': 'bongo'}
109+
updated = _ovr(dict(orig))
110+
smb.validation.check_custom_options(updated)
111+
assert smb.validation.clean_custom_options(updated) == orig
112+
assert smb.validation.clean_custom_options(None) is None

0 commit comments

Comments
 (0)