Skip to content

Commit f43df0f

Browse files
Brandon Duane Walkermr-c
Brandon Duane Walker
authored andcommitted
add test for building Dockerfile
1 parent a0f982f commit f43df0f

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_tmpdir.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,64 @@ def test_dockerfile_tmpdir_prefix(tmp_path: Path, monkeypatch: pytest.MonkeyPatc
168168
assert (subdir / "Dockerfile").exists()
169169

170170

171+
@needs_docker
172+
def test_dockerfile_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
173+
"""Test that DockerCommandLineJob.get_image builds a Dockerfile."""
174+
(tmp_path / "out").mkdir()
175+
tmp_outdir_prefix = tmp_path / "out" / "1"
176+
(tmp_path / "3").mkdir()
177+
tmpdir_prefix = str(tmp_path / "3" / "ttmp")
178+
runtime_context = RuntimeContext(
179+
{"tmpdir_prefix": tmpdir_prefix, "user_space_docker_cmd": None}
180+
)
181+
builder = Builder(
182+
{},
183+
[],
184+
[],
185+
{},
186+
schema.Names(),
187+
[],
188+
[],
189+
{},
190+
None,
191+
None,
192+
StdFsAccess,
193+
StdFsAccess(""),
194+
None,
195+
0.1,
196+
False,
197+
False,
198+
False,
199+
"no_listing",
200+
runtime_context.get_outdir(),
201+
runtime_context.get_tmpdir(),
202+
runtime_context.get_stagedir(),
203+
INTERNAL_VERSION,
204+
"docker",
205+
)
206+
207+
docker_image_id = sys._getframe().f_code.co_name
208+
209+
assert DockerCommandLineJob(
210+
builder, {}, CommandLineTool.make_path_mapper, [], [], ""
211+
).get_image(
212+
{
213+
"class": "DockerRequirement",
214+
"dockerFile": "FROM debian:stable-slim",
215+
"dockerImageId": docker_image_id,
216+
},
217+
pull_image=False,
218+
force_pull=False,
219+
tmp_outdir_prefix=str(tmp_outdir_prefix),
220+
)
221+
output = subprocess.check_output(
222+
["docker", "images", "--quiet", docker_image_id], stderr=subprocess.STDOUT, text=True
223+
)
224+
225+
# If the output is empty, the image doesn't exist
226+
assert output.strip(), f"Docker image {docker_image_id} does not exist"
227+
228+
171229
@needs_singularity
172230
def test_dockerfile_singularity_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
173231
"""Test that SingularityCommandLineJob.get_image builds a Dockerfile with Singularity."""

0 commit comments

Comments
 (0)