b936e7256fea94a16ae8e4a3938aaac8a092d87e
[tinc] / test / integration / basic.py
1 #!/usr/bin/env python3
2
3 """Check that basic functionality works (tincd can be started and stopped)."""
4
5 from testlib.test import Test
6 from testlib.proc import Tinc
7 from testlib.feature import SANDBOX_LEVEL
8 from testlib.log import log
9 from testlib.script import Script
10 from testlib import check
11
12
13 def init(ctx: Test) -> Tinc:
14     """Initialize new test nodes."""
15     node = ctx.node(init=f"set Sandbox {SANDBOX_LEVEL}")
16     node.add_script(Script.TINC_UP)
17     return node
18
19
20 def test(ctx: Test, *flags: str) -> None:
21     """Run tests with flags."""
22     log.info("init new node")
23     node = init(ctx)
24
25     log.info('starting tincd with flags "%s"', " ".join(flags))
26     tincd = node.tincd(*flags)
27
28     log.info("waiting for tinc-up script")
29     node[Script.TINC_UP].wait()
30
31     log.info("stopping tincd")
32     node.cmd("stop")
33
34     log.info("checking tincd exit code")
35     check.success(tincd.wait())
36
37
38 with Test("foreground mode") as context:
39     test(context, "-D")
40
41 with Test("background mode") as context:
42     test(context)