Debian Codegraph @

ansible_collections/community/docker/tests/unit/plugins/modules/test_docker_network.py

raw
1 # Copyright (c) Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 """Unit tests for docker_network."""
6
7 from __future__ import annotations
8
9 import typing as t
10
11 import pytest
12
13 from ansible_collections.community.docker.plugins.modules.docker_network import (
14 validate_cidr,
15 )
16
17
18 @pytest.mark.parametrize(
19 "cidr,expected",
20 [
21 ("192.168.0.1/16", "ipv4"),
22 ("192.168.0.1/24", "ipv4"),
23 ("192.168.0.1/32", "ipv4"),
24 ("fdd1:ac8c:0557:7ce2::/64", "ipv6"),
25 ("fdd1:ac8c:0557:7ce2::/128", "ipv6"),
26 ],
27 )
28 def test_validate_cidr_positives(
29 cidr: str, expected: t.Literal["ipv4", "ipv6"]
30 ) -> None:
31 assert validate_cidr(cidr) == expected
32
33
34 @pytest.mark.parametrize(
35 "cidr",
36 [
37 "192.168.0.1",
38 "192.168.0.1/34",
39 "192.168.0.1/asd",
40 "fdd1:ac8c:0557:7ce2::",
41 ],
42 )
43 def test_validate_cidr_negatives(cidr: str) -> None:
44 with pytest.raises(ValueError) as e:
45 validate_cidr(cidr)
46 assert f'"{cidr}" is not a valid CIDR' == str(e.value)