Fixed test_webui only failing in nix_sandbox also fixed test_create_flake

This commit is contained in:
Qubasa
2023-10-29 19:51:35 +01:00
parent 4209da96e9
commit 7a8eef0648
4 changed files with 11 additions and 45 deletions

View File

@@ -21,14 +21,11 @@ def command_exec(cmd: List[str], work_dir: Path, env: Dict[str, str]) -> None:
def block_for_input() -> None: def block_for_input() -> None:
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
procid = os.getpid() procid = os.getpid()
command = f"echo 'continue' > /sys/proc/{procid}/fd/{sys.stdin.fileno()}" f"echo 'continue' > /sys/proc/{procid}/fd/{sys.stdin.fileno()}"
while True: while True:
log.warning("Use sudo cntr attach <pid> to attach to the container.") log.warning("Use sudo cntr attach <pid> to attach to the container.")
log.warning("Resume execution by executing '%s' in cntr shell", command) # log.warning("Resume execution by executing '%s' in cntr shell", command)
res = input("Input 'continue' to resume execution: ")
if res == "continue":
break
time.sleep(1) time.sleep(1)
log.info("Resuming execution.") log.info("Resuming execution.")

View File

@@ -25,7 +25,7 @@ def test_create_flake_api(
response = api.post( response = api.post(
"/api/flake/create", "/api/flake/create",
json=dict( json=dict(
dest=str(flake_dir), flake_name=str(flake_dir),
url=str(DEFAULT_URL), url=str(DEFAULT_URL),
), ),
) )

View File

@@ -1,44 +1,13 @@
import json import json
import logging import logging
from pathlib import Path
import pytest import pytest
from api import TestClient from api import TestClient
from fixtures_flakes import FlakeForTest from fixtures_flakes import FlakeForTest
from clan_cli.flakes.create import DEFAULT_URL
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@pytest.mark.impure
def test_flake_create(api: TestClient, temporary_home: Path) -> None:
params = {"flake_name": "defaultFlake", "url": str(DEFAULT_URL)}
response = api.post(
"/api/flake/create",
json=params,
)
response.json()
assert response.status_code == 201, "Failed to create flake"
# @pytest.mark.impure
# def test_flake_create_fail(api: TestClient, temporary_home: Path) -> None:
# params = {
# "flake_name": "../../../defaultFlake/",
# "url": str(DEFAULT_URL)
# }
# response = api.post(
# "/api/flake/create",
# json=params,
# )
# data = response.json()
# log.debug("Data: %s", data)
# assert response.status_code == 422, "This should have failed"
@pytest.mark.impure @pytest.mark.impure
def test_inspect_ok(api: TestClient, test_flake_with_core: FlakeForTest) -> None: def test_inspect_ok(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
params = {"url": str(test_flake_with_core.path)} params = {"url": str(test_flake_with_core.path)}

View File

@@ -5,13 +5,12 @@ import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
import pytest
from cli import Cli from cli import Cli
from ports import PortFunction from ports import PortFunction
from clan_cli.debug import breakpoint_container
@pytest.mark.timeout(10)
# @pytest.mark.timeout(10)
def test_start_server(unused_tcp_port: PortFunction, temporary_home: Path) -> None: def test_start_server(unused_tcp_port: PortFunction, temporary_home: Path) -> None:
Cli() Cli()
port = unused_tcp_port() port = unused_tcp_port()
@@ -38,15 +37,16 @@ echo "1" > {fifo}
env["PATH"] = f"{temporary_home}:{env['PATH']}" env["PATH"] = f"{temporary_home}:{env['PATH']}"
# Add build/src to PYTHONPATH so that the webui module is found in nix sandbox # Add build/src to PYTHONPATH so that the webui module is found in nix sandbox
# TODO: We need a way to make sure things which work in the devshell also work in the sandbox
python_path = env.get("PYTHONPATH") python_path = env.get("PYTHONPATH")
if python_path: if python_path:
env["PYTHONPATH"] = f"/build/src:{python_path}" env["PYTHONPATH"] = f"/build/src:{python_path}"
breakpoint_container( # breakpoint_container(
cmd=[sys.executable, "-m", "clan_cli.webui", "--port", str(port)], # cmd=[sys.executable, "-m", "clan_cli.webui", "--port", str(port)],
env=env, # env=env,
work_dir=temporary_home, # work_dir=temporary_home,
) # )
with subprocess.Popen( with subprocess.Popen(
[sys.executable, "-m", "clan_cli.webui", "--port", str(port)], [sys.executable, "-m", "clan_cli.webui", "--port", str(port)],