test: фаза 4 — тесты extractors, ecosystem, i18n, metrics
- test_nexus.py: extract_pypi/go/npm, dispatch, edge cases (16 тестов) - test_i18n.py: RU/EN переводы, fallback, форматирование, web UI (10 тестов) - test_metrics.py: Prometheus endpoint (4 теста) - test_webhooks.py: _detect_ecosystem (6 тестов), Go/npm webhook fixtures - conftest.py: sample_nexus_go/npm_webhook fixtures - Всего: 85 тестов (было 50)
This commit is contained in:
35
tests/test_metrics.py
Normal file
35
tests/test_metrics.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Tests for Prometheus metrics endpoint."""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metrics_returns_200(client):
|
||||
resp = await client.get("/metrics")
|
||||
assert resp.status_code == 200
|
||||
assert "text/plain" in resp.headers["content-type"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metrics_contains_keys(client):
|
||||
resp = await client.get("/metrics")
|
||||
text = resp.text
|
||||
assert "guarddog_scans_total" in text
|
||||
assert "guarddog_scans_flagged_total" in text
|
||||
assert "guarddog_findings_total" in text
|
||||
assert "guarddog_scans_by_status" in text
|
||||
assert "guarddog_scans_by_ecosystem" in text
|
||||
# last_scan may not be present if no scans exist
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metrics_help_section(client):
|
||||
resp = await client.get("/metrics")
|
||||
assert "# HELP" in resp.text
|
||||
assert "# TYPE" in resp.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metrics_last_scan_with_data(client, sample_flagged_scan):
|
||||
resp = await client.get("/metrics")
|
||||
assert "guarddog_last_scan_timestamp_seconds" in resp.text
|
||||
Reference in New Issue
Block a user