This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_example.py
49 lines (41 loc) · 1.5 KB
/
test_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import subprocess
import time
import example
from cli import key_dir
from mesh import NS
def test_gen_net_smoke():
net = example.gen_net(True, mock_net = False)
def test_gen_net_mock():
net = example.gen_net(True, mock_net = True)
net.up_mock_net()
for h in net.hosts:
print(f"Starting {h}")
net.up(h)
assert(os.system(NS("iPhone").gen_cmd("ping 10.56.1.1 -c 1")) == 0)
assert(os.system(NS("iPhone").gen_cmd("ping 10.56.1.2 -c 1")) == 0)
assert(os.system(NS("iPhone").gen_cmd("ping 10.56.200.21 -c 1")) == 0)
if os.environ.get("CI") == None:
assert(os.system(NS("iPhone").gen_cmd("host google.com 10.56.1.1")) == 0)
# todo: test traceroute
for h in net.hosts:
net.down(h)
net.down_mock_net()
def test_cli():
assert(os.system(f"mv {key_dir} bak") == 0)
assert(os.system(f"mkdir {key_dir}") == 0)
assert(os.system(f"./example.py genkey all") == 0)
assert(os.path.exists(os.path.join(key_dir, "iPhone.key")))
assert(os.system(f"./example.py gen-client-conf iPhone") == 0)
# TODO: get this test works
# p = subprocess.Popen(["./example.py", "mock"], stdout=subprocess.PIPE)
# while p.poll() == None:
# out = p.stdout.read().decode()
# print(out, end="", flush=True)
# if "is up" in out:
# p.terminate()
# p.wait()
# break
# assert(p.returncode == 0)
assert(os.system(f"rm -r {key_dir}") == 0)
assert(os.system(f"mv bak {key_dir}") == 0)