Improve TUN routing readability

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2026-10-09 20:48:16 +08:00
parent 246f4e2ae5
commit ef0b20153b
4 changed files with 20 additions and 0 deletions
+8
View File
@@ -85,6 +85,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
Path(arguments[2]).name.startswith(tempfile.gettempprefix())
)
self.assertEqual(Path(arguments[2]).suffix, '.sh')
scripts.append(Path(arguments[2]).read_text(encoding='utf-8'))
return process
@@ -103,6 +104,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
self.host.applyDNS('1.1.1.1')
self.assertEqual(self.host.index, 77)
self.assertIn('ip tuntap add dev utun101 mode tun user 1000', scripts[0])
self.assertIn('ip link set dev utun101 mtu 1500', scripts[0])
self.assertIn('ip -6 addr add fd00::1/64 dev utun101', scripts[0])
@@ -142,6 +144,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
)
directory = Path(self.host._directory.name)
self.assertIs(self.host._process, process)
self.assertEqual(len(list(directory.glob('*.sh'))), 1)
self.assertTrue((directory / 'cancelled').exists())
@@ -180,8 +183,10 @@ class SingTUNLinuxHostTest(unittest.TestCase):
root = Path(directory).resolve()
net = root / 'net'
binDirectory = root / 'bin'
net.mkdir()
binDirectory.mkdir()
ip = binDirectory / 'ip'
# This fixture only creates/removes files under its temporary
@@ -217,6 +222,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
def launch(arguments, **kwargs):
self.assertEqual(arguments[:2], ['pkexec', 'bash'])
script = Path(arguments[-1])
text = script.read_text(encoding='utf-8')
text = text.replace('/sys/class/net', net.as_posix())
@@ -239,6 +245,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
FAKE_CANCEL=(script.parent / 'cancelled').as_posix(),
FAKE_SCRIPT=script.as_posix(),
)
return realPopen([bash, str(script)], env=environment, **kwargs)
with mock.patch.object(
@@ -254,6 +261,7 @@ class SingTUNLinuxHostTest(unittest.TestCase):
):
if failure == 'none':
self.host.prepare()
self.assertEqual(self.host.index, 77)
else:
with self.assertRaisesRegex(