|
20 | 20 | _find_app_root, # pyright: ignore[reportPrivateUsage] |
21 | 21 | ) |
22 | 22 |
|
| 23 | +_SPLUNK_HOME = os.path.join(os.sep, "opt", "splunk") |
| 24 | +_APPS_DIRECTORY = os.path.join(_SPLUNK_HOME, "etc", "apps") |
| 25 | + |
23 | 26 |
|
24 | 27 | @pytest.mark.parametrize( |
25 | 28 | ("app_file_parts", "expected_app_root_parts"), |
26 | 29 | [ |
27 | | - (("apps", "my_app", "bin", "command.py"), ("apps", "my_app")), |
28 | | - (("apps", "my_app", "bin", "linux_x86_64", "command.py"), ("apps", "my_app")), |
29 | | - (("apps", "my_app", "bin", "foo", "bar", "command.py"), ("apps", "my_app")), |
30 | | - (("some", "other", "layout", "command.py"), ("some", "other")), |
| 30 | + # A script located directly in the app's bin directory |
| 31 | + (("my_app", "bin", "command.py"), ("my_app",)), |
| 32 | + # A script located in a subdirectory of bin, including one that happens to be |
| 33 | + # named "bin" itself; the app root is still $SPLUNK_HOME/etc/apps/my_app |
| 34 | + (("my_app", "bin", "foo", "bin", "command.py"), ("my_app",)), |
31 | 35 | ], |
32 | 36 | ) |
33 | 37 | def test_find_app_root( |
34 | 38 | app_file_parts: tuple[str, ...], expected_app_root_parts: tuple[str, ...] |
35 | 39 | ) -> None: |
36 | | - app_file = os.path.join(*app_file_parts) |
37 | | - assert _find_app_root(app_file) == os.path.abspath(os.path.join(*expected_app_root_parts)) |
| 40 | + app_file = os.path.join(_APPS_DIRECTORY, *app_file_parts) |
| 41 | + expected_app_root = os.path.join(_APPS_DIRECTORY, *expected_app_root_parts) |
| 42 | + assert _find_app_root(app_file, _SPLUNK_HOME) == expected_app_root |
| 43 | + |
| 44 | + |
| 45 | +def test_find_app_root_falls_back_on_nonstandard_splunk_home() -> None: |
| 46 | + app_file = os.path.join("some", "other", "layout", "command.py") |
| 47 | + expected_app_root = os.path.dirname(os.path.abspath(os.path.dirname(app_file))) |
| 48 | + assert _find_app_root(app_file, _SPLUNK_HOME) == expected_app_root |
0 commit comments