Skip to content

Commit

Permalink
test: More CLI coverage (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc authored Apr 29, 2024
1 parent 4ef2a23 commit 7d8519f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions anta/cli/debug/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ def wrapper(
# TODO: @gmuloc - tags come from context https://github.com/arista-netdevops-community/anta/issues/584
# pylint: disable=unused-argument
# ruff: noqa: ARG001
try:
d = inventory[device]
except KeyError as e:
message = f"Device {device} does not exist in Inventory"
logger.error(e, message)
if (d := inventory.get(device)) is None:
logger.error("Device '%s' does not exist in Inventory", device)
ctx.exit(ExitCode.USAGE_ERROR)
return f(*args, device=d, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions tests/units/cli/debug/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
pytest.param("show version", None, "1", None, "dummy", False, id="version"),
pytest.param("show version", None, None, 3, "dummy", False, id="revision"),
pytest.param("undefined", None, None, None, "dummy", True, id="command fails"),
pytest.param("undefined", None, None, None, "doesnotexist", True, id="Device does not exist"),
],
)
def test_run_cmd(
Expand Down
8 changes: 8 additions & 0 deletions tests/units/cli/nrfu/test__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_anta_nrfu_help(click_runner: CliRunner) -> None:
assert "Usage: anta nrfu" in result.output


def test_anta_nrfu_wrong_subcommand(click_runner: CliRunner) -> None:
"""Test anta nrfu toast."""
result = click_runner.invoke(anta, ["nrfu", "oook"])
assert result.exit_code == ExitCode.USAGE_ERROR
assert "Usage: anta nrfu" in result.output
assert "No such command 'oook'." in result.output


def test_anta_nrfu(click_runner: CliRunner) -> None:
"""Test anta nrfu, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu"])
Expand Down
14 changes: 14 additions & 0 deletions tests/units/cli/nrfu/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def test_anta_nrfu_table(click_runner: CliRunner) -> None:
assert "dummy │ VerifyEOSVersion │ success" in result.output


def test_anta_nrfu_table_group_by_device(click_runner: CliRunner) -> None:
"""Test anta nrfu, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu", "table", "--group-by", "device"])
assert result.exit_code == ExitCode.OK
assert "Summary per device" in result.output


def test_anta_nrfu_table_group_by_test(click_runner: CliRunner) -> None:
"""Test anta nrfu, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu", "table", "--group-by", "test"])
assert result.exit_code == ExitCode.OK
assert "Summary per test" in result.output


def test_anta_nrfu_text(click_runner: CliRunner) -> None:
"""Test anta nrfu, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu", "text"])
Expand Down

0 comments on commit 7d8519f

Please sign in to comment.