45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
# retoor <retoor@molodetz.nl>
|
|||
|
|
|
||
|
|
from devplacepy.services.containers.backend.docker_cli import (
|
||
|
|
COMMAND_NOT_FOUND,
|
||
|
|
DockerCliBackend,
|
||
|
|
)
|
||
|
|
from tests.conftest import run_async
|
||
|
|
|
||
|
|
MISSING = "devplace-no-such-container-cli"
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_missing_cli_is_a_command_not_found_result_not_an_exception():
|
||
|
|
backend = DockerCliBackend(binary=MISSING)
|
||
|
|
code, out, err = run_async(backend._run([MISSING, "ps"]))
|
||
|
|
assert code == COMMAND_NOT_FOUND == 127
|
||
|
|
assert out == ""
|
||
|
|
assert MISSING in err and "not found" in err
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_missing_cli_means_the_image_does_not_exist():
|
||
|
|
backend = DockerCliBackend(binary=MISSING)
|
||
|
|
assert run_async(backend.image_exists("ppy:latest")) is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_missing_cli_reports_through_the_stream_callback():
|
||
|
|
backend = DockerCliBackend(binary=MISSING)
|
||
|
|
lines = []
|
||
|
|
|
||
|
|
async def on_log(line):
|
||
|
|
lines.append(line)
|
||
|
|
|
||
|
|
code = run_async(backend._stream([MISSING, "run"], on_log))
|
||
|
|
assert code == COMMAND_NOT_FOUND
|
||
|
|
assert lines == [f"{MISSING}: command not found"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_failing_check_names_the_missing_cli():
|
||
|
|
backend = DockerCliBackend(binary=MISSING)
|
||
|
|
try:
|
||
|
|
run_async(backend._check([MISSING, "info"]))
|
||
|
|
except RuntimeError as exc:
|
||
|
|
assert "127" in str(exc) and "not found" in str(exc)
|
||
|
|
else:
|
||
|
|
raise AssertionError("expected a RuntimeError")
|