3 """Test supported and unsupported commandline flags."""
5 from testlib import check, util
6 from testlib.log import log
7 from testlib.proc import Tinc, Script
8 from testlib.test import Test
12 (0, ("-n", "foo", "get", "name")),
13 (0, ("-nfoo", "get", "name")),
14 (0, ("--net=foo", "get", "name")),
15 (0, ("--net", "foo", "get", "name")),
16 (0, ("-c", "conf", "-c", "conf")),
17 (0, ("-n", "net", "-n", "net")),
18 (0, ("--pidfile=pid", "--pidfile=pid")),
19 (1, ("-n", "foo", "get", "somethingreallyunknown")),
21 (1, ("--net", "get", "name")),
23 (1, ("-c", "conf", "-n", "n/e\\t")),
28 (0, ("--no-detach",)),
31 (0, ("-D", "-d", "2")),
32 (0, ("-D", "-n", "foo")),
34 (0, ("-D", "--net=foo")),
35 (0, ("-D", "--net", "foo")),
36 (0, ("-D", "-c", ".", "-c", ".")),
37 (0, ("-D", "-n", "net", "-n", "net")),
38 (0, ("-D", "-n", "net", "-o", "FakeOpt=42")),
39 (0, ("-D", "--logfile=log", "--logfile=log")),
40 (0, ("-D", "--pidfile=pid", "--pidfile=pid")),
44 (1, ("-n", "net", "-o", "Compression=")),
45 (1, ("-c", "fakedir", "-n", "n/e\\t")),
49 def init(ctx: Test) -> Tinc:
50 """Initialize new test nodes."""
59 tinc.add_script(Script.TINC_UP)
63 with Test("commandline flags") as context:
66 for code, flags in tincd_flags:
67 COOKIE = util.random_string(10)
68 server = node.tincd(*flags, env={"COOKIE": COOKIE})
71 log.info("waiting for tincd to come up")
72 env = node[Script.TINC_UP].wait().env
73 check.equals(COOKIE, env["COOKIE"])
75 log.info("stopping tinc")
76 node.cmd("stop", code=code)
78 log.info("reading tincd output")
79 stdout, stderr = server.communicate()
81 log.debug('got code %d, ("%s", "%s")', server.returncode, stdout, stderr)
82 check.equals(code, server.returncode)
84 for code, flags in tinc_flags:
85 node.cmd(*flags, code=code)