From 05bf213010f4a09487c1bb67e73e61bd31bb33b7 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Tue, 22 Sep 2026 14:14:52 +0100 Subject: Find bond source profiles through NetworkManager --- tests/test_canonical_bond.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/test_canonical_bond.py') diff --git a/tests/test_canonical_bond.py b/tests/test_canonical_bond.py index d9f097c..d3505cb 100644 --- a/tests/test_canonical_bond.py +++ b/tests/test_canonical_bond.py @@ -1,12 +1,37 @@ import shutil import subprocess +import tempfile import unittest +from pathlib import Path from unittest.mock import patch from scripts import canonical_bond as bond class BondTests(unittest.TestCase): + def test_profile_source_uses_reported_filename_without_embedded_uuid(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "netplan wired:profile.nmconnection" + source = "[connection]\nid=netplan-ethernet\ntype=ethernet\n" + path.write_text(source) + with ( + patch.object( + bond, "nmcli", return_value=f"other:/missing\nidentity:{path}" + ) as command, + patch.object(Path, "glob", return_value=[]), + ): + self.assertEqual(bond.profile_source("identity"), source) + command.assert_called_once_with( + "--escape", "no", "-g", "UUID,FILENAME", "connection", "show" + ) + + def test_profile_source_rejects_missing_filename(self): + with ( + patch.object(bond, "nmcli", return_value="identity:"), + self.assertRaisesRegex(ValueError, "No saved"), + ): + bond.profile_source("identity") + @unittest.skipUnless(shutil.which("nmcli"), "nmcli is in the Nix development shell") def test_networkmanager_accepts_offline_profiles(self): config = bond.keyfile(bond.bond_profile()) -- cgit v1.3.1