Skip to content

Commit

Permalink
Increase test coverage of containerfile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrews committed Oct 13, 2023
1 parent d250606 commit 9f1f13a
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion test/unit/test_containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# pylint: disable=W0212


def make_containerfile(tmpdir, ee_path, **cf_kwargs):
def make_containerfile(tmpdir, ee_path, run_validate=False, **cf_kwargs):
definition = UserDefinition(ee_path)
if run_validate:
definition.validate()
build_context = str(tmpdir / '_build')
c = Containerfile(definition, build_context=build_context, container_runtime='podman', **cf_kwargs)
return c
Expand Down Expand Up @@ -119,3 +121,49 @@ def test_prepare_galaxy_install_steps_with_ignore_code(build_dir_and_ee_yml):
f"--keyring \"{constants.default_keyring_name}\""
]
assert c.steps == expected


def test_v2_custom_builder_image(build_dir_and_ee_yml):
"""
Test that a customer builder image in the v2 schema is used (not valid for v3).
"""
ee_data = [
'version: 2',
'images:',
' base_image:',
' name: quay.io/user/mycustombaseimage:latest',
' builder_image:',
' name: quay.io/user/mycustombuilderimage:latest',
]
tmpdir, ee_path = build_dir_and_ee_yml("\n".join(ee_data))
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert 'ARG EE_BUILDER_IMAGE="quay.io/user/mycustombuilderimage:latest"' in c.steps
assert "FROM $EE_BUILDER_IMAGE as builder" in c.steps


def test_v3_various(build_dir_and_ee_yml):
"""
Test various v3 expected outputs appear in the Containerfile.
"""
ee_data = [
'version: 3',
'images:',
' base_image:',
' name: quay.io/user/mycustombaseimage:latest',
'options:',
' skip_ansible_check: False',
' relax_passwd_permissions: True',
' workdir: /myworkdir',
' container_init:',
' package_pip: dumb-init==x.y.z',
' user: myuser',
]
tmpdir, ee_path = build_dir_and_ee_yml("\n".join(ee_data))
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "RUN /output/scripts/check_ansible $PYCMD" in c.steps
assert "RUN chmod ug+rw /etc/passwd" in c.steps
assert "RUN mkdir -p /myworkdir && chgrp 0 /myworkdir && chmod -R ug+rwx /myworkdir" in c.steps
assert "RUN $PYCMD -m pip install --no-cache-dir 'dumb-init==x.y.z'" in c.steps
assert "USER myuser" in c.steps

0 comments on commit 9f1f13a

Please sign in to comment.