Skip to content

Commit

Permalink
draft: move/rework tests
Browse files Browse the repository at this point in the history
  • Loading branch information
funkecoder23 authored and funkecoder23 committed May 27, 2024
1 parent 0f6f348 commit cd80d06
Showing 1 changed file with 78 additions and 79 deletions.
157 changes: 78 additions & 79 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"

0 comments on commit cd80d06

Please sign in to comment.