2018-11-01 23:59:16 +01:00
|
|
|
"""Unit tests for docker_network."""
|
2019-08-09 23:50:11 +02:00
|
|
|
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2018-11-01 23:59:16 +01:00
|
|
|
import pytest
|
|
|
|
|
2019-12-29 23:16:17 +01:00
|
|
|
from ansible.modules.cloud.docker.docker_network import validate_cidr
|
2018-11-01 23:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("cidr,expected", [
|
|
|
|
('192.168.0.1/16', 'ipv4'),
|
|
|
|
('192.168.0.1/24', 'ipv4'),
|
|
|
|
('192.168.0.1/32', 'ipv4'),
|
|
|
|
('fdd1:ac8c:0557:7ce2::/64', 'ipv6'),
|
|
|
|
('fdd1:ac8c:0557:7ce2::/128', 'ipv6'),
|
|
|
|
])
|
2019-12-29 23:16:17 +01:00
|
|
|
def test_validate_cidr_positives(cidr, expected):
|
|
|
|
assert validate_cidr(cidr) == expected
|
2018-11-01 23:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("cidr", [
|
|
|
|
'192.168.0.1',
|
|
|
|
'192.168.0.1/34',
|
|
|
|
'192.168.0.1/asd',
|
|
|
|
'fdd1:ac8c:0557:7ce2::',
|
|
|
|
])
|
2019-12-29 23:16:17 +01:00
|
|
|
def test_validate_cidr_negatives(cidr):
|
2018-11-01 23:59:16 +01:00
|
|
|
with pytest.raises(ValueError) as e:
|
2019-12-29 23:16:17 +01:00
|
|
|
validate_cidr(cidr)
|
2018-11-01 23:59:16 +01:00
|
|
|
assert '"{0}" is not a valid CIDR'.format(cidr) == str(e.value)
|