summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2022-07-29 19:57:30 +0200
committerGitHub <noreply@github.com>2022-07-29 13:57:30 -0400
commit1a4cacdfb63f0fbf2299962732c75484c24ad8b0 (patch)
tree97e4a946482b669750e5553056e028599e14d96b /tests
parent26064dd6b584ee14878157b4c8b001eefed70caf (diff)
downloaddocker-py-1a4cacdfb63f0fbf2299962732c75484c24ad8b0.tar.gz
api: add platform to container create (#2927)
Add platform parameter for container creation/run Signed-off-by: Felix Fontein <felix@fontein.de> Signed-off-by: Milas Bowman <milas.bowman@docker.com> Co-authored-by: Milas Bowman <milas.bowman@docker.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/api_container_test.py16
-rw-r--r--tests/unit/models_containers_test.py29
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py
index 7030841..3a2fbde 100644
--- a/tests/unit/api_container_test.py
+++ b/tests/unit/api_container_test.py
@@ -348,6 +348,22 @@ class CreateContainerTest(BaseAPIClientTest):
assert args[1]['headers'] == {'Content-Type': 'application/json'}
assert args[1]['params'] == {'name': 'marisa-kirisame'}
+ def test_create_container_with_platform(self):
+ self.client.create_container('busybox', 'true',
+ platform='linux')
+
+ args = fake_request.call_args
+ assert args[0][1] == url_prefix + 'containers/create'
+ assert json.loads(args[1]['data']) == json.loads('''
+ {"Tty": false, "Image": "busybox", "Cmd": ["true"],
+ "AttachStdin": false,
+ "AttachStderr": true, "AttachStdout": true,
+ "StdinOnce": false,
+ "OpenStdin": false, "NetworkDisabled": false}
+ ''')
+ assert args[1]['headers'] == {'Content-Type': 'application/json'}
+ assert args[1]['params'] == {'name': None, 'platform': 'linux'}
+
def test_create_container_with_mem_limit_as_int(self):
self.client.create_container(
'busybox', 'true', host_config=self.client.create_host_config(
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py
index 785a849..e4ee074 100644
--- a/tests/unit/models_containers_test.py
+++ b/tests/unit/models_containers_test.py
@@ -77,6 +77,7 @@ class ContainerCollectionTest(unittest.TestCase):
oom_score_adj=5,
pid_mode='host',
pids_limit=500,
+ platform='linux',
ports={
1111: 4567,
2222: None
@@ -186,6 +187,7 @@ class ContainerCollectionTest(unittest.TestCase):
name='somename',
network_disabled=False,
networking_config={'foo': None},
+ platform='linux',
ports=[('1111', 'tcp'), ('2222', 'tcp')],
stdin_open=True,
stop_signal=9,
@@ -314,6 +316,33 @@ class ContainerCollectionTest(unittest.TestCase):
'NetworkMode': 'default'}
)
+ def test_run_platform(self):
+ client = make_fake_client()
+
+ # raise exception on first call, then return normal value
+ client.api.create_container.side_effect = [
+ docker.errors.ImageNotFound(""),
+ client.api.create_container.return_value
+ ]
+
+ client.containers.run(image='alpine', platform='linux/arm64')
+
+ client.api.pull.assert_called_with(
+ 'alpine',
+ tag='latest',
+ all_tags=False,
+ stream=True,
+ platform='linux/arm64',
+ )
+
+ client.api.create_container.assert_called_with(
+ detach=False,
+ platform='linux/arm64',
+ image='alpine',
+ command=None,
+ host_config={'NetworkMode': 'default'},
+ )
+
def test_create(self):
client = make_fake_client()
container = client.containers.create(