aae3ff27d11d4d2a0aa4f6e98c39284aebb446e2
[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.log import log
8 from testlib.script import Script
9 from testlib import check
10
11
12 def init(ctx: Test) -> Tinc:
13     """Initialize new test nodes."""
14     node = ctx.node()
15     node.add_script(Script.TINC_UP)
16     stdin = f"""
17         init {node}
18         set Address localhost
19         set Port 0
20         set DeviceType dummy
21     """
22     node.cmd(stdin=stdin)
23     return node
24
25
26 def test(ctx: Test, *flags: str) -> None:
27     """Run tests with flags."""
28     log.info("init new node")
29     node = init(ctx)
30
31     log.info('starting tincd with flags "%s"', " ".join(flags))
32     tincd = node.tincd(*flags)
33
34     log.info("waiting for tinc-up script")
35     node[Script.TINC_UP].wait()
36
37     log.info("stopping tincd")
38     node.cmd("stop")
39
40     log.info("checking tincd exit code")
41     check.equals(0, tincd.wait())
42
43
44 with Test("foreground mode") as context:
45     test(context, "-D")
46
47 with Test("background mode") as context:
48     test(context)