Add cleanup hook for integration tests
[tinc] / test / variables.test
1 #!/bin/sh
2
3 # shellcheck source=testlib.sh
4 . ./testlib.sh
5
6 echo [STEP] Initialize one node
7
8 tinc foo init foo
9 test "$(tinc foo get Name)" = "foo"
10
11 echo [STEP] Test case sensitivity
12
13 tinc foo set Mode switch
14 test "$(tinc foo get Mode)" = "switch"
15 test "$(tinc foo get mode)" = "switch"
16
17 tinc foo set mode router
18 test "$(tinc foo get Mode)" = "router"
19 test "$(tinc foo get mode)" = "router"
20
21 tinc foo set Mode Switch
22 test "$(tinc foo get Mode)" = "Switch"
23
24 echo [STEP] Test deletion
25
26 must_fail tinc foo del Mode hub
27 tinc foo del Mode switch
28 test -z "$(tinc foo get Mode)"
29
30 echo [STEP] There can only be one Mode variable
31
32 tinc foo add Mode switch
33 tinc foo add Mode hub
34 test "$(tinc foo get Mode)" = "hub"
35
36 echo [STEP] Test addition/deletion of multivalued variables
37
38 tinc foo add Subnet 1
39 tinc foo add Subnet 2
40 tinc foo add Subnet 2
41 tinc foo add Subnet 3
42 test "$(tinc foo get Subnet | rm_cr)" = "1
43 2
44 3"
45
46 tinc foo del Subnet 2
47 test "$(tinc foo get Subnet | rm_cr)" = "1
48 3"
49
50 tinc foo del Subnet
51 test -z "$(tinc foo get Subnet)"
52
53 echo [STEP] We should not be able to get/set server variables using node.variable syntax
54
55 test -z "$(tinc foo get foo.Name)"
56 must_fail tinc foo set foo.Name bar
57
58 echo [STEP] Test getting/setting host variables for other nodes
59
60 touch "$DIR_FOO/hosts/bar"
61
62 tinc foo add bar.PMTU 1
63 tinc foo add bar.PMTU 2
64 test "$(tinc foo get bar.PMTU)" = "2"
65
66 tinc foo add bar.Subnet 1
67 tinc foo add bar.Subnet 2
68 tinc foo add bar.Subnet 2
69 tinc foo add bar.Subnet 3
70 test "$(tinc foo get bar.Subnet | rm_cr)" = "1
71 2
72 3"
73
74 tinc foo del bar.Subnet 2
75 test "$(tinc foo get bar.Subnet | rm_cr)" = "1
76 3"
77
78 tinc foo del bar.Subnet
79 test -z "$(tinc foo get bar.Subnet)"
80
81 echo [STEP] We should not be able to get/set for nodes with invalid names
82
83 touch "$DIR_FOO/hosts/qu-ux"
84 must_fail tinc foo set qu-ux.Subnet 1
85
86 echo [STEP] We should not be able to set obsolete variables unless forced
87
88 must_fail tinc foo set PrivateKey 12345
89 tinc foo --force set PrivateKey 12345
90 test "$(tinc foo get PrivateKey)" = "12345"
91
92 tinc foo del PrivateKey
93 test -z "$(tinc foo get PrivateKey)"