Exemple #1
0
def test_bash_alt_subst() -> None:
    step = {"step": "run", "cmd": "${EXAMPLE:+baz}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    env = {"EXAMPLE": "foo"}
    mzcompose._substitute_env_vars(one, env)
    assert step["cmd"] == "baz"

    step = {"step": "run", "cmd": "${EXAMPLE:+baz}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    del env["EXAMPLE"]
    mzcompose._substitute_env_vars(one, env)
    assert step["cmd"] == ""

    step = {"step": "run", "cmd": "${EXAMPLE}${EXAMPLE:+baz}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    env = {"EXAMPLE": "foo"}
    mzcompose._substitute_env_vars(one, env)
    assert step["cmd"] == "foobaz"

    step = {"step": "run", "cmd": "${EXAMPLE:-bar}${EXAMPLE:+baz}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    del env["EXAMPLE"]
    mzcompose._substitute_env_vars(one, env)
    assert step["cmd"] == "bar"
Exemple #2
0
def test_bash_subst() -> None:
    step = {"step": "run", "cmd": "${EXAMPLE}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    os.environ["EXAMPLE"] = "foo"
    mzcompose._substitute_env_vars(one)
    assert step["cmd"] == "foo"

    step = {"step": "run", "cmd": "${EXAMPLE:-bar}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    del os.environ["EXAMPLE"]
    mzcompose._substitute_env_vars(one)
    assert step["cmd"] == "bar"

    step = {"step": "run", "cmd": "${NOPE NOPE}"}
    one = {"mzconduct": {"workflows": {"ci": {"steps": [step]}}}}
    mzcompose._substitute_env_vars(one)
    assert step["cmd"] == "${NOPE NOPE}"