Skip to content

Commit 6d0890e

Browse files
committed
add tests
1 parent cf7586c commit 6d0890e

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

unit_test/oci_container_test.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import os
45
import platform
56
import random
@@ -18,15 +19,12 @@
1819

1920
# for these tests we use manylinux2014 images, because they're available on
2021
# multi architectures and include python3.8
22+
DEFAULT_IMAGE_TEMPLATE = "quay.io/pypa/manylinux2014_{machine}:2023-09-04-0828984"
2123
pm = platform.machine()
22-
if pm == "x86_64":
23-
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_x86_64:2020-05-17-2f8ac3b"
24+
if pm in {"x86_64", "ppc64le", "s390x"}:
25+
DEFAULT_IMAGE = DEFAULT_IMAGE_TEMPLATE.format(machine=pm)
2426
elif pm in {"aarch64", "arm64"}:
25-
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_aarch64:2020-05-17-2f8ac3b"
26-
elif pm == "ppc64le":
27-
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_ppc64le:2020-05-17-2f8ac3b"
28-
elif pm == "s390x":
29-
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_s390x:2020-05-17-2f8ac3b"
27+
DEFAULT_IMAGE = DEFAULT_IMAGE_TEMPLATE.format(machine="aarch64")
3028
else:
3129
DEFAULT_IMAGE = ""
3230

@@ -378,3 +376,24 @@ def test_parse_engine_config(config, name, create_args):
378376
engine_config = OCIContainerEngineConfig.from_config_string(config)
379377
assert engine_config.name == name
380378
assert engine_config.create_args == create_args
379+
380+
381+
@pytest.mark.skipif(pm != "x86_64", reason="Only runs on x86_64")
382+
@pytest.mark.parametrize(
383+
("image", "shell_args"),
384+
[
385+
(DEFAULT_IMAGE_TEMPLATE.format(machine="i686"), ["/bin/bash"]),
386+
(DEFAULT_IMAGE_TEMPLATE.format(machine="x86_64"), ["linux32", "/bin/bash"]),
387+
],
388+
)
389+
def test_enforce_32_bit(container_engine, image, shell_args):
390+
with OCIContainer(engine=container_engine, image=image, enforce_32_bit=True) as container:
391+
assert container.call(["uname", "-m"], capture_output=True).strip() == "i686"
392+
container_args = subprocess.run(
393+
f"{container.engine.name} inspect -f '{{{{json .Args }}}}' {container.name}",
394+
shell=True,
395+
check=True,
396+
stdout=subprocess.PIPE,
397+
text=True,
398+
).stdout
399+
assert json.loads(container_args) == shell_args

0 commit comments

Comments
 (0)