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 438db3c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cwltool/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def get_image(
dockerfile_dir,
]
_logger.info(str(cmd))

Check warning on line 140 in cwltool/docker.py

View check run for this annotation

Codecov / codecov/patch

cwltool/docker.py#L140

Added line #L140 was not covered by tests
subprocess.check_call(cmd, stdout=sys.stderr) # nosec
# check_call doesn't work when using pytest
subprocess.run(cmd, check=True, stdout=sys.stderr, stderr=subprocess.PIPE)
found = True

Check warning on line 143 in cwltool/docker.py

View check run for this annotation

Codecov / codecov/patch

cwltool/docker.py#L142-L143

Added lines #L142 - L143 were not covered by tests

if (force_pull or not found) and pull_image:
Expand Down
57 changes: 57 additions & 0 deletions tests/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,63 @@ 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 438db3c

Please sign in to comment.