105 lines
3.1 KiB
Bash
Executable File
105 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -uo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
PYTHONPATH="$ROOT/lib" python3 - <<'PY'
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from classroom_config import dock_items, ensure_device_config, read_device_config
|
|
|
|
passed = failed = 0
|
|
|
|
|
|
def check(label, condition, detail=""):
|
|
global passed, failed
|
|
if condition:
|
|
print(f" ok {label}")
|
|
passed += 1
|
|
else:
|
|
print(f" FAIL {label}")
|
|
if detail:
|
|
print(f" {detail}")
|
|
failed += 1
|
|
|
|
|
|
print("1. dock capabilities")
|
|
cases = [
|
|
({}, ("browser",)),
|
|
({"DVD_ENABLED": "true"}, ("browser", "dvd")),
|
|
({"LIVE_ENABLED": "true"}, ("browser", "live")),
|
|
(
|
|
{"DVD_ENABLED": "true", "LIVE_ENABLED": "true"},
|
|
("browser", "dvd", "live"),
|
|
),
|
|
]
|
|
|
|
for config, expected in cases:
|
|
actual = dock_items(config)
|
|
check(f"{config or 'both disabled'} -> {expected}", actual == expected, actual)
|
|
|
|
check(
|
|
"false spellings do not leave placeholder items",
|
|
dock_items({"DVD_ENABLED": "false", "LIVE_ENABLED": "off"}) == ("browser",),
|
|
)
|
|
check(
|
|
"existing dock order is browser, DVD, LIVE",
|
|
dock_items({"DVD_ENABLED": "yes", "LIVE_ENABLED": "1"})
|
|
== ("browser", "dvd", "live"),
|
|
)
|
|
|
|
print()
|
|
print("2. fresh device configuration")
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / "etc" / "device.conf"
|
|
ensure_device_config(path)
|
|
config = read_device_config(path)
|
|
check("fresh config is created", path.is_file())
|
|
check("DVD defaults off", config.get("DVD_ENABLED") == "false")
|
|
check("LIVE defaults off", config.get("LIVE_ENABLED") == "false")
|
|
check("MQTT defaults off", config.get("MQTT_ENABLED") == "false")
|
|
check("stable remains the fresh-install default", config.get("CHANNEL") == "stable")
|
|
|
|
print()
|
|
print("3. upgrade from 0.1.36")
|
|
old = """# endpoint configuration from 0.1.36
|
|
UPDATE_URL=https://updates.example.test
|
|
CHANNEL=canary
|
|
DVD_ENABLED=true
|
|
UI_SCALE=1.25
|
|
MQTT_ENABLED=true
|
|
MQTT_HOST=broker.example.test
|
|
MQTT_PORT=1884
|
|
MQTT_USERNAME=room
|
|
MQTT_PASSWORD=secret
|
|
CUSTOM_SETTING=keep-me
|
|
"""
|
|
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / "device.conf"
|
|
path.write_text(old)
|
|
|
|
ensure_device_config(path)
|
|
first = path.read_text()
|
|
config = read_device_config(path)
|
|
|
|
check("old bytes remain at the start", first.startswith(old))
|
|
check("channel survives", config.get("CHANNEL") == "canary")
|
|
check("DVD choice survives", config.get("DVD_ENABLED") == "true")
|
|
check("UI scale survives", config.get("UI_SCALE") == "1.25")
|
|
check("MQTT host survives", config.get("MQTT_HOST") == "broker.example.test")
|
|
check("MQTT password survives", config.get("MQTT_PASSWORD") == "secret")
|
|
check("unknown settings survive", config.get("CUSTOM_SETTING") == "keep-me")
|
|
check("LIVE is appended once", first.count("LIVE_ENABLED=") == 1)
|
|
|
|
ensure_device_config(path)
|
|
second = path.read_text()
|
|
check("reinstall makes no further change", second == first)
|
|
check("LIVE still occurs once", second.count("LIVE_ENABLED=") == 1)
|
|
|
|
print()
|
|
print(f"passed: {passed} failed: {failed}")
|
|
raise SystemExit(1 if failed else 0)
|
|
PY
|