test: add unit tests for AlertmanagerClient (#876)#1194
test: add unit tests for AlertmanagerClient (#876)#1194muddlebee merged 1 commit intoTracer-Cloud:mainfrom
Conversation
Greptile SummaryThis PR adds 32 unit tests for Confidence Score: 4/5Safe to merge — only P2 findings (missing list_silences tests and a PR description count discrepancy); no logic or correctness issues found. All 32 tests are logically correct, mock the right targets, and match the production implementation's control flow. The only gaps are a missing test suite for list_silences and a one-off error in the PR description. No P0 or P1 findings. No files require special attention; tests/services/test_alertmanager_client.py could be extended with list_silences coverage. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[test suite entry] --> B{test category}
B --> C[Config tests\nbearer / basic-auth / is_configured / dual-auth]
B --> D[get_status tests\nsuccess / HTTP error / network error / endpoint]
B --> E[list_alerts tests\nsuccess / filters / HTTP error / empty / bad format / limit]
B --> F[Context-manager tests\nclose / idempotent / with-block / exception / returns-self]
B --> G[Factory tests\nmake_alertmanager_client\nbearer / basic-auth / no-url / normalize / strip]
B --> H[Probe access tests\nsuccess / failure / not-configured]
B --> I[NOT TESTED\nlist_silences]
C --> J[AlertmanagerConfig Pydantic model]
D --> K[AlertmanagerClient.get_status]
E --> L[AlertmanagerClient.list_alerts]
F --> M[AlertmanagerClient.close / __enter__ / __exit__]
G --> N[make_alertmanager_client factory]
H --> O[AlertmanagerClient.probe_access]
Reviews (1): Last reviewed commit: "test: add unit tests for AlertmanagerCli..." | Re-trigger Greptile |
24e436b to
d780828
Compare
|
🧑💻 @turancannb02 has entered the contributor hall of fame. Merged. Done. Shipped. Go touch grass (then come back with another PR). 🌱 👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome. |

Fixes #876
Describe the changes you have made in this PR -
Added 37 direct unit tests for the AlertmanagerClient class following the OpsGenie/Vercel test patterns. The tests use a
_FakeResponsehelper class and monkeypatch to mockhttpx.Client, ensuring no real HTTP calls are made.Coverage: 92% of
app/services/alertmanager/client.pyDemo/Screenshot for feature changes and bug fixes -
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
Added unit tests for AlertmanagerClient using the same mocking pattern as OpsGenie/Vercel client tests (
_FakeResponseclass with monkeypatch for httpx.Client). This ensures fast, isolated tests without real HTTP calls.Key components:
_FakeResponse: Mock HTTP response class that simulates success/error responses_client(): Helper factory for creating test clientsChecklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.