2025-02-05 11:32:35 +01:00
|
|
|
# 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.
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Tests for anta.cli.nrfu.commands."""
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
2025-02-05 11:39:09 +01:00
|
|
|
from typing import TYPE_CHECKING
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
from anta.cli import anta
|
|
|
|
from anta.cli.utils import ExitCode
|
|
|
|
|
2025-02-05 11:39:09 +01:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
DATA_DIR: Path = Path(__file__).parent.parent.parent.parent.resolve() / "data"
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_table_help(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu table --help."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "table", "--help"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "Usage: anta nrfu table" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_text_help(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu text --help."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "text", "--help"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "Usage: anta nrfu text" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_json_help(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu json --help."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "json", "--help"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "Usage: anta nrfu json" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_template_help(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu tpl-report --help."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "tpl-report", "--help"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "Usage: anta nrfu tpl-report" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_table(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu, catalog is given via env."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "table"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "dummy │ VerifyEOSVersion │ success" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_text(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu, catalog is given via env."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "text"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "dummy :: VerifyEOSVersion :: SUCCESS" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_json(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu, catalog is given via env."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "json"])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
2025-02-05 11:39:09 +01:00
|
|
|
assert "JSON results" in result.output
|
|
|
|
match = re.search(r"\[\n {[\s\S]+ }\n\]", result.output)
|
|
|
|
assert match is not None
|
|
|
|
result_list = json.loads(match.group())
|
|
|
|
for res in result_list:
|
|
|
|
if res["name"] == "dummy":
|
|
|
|
assert res["test"] == "VerifyEOSVersion"
|
|
|
|
assert res["result"] == "success"
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_anta_nrfu_template(click_runner: CliRunner) -> None:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Test anta nrfu, catalog is given via env."""
|
2025-02-05 11:32:35 +01:00
|
|
|
result = click_runner.invoke(anta, ["nrfu", "tpl-report", "--template", str(DATA_DIR / "template.j2")])
|
|
|
|
assert result.exit_code == ExitCode.OK
|
|
|
|
assert "* VerifyEOSVersion is SUCCESS for dummy" in result.output
|