Skip to content

Commit b12ce76

Browse files
committed
vcrtrace: improve API doc
CMK-27519 Change-Id: I4b15ed856a1d72b24474c1c1ecda711ec18bab16
1 parent 40b44aa commit b12ce76

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

packages/cmk-plugin-apis/cmk/server_side_programs/v1_unstable/_vcrtrace.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def _check_path(filename: str) -> None:
2020
allowed_path = (Path.home() / "tmp" / "debug").resolve()
2121
if not p.is_relative_to(allowed_path):
2222
raise ValueError(f"Traces can only be stored in {allowed_path}")
23+
if not (p_dir := p.parent).is_dir():
24+
raise NotADirectoryError(f"Directory {p_dir} does not exist")
2325

2426

2527
def vcrtrace(
@@ -40,6 +42,7 @@ def vcrtrace(
4042
all requests the program sends and their corresponding answers will be recorded in said file.
4143
If the file already exists, no requests are sent to the server, but the responses will be
4244
replayed from the tracefile.
45+
TRACEFILE must be a file path within the directory `~/tmp/debug`; `~/tmp/debug` must exist.
4346
4447
The destination attribute will be set to `True` if the option was specified, the
4548
provided default otherwise.

packages/cmk-plugin-apis/tests/cmk/server_side_programs/v1/test_vcrtrace.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,40 @@ def _mocked_home(tmp_path: Path) -> Iterator[Path]:
1919
yield tmp_path
2020

2121

22-
def test_check_path_relative(mocked_home: Path) -> None:
22+
def test_check_path_relative_ok(mocked_home: Path) -> None:
23+
(mocked_home / "tmp/debug").mkdir(parents=True, exist_ok=True)
2324
with chdir(mocked_home):
24-
with pytest.raises(ValueError):
25-
_check_path("foo")
2625
_check_path("tmp/debug/foo")
2726

28-
some_dir = mocked_home / "foobar"
29-
some_dir.mkdir()
30-
with chdir(some_dir):
31-
with pytest.raises(ValueError):
32-
_check_path("tmp/debug/foo")
33-
_check_path("../tmp/debug/foo")
27+
28+
def test_check_path_relative_missing(mocked_home: Path) -> None:
29+
with chdir(mocked_home), pytest.raises(NotADirectoryError):
30+
_check_path("tmp/debug/foo")
31+
32+
33+
def test_check_path_relative_too_far_down(mocked_home: Path) -> None:
34+
(mocked_home / "tmp/debug").mkdir(parents=True, exist_ok=True)
35+
with chdir(mocked_home / "tmp"), pytest.raises(ValueError):
36+
_check_path("tmp/debug/foo")
37+
38+
39+
def test_check_path_relative_too_far_up(mocked_home: Path) -> None:
40+
(mocked_home / "tmp/debug").mkdir(parents=True, exist_ok=True)
41+
with chdir(mocked_home / ".."), pytest.raises(ValueError):
42+
_check_path("tmp/debug/foo")
43+
44+
45+
def test_check_path_absolute_ok(mocked_home: Path) -> None:
46+
(mocked_home / "tmp/debug").mkdir(parents=True, exist_ok=True)
47+
_check_path(str(mocked_home / "tmp/debug/foo"))
48+
49+
50+
def test_check_path_absolute_missing(mocked_home: Path) -> None:
51+
with pytest.raises(NotADirectoryError):
52+
_check_path(str(mocked_home / "tmp/debug/foo"))
3453

3554

36-
def test_check_path_absolute(mocked_home: Path) -> None:
37-
with pytest.raises(ValueError):
38-
_check_path(str(mocked_home / "foo"))
39-
_check_path(str(mocked_home / "tmp" / "debug" / "foo"))
55+
def test_check_path_absolute_invalid(mocked_home: Path) -> None:
56+
(mocked_home / "tmp/debug").mkdir(parents=True, exist_ok=True)
57+
with chdir(mocked_home / "tmp"), pytest.raises(ValueError):
58+
_check_path(str(mocked_home / "tmp/degug/foo"))

0 commit comments

Comments
 (0)