ansible/test/units/modules/cloud/docker/test_docker_network.py
Stephan Müller 00bab2d24d [docker_network] add ipv6 support (#47492)
* [docker_network] add ipv6 support

* docker_network: review ipam_options

* docker_network: fix requirements

* docker_network: fix deprecation notice

* docker_network: add minimum docker version change

* docker_network: remove trailing whitespace

* docker_network: revert rename of network_four #discussion_r228707101

* docker_network: refactor IPAM config comparison #discussion_r228707255, #discussion_r228707280

* docker_network: correct spelling of IPv4 and IPv6 #discussion_r228707114, #discussion_r228707138

* docker_network: manually remove networks #discussion_r228709051

* docker_network: refactor enable_ipv6 condition #discussion_r228707317

* docker_network: add mutually_exclusive #discussion_r228707185

* docker_network: fix iprange #discussion_r228709072

* docker_network: add auxiliary addresses in examples and tests

* docker_network: link to docker docs #discussion_r228707018

* docker_network: remove list default #discussion_r228707060, #discussion_r228709091

* docker_network: introduce params syntax for create_network() #discussion_r228709031

* docker_network: beautify code

* docker_network: resolve change requests

* docker_network: add yaml header

* docker_networking: fix get_ip_version

* docker_network: extend CIDR test

* docker_network: use backported unittest2 for python 2.6

* docker_network: migrate unittest to pytest
2018-11-02 08:59:16 +10:00

27 lines
760 B
Python

"""Unit tests for docker_network."""
import pytest
from ansible.modules.cloud.docker.docker_network import get_ip_version
@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'),
])
def test_get_ip_version_positives(cidr, expected):
assert get_ip_version(cidr) == expected
@pytest.mark.parametrize("cidr", [
'192.168.0.1',
'192.168.0.1/34',
'192.168.0.1/asd',
'fdd1:ac8c:0557:7ce2::',
])
def test_get_ip_version_negatives(cidr):
with pytest.raises(ValueError) as e:
get_ip_version(cidr)
assert '"{0}" is not a valid CIDR'.format(cidr) == str(e.value)