summaryrefslogtreecommitdiffstats
path: root/tests/units/cli/debug
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/cli/debug')
-rw-r--r--tests/units/cli/debug/__init__.py3
-rw-r--r--tests/units/cli/debug/test__init__.py30
-rw-r--r--tests/units/cli/debug/test_commands.py60
3 files changed, 93 insertions, 0 deletions
diff --git a/tests/units/cli/debug/__init__.py b/tests/units/cli/debug/__init__.py
new file mode 100644
index 0000000..e772bee
--- /dev/null
+++ b/tests/units/cli/debug/__init__.py
@@ -0,0 +1,3 @@
+# Copyright (c) 2023-2024 Arista Networks, Inc.
+# Use of this source code is governed by the Apache License 2.0
+# that can be found in the LICENSE file.
diff --git a/tests/units/cli/debug/test__init__.py b/tests/units/cli/debug/test__init__.py
new file mode 100644
index 0000000..062182d
--- /dev/null
+++ b/tests/units/cli/debug/test__init__.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2023-2024 Arista Networks, Inc.
+# Use of this source code is governed by the Apache License 2.0
+# that can be found in the LICENSE file.
+"""
+Tests for anta.cli.debug
+"""
+from __future__ import annotations
+
+from click.testing import CliRunner
+
+from anta.cli import anta
+from anta.cli.utils import ExitCode
+
+
+def test_anta_debug(click_runner: CliRunner) -> None:
+ """
+ Test anta debug
+ """
+ result = click_runner.invoke(anta, ["debug"])
+ assert result.exit_code == ExitCode.OK
+ assert "Usage: anta debug" in result.output
+
+
+def test_anta_debug_help(click_runner: CliRunner) -> None:
+ """
+ Test anta debug --help
+ """
+ result = click_runner.invoke(anta, ["debug", "--help"])
+ assert result.exit_code == ExitCode.OK
+ assert "Usage: anta debug" in result.output
diff --git a/tests/units/cli/debug/test_commands.py b/tests/units/cli/debug/test_commands.py
new file mode 100644
index 0000000..6d9ac29
--- /dev/null
+++ b/tests/units/cli/debug/test_commands.py
@@ -0,0 +1,60 @@
+# Copyright (c) 2023-2024 Arista Networks, Inc.
+# Use of this source code is governed by the Apache License 2.0
+# that can be found in the LICENSE file.
+"""
+Tests for anta.cli.debug.commands
+"""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Literal
+
+import pytest
+
+from anta.cli import anta
+from anta.cli.utils import ExitCode
+
+if TYPE_CHECKING:
+ from click.testing import CliRunner
+
+
+@pytest.mark.parametrize(
+ "command, ofmt, version, revision, device, failed",
+ [
+ pytest.param("show version", "json", None, None, "dummy", False, id="json command"),
+ pytest.param("show version", "text", None, None, "dummy", False, id="text command"),
+ pytest.param("show version", None, "latest", None, "dummy", False, id="version-latest"),
+ 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"),
+ ],
+)
+def test_run_cmd(
+ click_runner: CliRunner, command: str, ofmt: Literal["json", "text"], version: Literal["1", "latest"] | None, revision: int | None, device: str, failed: bool
+) -> None:
+ """
+ Test `anta debug run-cmd`
+ """
+ # pylint: disable=too-many-arguments
+ cli_args = ["-l", "debug", "debug", "run-cmd", "--command", command, "--device", device]
+
+ # ofmt
+ if ofmt is not None:
+ cli_args.extend(["--ofmt", ofmt])
+
+ # version
+ if version is not None:
+ cli_args.extend(["--version", version])
+
+ # revision
+ if revision is not None:
+ cli_args.extend(["--revision", str(revision)])
+
+ result = click_runner.invoke(anta, cli_args)
+ if failed:
+ assert result.exit_code == ExitCode.USAGE_ERROR
+ else:
+ assert result.exit_code == ExitCode.OK
+ if revision is not None:
+ assert f"revision={revision}" in result.output
+ if version is not None:
+ assert (f"version='{version}'" if version == "latest" else f"version={version}") in result.output