Skip to content

Commit

Permalink
add test for building Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Duane Walker authored and Brandon Duane Walker committed Feb 27, 2024
1 parent 6c64a8b commit 7611ad9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,64 @@ def test_dockerfile_tmpdir_prefix(tmp_path: Path, monkeypatch: pytest.MonkeyPatc
assert (subdir / "Dockerfile").exists()


@needs_docker
def test_dockerfile_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
"""Test that DockerCommandLineJob.get_image builds a Dockerfile."""
monkeypatch.setattr(target=subprocess, name="check_call", value=lambda *args, **kwargs: True)
(tmp_path / "out").mkdir()
tmp_outdir_prefix = tmp_path / "out" / "1"
(tmp_path / "3").mkdir()
tmpdir_prefix = str(tmp_path / "3" / "ttmp")
runtime_context = RuntimeContext(
{"tmpdir_prefix": tmpdir_prefix, "user_space_docker_cmd": None}
)
builder = Builder(
{},
[],
[],
{},
schema.Names(),
[],
[],
{},
None,
None,
StdFsAccess,
StdFsAccess(""),
None,
0.1,
False,
False,
False,
"no_listing",
runtime_context.get_outdir(),
runtime_context.get_tmpdir(),
runtime_context.get_stagedir(),
INTERNAL_VERSION,
"docker",
)

docker_image_id = sys._getframe().f_code.co_name

assert DockerCommandLineJob(
builder, {}, CommandLineTool.make_path_mapper, [], [], ""
).get_image(
{
"class": "DockerRequirement",
"dockerFile": "FROM debian:stable-slim",
"dockerImageId": docker_image_id,
},
pull_image=False,
force_pull=False,
tmp_outdir_prefix=str(tmp_outdir_prefix),
)
output = subprocess.check_output(["docker", "images", "--quiet", docker_image_id], \
stderr=subprocess.STDOUT, text=True)

# If the output is empty, the image doesn't exist
assert output.strip(), f"Docker image {docker_image_id} does not exist"


@needs_singularity
def test_dockerfile_singularity_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
"""Test that SingularityCommandLineJob.get_image builds a Dockerfile with Singularity."""
Expand Down

0 comments on commit 7611ad9

Please sign in to comment.