diff --git a/test/unit/test_containerfile.py b/test/unit/test_containerfile.py index 6664f043..47fc5add 100644 --- a/test/unit/test_containerfile.py +++ b/test/unit/test_containerfile.py @@ -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 @@ -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