Push Tracker
ria-toolkit-oss/tests/agent/test_cli_install_udev.py

37 lines
1.4 KiB
Python
Raw Normal View History

"""Tests for `ria-agent install-udev` and the bundled udev rules."""
from __future__ import annotations
from importlib.resources import files
from unittest.mock import patch
from ria_toolkit_oss.agent import cli as agent_cli
def test_bundled_udev_rules_present_and_cover_usb_sdrs():
text = files("ria_toolkit_oss.agent").joinpath("udev", "90-ria-sdr.rules").read_text()
# ADALM-Pluto, RTL-SDR, HackRF, and USRP B2x0 VIDs must be covered.
for vid in ("0456", "0bda", "1d50", "2500"):
assert vid in text
def test_install_udev_requires_root(capsys):
args = agent_cli.argparse.Namespace(dest="/etc/udev/rules.d", group="plugdev", no_reload=True)
with patch("os.geteuid", return_value=1000):
rc = agent_cli._cmd_install_udev(args)
assert rc == 1
err = capsys.readouterr().err
assert "requires root" in err
assert "install-udev" in err
def test_install_udev_writes_rules_when_root(tmp_path, monkeypatch, capsys):
args = agent_cli.argparse.Namespace(dest=str(tmp_path), group="plugdev", no_reload=True)
# No SUDO_USER and --no-reload → no subprocess calls; just the file write.
monkeypatch.delenv("SUDO_USER", raising=False)
with patch("os.geteuid", return_value=0):
rc = agent_cli._cmd_install_udev(args)
assert rc == 0
written = (tmp_path / "90-ria-sdr.rules").read_text()
assert "SUBSYSTEM" in written