Skip to content

Commit

Permalink
topotato: add vtysh output compare filters
Browse files Browse the repository at this point in the history
Allow the test to do some text mangling beyond what the template
supports.

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Sep 17, 2024
1 parent d50538b commit 1d73a71
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion topotato/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import (
cast,
Any,
Callable,
ClassVar,
List,
Optional,
Expand Down Expand Up @@ -235,8 +236,12 @@ class AssertVtysh(TimedMixin, TopotatoAssertion):
_daemon: str
_command: str
_compare: Optional[str]
_filters: List[Callable[[str], str]]

default_delay = 0.1
default_filters = [
lambda t: deindent(t, trim=True),
]

posargs = ["rtr", "daemon", "command", "compare"]

Expand All @@ -249,6 +254,7 @@ def __init__(
daemon,
command,
compare=None,
filters=None,
**kwargs,
):
command_cleaned = command
Expand All @@ -270,6 +276,7 @@ def __init__(
self._daemon = daemon
self._command = self._cmdprefix + command
self._compare = compare
self._filters = filters or self.default_filters

def __call__(self):
router = cast("FRRRouterNS", self.instance.routers[self._rtr.name])
Expand All @@ -289,7 +296,8 @@ def __call__(self):
if isinstance(self._compare, type(None)):
pass
elif isinstance(self._compare, str):
text = deindent(text, trim=True)
for filterfn in self._filters:
text = filterfn(text)
result = text_rich_cmp(
router._configs,
text,
Expand Down

0 comments on commit 1d73a71

Please sign in to comment.