File: test_bfd.py

package info (click to toggle)
anta 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,048 kB
  • sloc: python: 48,164; sh: 28; javascript: 9; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,580 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) 2023-2025 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.input_models.bfd.py."""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from pydantic import ValidationError

from anta.tests.bfd import VerifyBFDPeersIntervals, VerifyBFDPeersRegProtocols

if TYPE_CHECKING:
    from anta.input_models.bfd import BFDPeer


class TestVerifyBFDPeersIntervalsInput:
    """Test anta.tests.bfd.VerifyBFDPeersIntervals.Input."""

    @pytest.mark.parametrize(
        ("bfd_peers"),
        [
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3}], id="valid"),
        ],
    )
    def test_valid(self, bfd_peers: list[BFDPeer]) -> None:
        """Test VerifyBFDPeersIntervals.Input valid inputs."""
        VerifyBFDPeersIntervals.Input(bfd_peers=bfd_peers)

    @pytest.mark.parametrize(
        ("bfd_peers"),
        [
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default", "tx_interval": 1200}], id="invalid-tx-interval"),
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default", "rx_interval": 1200}], id="invalid-rx-interval"),
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200}], id="invalid-multiplier"),
        ],
    )
    def test_invalid(self, bfd_peers: list[BFDPeer]) -> None:
        """Test VerifyBFDPeersIntervals.Input invalid inputs."""
        with pytest.raises(ValidationError):
            VerifyBFDPeersIntervals.Input(bfd_peers=bfd_peers)


class TestVerifyBFDPeersRegProtocolsInput:
    """Test anta.tests.bfd.VerifyBFDPeersRegProtocols.Input."""

    @pytest.mark.parametrize(
        ("bfd_peers"),
        [
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default", "protocols": ["bgp"]}], id="valid"),
        ],
    )
    def test_valid(self, bfd_peers: list[BFDPeer]) -> None:
        """Test VerifyBFDPeersRegProtocols.Input valid inputs."""
        VerifyBFDPeersRegProtocols.Input(bfd_peers=bfd_peers)

    @pytest.mark.parametrize(
        ("bfd_peers"),
        [
            pytest.param([{"peer_address": "10.0.0.1", "vrf": "default"}], id="invalid"),
        ],
    )
    def test_invalid(self, bfd_peers: list[BFDPeer]) -> None:
        """Test VerifyBFDPeersRegProtocols.Input invalid inputs."""
        with pytest.raises(ValidationError):
            VerifyBFDPeersRegProtocols.Input(bfd_peers=bfd_peers)