Skip to content

Commit 02b7511

Browse files
author
Dementii Priadko
committed
Merge branch 'fix-broken-tests' into 'main'
Update reporter tests according to the code changes See merge request postgres-ai/postgres_ai!81
2 parents 7014def + 9023ca7 commit 02b7511

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

tests/reporter/test_formatters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ def test_format_report_data_structure(generator: PostgresReportGenerator) -> Non
7070
payload = generator.format_report_data("A002", {"foo": "bar"}, host)
7171

7272
assert payload["checkId"] == "A002"
73-
assert payload["hosts"]["master"] == host
73+
# Newer reporter returns a 'nodes' structure instead of legacy 'hosts'.
74+
assert payload["nodes"]["primary"] == host
7475
assert payload["results"][host]["data"] == {"foo": "bar"}

tests/reporter/test_generators_unit.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,11 @@ class DummyGenerator:
784784
def __init__(self, *args, **kwargs):
785785
self.closed = False
786786

787+
def get_all_clusters(self):
788+
# Match current reporter.main() behavior which always calls
789+
# get_all_clusters() when cluster is not explicitly provided.
790+
return ["local"]
791+
787792
def test_connection(self) -> bool:
788793
return True
789794

@@ -799,7 +804,19 @@ def close_postgres_sink(self):
799804
postgres_reports_module.main()
800805

801806
captured = capsys.readouterr().out
802-
output = json.loads(captured)
807+
808+
# main() prints progress banners along with the JSON payload.
809+
# Extract the JSON object from the captured stdout by finding the
810+
# first line that looks like JSON and joining from there.
811+
lines = captured.splitlines()
812+
start_idx = 0
813+
for i, line in enumerate(lines):
814+
if line.strip().startswith("{"):
815+
start_idx = i
816+
break
817+
json_str = "\n".join(lines[start_idx:])
818+
819+
output = json.loads(json_str)
803820
assert output["checkId"] == "A002"
804821
assert "results" in output
805822

0 commit comments

Comments
 (0)