1 |
On 8/27/19 9:24 AM, Alec Warner wrote: |
2 |
> unit tests? |
3 |
> |
4 |
> -A |
5 |
|
6 |
Maybe something like this: |
7 |
|
8 |
diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py |
9 |
new file mode 100644 |
10 |
index 000000000..2d3eebad0 |
11 |
--- /dev/null |
12 |
+++ b/lib/portage/tests/process/test_unshare_net.py |
13 |
@@ -0,0 +1,30 @@ |
14 |
+# Copyright 2019 Gentoo Authors |
15 |
+# Distributed under the terms of the GNU General Public License v2 |
16 |
+ |
17 |
+import os |
18 |
+import platform |
19 |
+ |
20 |
+import portage.process |
21 |
+from portage.const import BASH_BINARY |
22 |
+from portage.tests import TestCase |
23 |
+ |
24 |
+UNSHARE_NET_TEST_SCRIPT = """ |
25 |
+ping -c 1 -W 1 127.0.0.1 || exit 1 |
26 |
+[[ -n ${IPV6} ]] || exit 0 |
27 |
+ping -c 1 -W 1 ::1 || exit 1 |
28 |
+""" |
29 |
+ |
30 |
+class UnshareNetTestCase(TestCase): |
31 |
+ |
32 |
+ def testUnshareNet(self): |
33 |
+ |
34 |
+ if os.geteuid() != 0: |
35 |
+ self.skipTest('not root') |
36 |
+ if platform.system() != 'Linux': |
37 |
+ self.skipTest('not Linux') |
38 |
+ if portage.process.find_binary('ping') is None: |
39 |
+ self.skipTest('ping not found') |
40 |
+ |
41 |
+ env = os.environ.copy() |
42 |
+ env['IPV6'] = '1' if portage.process._has_ipv6() else '' |
43 |
+ self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0) |
44 |
|
45 |
-- |
46 |
Thanks, |
47 |
Zac |