Skip to content

Commit f876a19

Browse files
authored
Add import tests (#1945)
1 parent c4ce007 commit f876a19

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test_app_imports.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import pytest
3+
4+
EXPECTED_LINES = [
5+
"import os\n",
6+
"\n",
7+
"from robusta.runner.ssl_utils import add_custom_certificate\n",
8+
"\n",
9+
'ADDITIONAL_CERTIFICATE: str = os.environ.get("CERTIFICATE", "")\n',
10+
"\n",
11+
"if add_custom_certificate(ADDITIONAL_CERTIFICATE):\n",
12+
' print("added custom certificate")\n',
13+
"\n",
14+
"# DO NOT ADD ANY CODE ABOVE THIS\n",
15+
"# ADDING IMPORTS BEFORE ADDING THE CUSTOM CERTS MIGHT INIT HTTP CLIENTS THAT DOESN'T RESPECT THE CUSTOM CERT\n",
16+
]
17+
18+
19+
@pytest.mark.parametrize(
20+
"file_path,file_name",
21+
[
22+
("src/robusta/runner/main.py", "main.py"),
23+
],
24+
)
25+
def test_app_files_have_correct_initial_lines(file_path, file_name):
26+
"""Test that app files start with the required certificate handling code."""
27+
full_path = os.path.join(os.path.dirname(__file__), "..", file_path)
28+
29+
with open(full_path, "r") as f:
30+
lines = f.readlines()
31+
32+
for i, expected_line in enumerate(EXPECTED_LINES):
33+
assert (
34+
lines[i] == expected_line
35+
), f"Line {i + 1} should be: {expected_line.strip()!r}, but got: {lines[i].strip()!r}. This tests make sure the import order in {file_name} file is correct, if you see this, go to {file_name} file and move your imports code to lower lines."

0 commit comments

Comments
 (0)