diff options
| author | Mariano Scazzariello <marianoscazzariello@gmail.com> | 2023-01-27 15:26:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-27 09:26:21 -0500 |
| commit | ee9151f33611f693958a29c38ab0fbf5b6741c1b (patch) | |
| tree | 0c3f9f403df0dad1bc712387f48431136e5bcef2 /tests/unit | |
| parent | 2494d63f36eba0e1811f05e7b2136f8b30f7cdb7 (diff) | |
| download | docker-py-ee9151f33611f693958a29c38ab0fbf5b6741c1b.tar.gz | |
client: add `network_driver_opt` to container run and create (#3083)
Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/models_containers_test.py | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 101708e..d2a7ea5 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -74,6 +74,7 @@ class ContainerCollectionTest(unittest.TestCase): name='somename', network_disabled=False, network='foo', + network_driver_opt={'key1': 'a'}, oom_kill_disable=True, oom_score_adj=5, pid_mode='host', @@ -188,7 +189,7 @@ class ContainerCollectionTest(unittest.TestCase): mac_address='abc123', name='somename', network_disabled=False, - networking_config={'foo': None}, + networking_config={'foo': {'driver_opt': {'key1': 'a'}}}, platform='linux', ports=[('1111', 'tcp'), ('2222', 'tcp')], stdin_open=True, @@ -345,6 +346,42 @@ class ContainerCollectionTest(unittest.TestCase): host_config={'NetworkMode': 'default'}, ) + def test_run_network_driver_opts_without_network(self): + client = make_fake_client() + + with pytest.raises(RuntimeError): + client.containers.run( + image='alpine', + network_driver_opt={'key1': 'a'} + ) + + def test_run_network_driver_opts_with_network_mode(self): + client = make_fake_client() + + with pytest.raises(RuntimeError): + client.containers.run( + image='alpine', + network_mode='none', + network_driver_opt={'key1': 'a'} + ) + + def test_run_network_driver_opts(self): + client = make_fake_client() + + client.containers.run( + image='alpine', + network='foo', + network_driver_opt={'key1': 'a'} + ) + + client.api.create_container.assert_called_with( + detach=False, + image='alpine', + command=None, + networking_config={'foo': {'driver_opt': {'key1': 'a'}}}, + host_config={'NetworkMode': 'foo'} + ) + def test_create(self): client = make_fake_client() container = client.containers.create( @@ -372,6 +409,51 @@ class ContainerCollectionTest(unittest.TestCase): host_config={'NetworkMode': 'default'} ) + def test_create_network_driver_opts_without_network(self): + client = make_fake_client() + + client.containers.create( + image='alpine', + network_driver_opt={'key1': 'a'} + ) + + client.api.create_container.assert_called_with( + image='alpine', + command=None, + host_config={'NetworkMode': 'default'} + ) + + def test_create_network_driver_opts_with_network_mode(self): + client = make_fake_client() + + client.containers.create( + image='alpine', + network_mode='none', + network_driver_opt={'key1': 'a'} + ) + + client.api.create_container.assert_called_with( + image='alpine', + command=None, + host_config={'NetworkMode': 'none'} + ) + + def test_create_network_driver_opts(self): + client = make_fake_client() + + client.containers.create( + image='alpine', + network='foo', + network_driver_opt={'key1': 'a'} + ) + + client.api.create_container.assert_called_with( + image='alpine', + command=None, + networking_config={'foo': {'driver_opt': {'key1': 'a'}}}, + host_config={'NetworkMode': 'foo'} + ) + def test_get(self): client = make_fake_client() container = client.containers.get(FAKE_CONTAINER_ID) |
