|
| 1 | +from subprocess import run |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +IMPLEMENTATIONS_TO_TRY = ["apptainer", "singularity"] |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY) |
| 9 | +def test_oci(implementation): |
| 10 | + cmd = [implementation, "exec", "docker://centos:7"] |
| 11 | + cmd += ["bash", "-c", "echo Hello world $(( 1+1 ))!"] |
| 12 | + proc = run(cmd, capture_output=True, check=True, text=True) |
| 13 | + assert proc.stdout == "Hello world 2!\n" |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY) |
| 17 | +def test_build_image(implementation, tmp_path): |
| 18 | + cmd = [implementation, "build", "--fix-perms", "--sandbox"] |
| 19 | + cmd += [tmp_path / "container", "docker://centos:7"] |
| 20 | + run(cmd, capture_output=True, check=True, text=True) |
| 21 | + assert (tmp_path / "container" / "bin").is_dir() |
| 22 | + assert (tmp_path / "container" / "bin" / "bash").is_file() |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY) |
| 26 | +def test_singularity_ce(implementation, tmp_path): |
| 27 | + test_build_image(implementation, tmp_path) |
| 28 | + |
| 29 | + (tmp_path / "work").mkdir() |
| 30 | + (tmp_path / "home").mkdir() |
| 31 | + (tmp_path / "cvmfs").mkdir() |
| 32 | + |
| 33 | + cmd = [implementation, "exec", "--contain", "--ipc", "--pid", "--userns"] |
| 34 | + cmd += ["--workdir", tmp_path / "work", "--home", tmp_path / "home"] |
| 35 | + cmd += ["--bind", tmp_path / "cvmfs", tmp_path / "container"] |
| 36 | + cmd += ["bash", "-c", "echo Hello world $(( 1+1+1 ))!"] |
| 37 | + proc = run(cmd, capture_output=True, check=True, text=True) |
| 38 | + assert proc.stdout == "Hello world 3!\n" |
0 commit comments