Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·59 lines (43 loc) · 1.6 KB
/
Copy pathtest.py
File metadata and controls
executable file
·59 lines (43 loc) · 1.6 KB
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
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
from dev import get_parser, process_args
import unittest
def to_cmd(inp: str) -> str:
parser = get_parser()
args = parser.parse_args(inp.split())
return process_args(args)
class TestCreate(unittest.TestCase):
def test_empty(self):
cmd = to_cmd("create test")
self.assertNotIn("--userns", cmd)
self.assertNotIn("-v", cmd)
self.assertNotIn("-p", cmd)
self.assertNotIn("--device", cmd)
def test_deduped(self):
cmd = to_cmd("create -x -w -g -a test")
count = cmd.count("--security-opt label=type:container_runtime_t")
self.assertEqual(count, 1)
def test_missing_name(self):
with self.assertRaises(SystemExit):
to_cmd("create")
def test_default_volume(self):
cmd = to_cmd("create test -v")
self.assertIn("-v test:/home/user/data", cmd)
def test_specified_volume(self):
cmd = to_cmd("create test -v vol")
self.assertIn("-v vol:/home/user/data", cmd)
def test_missing_ports(self):
with self.assertRaises(SystemExit):
to_cmd("create test -i")
def test_ports(self):
ports = [1, 2, 3, 4]
cmd = to_cmd(f"create test -p {','.join(map(str, ports))}")
for p in ports:
self.assertIn(f"-p 127.0.0.1:{p}:{p}", cmd)
def test_invalid_ports(self):
with self.assertRaises(SystemExit):
to_cmd("create -p not_some_numbers")
def test_missing_image(self):
with self.assertRaises(SystemExit):
to_cmd("create test -i")
if __name__ == "__main__":
unittest.main()