Add two more test scripts.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 5 Sep 2013 12:59:56 +0000 (14:59 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 5 Sep 2013 13:36:37 +0000 (15:36 +0200)
test/Makefile.am
test/commandline.test [new file with mode: 0755]
test/variables.test [new file with mode: 0755]

index 4766004880406b4d5382999d6f27b9e2648ff74f..7a09576ef2312ae71d399ec2c54a1c26c4c986ee 100644 (file)
@@ -1,9 +1,11 @@
 TESTS = \
        basic.test \
+       commandline.test \
        executables.test \
        import-export.test \
        invite-join.test \
-       sptps-basic.test
+       sptps-basic.test \
+       variables.test
 
 EXTRA_DIST = testlib.sh
 
diff --git a/test/commandline.test b/test/commandline.test
new file mode 100755 (executable)
index 0000000..e95c953
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+. ./testlib.sh
+
+# Initialize one node
+
+$tinc $c1 <<EOF
+init foo
+set DeviceType dummy
+set Port 0
+EOF
+
+cat >$d1/tinc-up <<EOF
+#!/bin/sh
+read pid rest <$d1/pid
+(sleep 0.1; kill \$pid) &
+EOF
+
+# Test tincd command line options that should work
+
+$tincd $c1 $r1 -D
+$tincd $c1 $r1 --no-detach
+$tincd $c1 $r1 -D -d
+$tincd $c1 $r1 -D -d2
+$tincd $c1 $r1 -D -d 2
+$tincd $c1 $r1 -D -n foo
+$tincd $c1 $r1 -D -nfoo
+$tincd $c1 $r1 -D --net=foo
+$tincd $c1 $r1 -D --net foo
+
+# Test tincd command line options that should not work
+
+$tincd $c1 $r1 foo && exit 1 || true
+$tincd $c1 $r1 --pidfile && exit 1 || true
+$tincd $c1 $r1 --foo && exit 1 || true
+
+# Test tinc command line options that should work
+
+$tinc $c1 get name
+$tinc $c1 -n foo get name
+$tinc $c1 -nfoo get name
+$tinc $c1 --net=foo get name
+$tinc $c1 --net foo get name
+
+# Test tinc command line options that should not work
+
+$tinc $c1 --net && exit 1 || true
+$tinc $c1 --net get name && exit 1 || true
+$tinc $c1 foo && exit 1 || true
diff --git a/test/variables.test b/test/variables.test
new file mode 100755 (executable)
index 0000000..4cf9d5e
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+. ./testlib.sh
+
+# Initialize one node
+
+$tinc $c1 init foo
+test "`$tinc $c1 get Name`" = "foo"
+
+# Test case sensitivity
+
+$tinc $c1 set Mode switch
+test "`$tinc $c1 get Mode`" = "switch"
+test "`$tinc $c1 get mode`" = "switch"
+$tinc $c1 set mode router
+test "`$tinc $c1 get Mode`" = "router"
+test "`$tinc $c1 get mode`" = "router"
+$tinc $c1 set Mode Switch
+test "`$tinc $c1 get Mode`" = "Switch"
+
+# Test deletion
+
+$tinc $c1 del Mode hub && exit 1 || true
+$tinc $c1 del Mode switch
+test -z "`$tinc $c1 get Mode`"
+
+# There can only be one Mode variable
+
+$tinc $c1 add Mode switch
+$tinc $c1 add Mode hub
+test "`$tinc $c1 get Mode`" = "hub"
+
+# Test addition/deletion of multivalued variables
+
+$tinc $c1 add Subnet 1
+$tinc $c1 add Subnet 2
+$tinc $c1 add Subnet 2
+$tinc $c1 add Subnet 3
+test "`$tinc $c1 get Subnet`" = "1
+2
+2
+3"
+$tinc $c1 del Subnet 2
+test "`$tinc $c1 get Subnet`" = "1
+3"
+$tinc $c1 del Subnet
+test -z "`$tinc $c1 get Subnet`"
+
+# We should not be able to get/set server variables using node.variable syntax
+
+test -z "`$tinc $c1 get foo.Name`"
+$tinc $c1 set foo.Name bar && exit 1 || true
+
+# Test getting/setting host variables for other nodes
+
+touch $d1/hosts/bar
+
+$tinc $c1 add bar.PMTU 1
+$tinc $c1 add bar.PMTU 2
+test "`$tinc $c1 get bar.PMTU`" = "2"
+
+$tinc $c1 add bar.Subnet 1
+$tinc $c1 add bar.Subnet 2
+$tinc $c1 add bar.Subnet 2
+$tinc $c1 add bar.Subnet 3
+test "`$tinc $c1 get bar.Subnet`" = "1
+2
+2
+3"
+$tinc $c1 del bar.Subnet 2
+test "`$tinc $c1 get bar.Subnet`" = "1
+3"
+$tinc $c1 del bar.Subnet
+test -z "`$tinc $c1 get bar.Subnet`"
+
+# We should not be able to get/set for nodes with invalid names
+
+touch $d1/hosts/qu-ux
+
+$tinc $c1 set qu-ux.Subnet 1 && exit 1 || true
+
+# We should not be able to set obsolete variables unless forced
+
+$tinc $c1 set PrivateKey 12345 && exit 1 || true
+$tinc $c1 --force set PrivateKey 12345
+test "`$tinc $c1 get PrivateKey`" = "12345"
+$tinc $c1 del PrivateKey
+test -z "`$tinc $c1 get PrivateKey`"