diff --git a/tests/test_config.py b/tests/test_config.py index 8b3f470..99b8a5a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -282,6 +282,51 @@ def test_load_config_safe_external(self) -> None: SCUBA_YML.write_text(f"image: !from_yaml {external_yml} danger") self.__test_load_config_safe(external_yml) + def test_load_config_image_name(self) -> None: + """load_config loads a config using !from_yaml with nested keys""" + GITLAB_YML.write_text( + """ + one: + image: + name: "dummian:8.2" + """ + ) + config = load_config(config_text=f"image: !from_yaml {GITLAB_YML} one.image") + assert config.image == "dummian:8.2" + + def test_load_config_image_pull_policy(self) -> None: + """pull_policy can be always, if-not-present, or never""" + GITLAB_YML.write_text( + """ + build_all: + image: + name: "dummian:8.2" + entrypoint: ["/usr/bin/bash", "/opt/run_with_env.sh"] + """ + ) + config = load_config( + config_text=f"image: !from_yaml {GITLAB_YML} somewhere.down.here" + ) + assert config.image == "dummian:8.2" + + def test_load_config_image_pull_policy_array(self) -> None: + """ + for some reason, pull_policy can also be an array + containing always, if-not-present, or never + """ + GITLAB_YML.write_text( + """ + one: + image: + name: "dummian:8.2" + pull_policy: [always, if-not-present] + """ + ) + config = load_config( + config_text=f"policy: !from_yaml {GITLAB_YML} one.image" + ) + assert config.image == "dummian:8.2" + class TestConfigHooks(ConfigTest): def test_hooks_mixed(self) -> None: @@ -510,6 +555,39 @@ def test_alias_entrypoint(self) -> None: ) assert config.aliases["testalias"].entrypoint == "use_this_ep" + def test_image_single_entrypoint(self) -> None: + """gitlab images can have an array of entrypoints""" + GITLAB_YML.write_text( + """ + one: + image: + name: "dummian:8.2" + entrypoint: ["/usr/bin/bash"] + """ + ) + config = load_config( + config_text=f""" + image: !from_yaml {GITLAB_YML} one.image + entrypoint: !from_yaml {GITLAB_YML} one.image + """ + ) + assert config.image == "dummian:8.2" + assert config.entrypoint == "/usr/bin/bash" + + def test_image_multiple_entrypoints(self) -> None: + """gitlab images can have multiple entrypoints""" + GITLAB_YML.write_text( + """ + one: + image: + name: "dummian:8.2" + entrypoint: ["/usr/bin/bash", "/opt/run_with_env.sh"] + """ + ) + config = load_config(config_text=f"image: !from_yaml {GITLAB_YML} one.image") + assert config.image == "dummian:8.2" + assert config.entrypoint == "/usr/bin/bash" + class TestConfigDockerArgs(ConfigTest): def test_docker_args_not_set(self) -> None: @@ -1099,82 +1177,3 @@ def test_complex_empty(self) -> None: """, error_match="Volume /foo must have exactly one of 'hostpath' or 'name' subkey", ) - - def test_image_name(self) -> None: - """load_config loads a config using !from_yaml with nested keys""" - GITLAB_YML.write_text( - """ - one: - image: - name: "dummian:8.2" - """ - ) - config = load_config( - config_text=f"image: !from_yaml {GITLAB_YML} one.image" - ) - assert config.image == "dummian:8.2" - - def test_image_single_entrypoint(self) -> None: - """gitlab images can have an array of entrypoints""" - GITLAB_YML.write_text( - """ - build_all: - image: - name: "dummian:8.2" - entrypoint: ["/usr/bin/bash"] - script: "make -j24" - """ - ) - config = load_config( - config_text=f"image: !from_yaml {GITLAB_YML} somewhere.down.here" - ) - assert config.image == "dummian:8.2" - assert config.entrypoint == "/usr/bin/bash" - - def test_image_multiple_entrypoints(self) -> None: - """gitlab images can have multiple entrypoints""" - GITLAB_YML.write_text( - """ - one: - image: - name: "dummian:8.2" - entrypoint: ["/usr/bin/bash", "/opt/run_with_env.sh"] - """ - ) - config = load_config( - config_text=f"image: !from_yaml {GITLAB_YML} one.image" - ) - assert config.image == "dummian:8.2" - assert config.entrypoint == "/usr/bin/bash" - - def test_image_pull_policy(self) -> None: - """pull_policy can be always, if-not-present, or never""" - GITLAB_YML.write_text( - """ - build_all: - image: - name: "dummian:8.2" - entrypoint: ["/usr/bin/bash", "/opt/run_with_env.sh"] - script: "echo single pull policy" - """ - ) - config = load_config( - config_text=f"image: !from_yaml {GITLAB_YML} somewhere.down.here" - ) - assert config.image == "dummian:8.2" - - def test_image_pull_policy_array(self) -> None: - """pull_policy can also be an array containing always, if-not-present, or never""" - GITLAB_YML.write_text( - """ - build_all: - image: - name: "dummian:8.2" - pull_policy: [always, if-not-present] - script: "echo multiple pull policies (why?)" - """ - ) - config = load_config( - config_text=f"image: !from_yaml {GITLAB_YML} somewhere.down.here" - ) - assert config.image == "dummian:8.2" \ No newline at end of file