mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 15:42:10 +03:00
test: add error paths test for _add metric helper
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
8c99ac78b7
commit
59a1f7823e
1 changed files with 13 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from netsleuth.metrics import Metric, collect_metrics, render_csv, render_prometheus
|
from netsleuth.metrics import Metric, _add, collect_metrics, render_csv, render_prometheus
|
||||||
|
|
||||||
|
|
||||||
def _report(**overrides) -> dict:
|
def _report(**overrides) -> dict:
|
||||||
|
|
@ -84,3 +84,15 @@ def test_render_csv_has_a_header_row_and_quotes_a_comma_in_a_label():
|
||||||
lines = text.strip().splitlines()
|
lines = text.strip().splitlines()
|
||||||
assert lines[0] == "metric,labels,value"
|
assert lines[0] == "metric,labels,value"
|
||||||
assert '"target=a, b"' in lines[1]
|
assert '"target=a, b"' in lines[1]
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_ignores_uncastable_values():
|
||||||
|
metrics: list[Metric] = []
|
||||||
|
|
||||||
|
# Uncastable string raises ValueError
|
||||||
|
_add(metrics, "test_metric", "abc")
|
||||||
|
assert len(metrics) == 0
|
||||||
|
|
||||||
|
# Incompatible type like dict raises TypeError
|
||||||
|
_add(metrics, "test_metric", {"some": "dict"})
|
||||||
|
assert len(metrics) == 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue