add integration test for webui
This commit is contained in:
10
pkgs/clan-cli/clan_cli/webui/__main__.py
Normal file
10
pkgs/clan-cli/clan_cli/webui/__main__.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import argparse
|
||||||
|
|
||||||
|
from . import register_parser
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# this is use in our integration test
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
register_parser(parser)
|
||||||
|
args = parser.parse_args()
|
||||||
|
args.func(args)
|
||||||
38
pkgs/clan-cli/tests/test_webui.py
Normal file
38
pkgs/clan-cli/tests/test_webui.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
import select
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from ports import Ports
|
||||||
|
|
||||||
|
|
||||||
|
def test_start_server(ports: Ports, temporary_dir: Path) -> None:
|
||||||
|
port = ports.allocate(1)
|
||||||
|
|
||||||
|
fifo = temporary_dir / "fifo"
|
||||||
|
os.mkfifo(fifo)
|
||||||
|
notify_script = temporary_dir / "notify.sh"
|
||||||
|
bash = shutil.which("bash")
|
||||||
|
assert bash is not None
|
||||||
|
notify_script.write_text(
|
||||||
|
f"""#!{bash}
|
||||||
|
set -x
|
||||||
|
echo "1" > {fifo}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
notify_script.chmod(0o700)
|
||||||
|
|
||||||
|
env = os.environ.copy()
|
||||||
|
env["BROWSER"] = str(notify_script)
|
||||||
|
with subprocess.Popen(
|
||||||
|
[sys.executable, "-m", "clan_cli.webui", "--port", str(port)], env=env
|
||||||
|
) as p:
|
||||||
|
try:
|
||||||
|
with open(fifo) as f:
|
||||||
|
r, _, _ = select.select([f], [], [], 10)
|
||||||
|
assert f in r
|
||||||
|
assert f.read().strip() == "1"
|
||||||
|
finally:
|
||||||
|
p.kill()
|
||||||
Reference in New Issue
Block a user