tinc/test/variables.test

87 lines
2.1 KiB
Text
Raw Normal View History

2019-08-26 11:44:51 +00:00
#!/bin/sh
2019-08-26 11:44:53 +00:00
. "${0%/*}/testlib.sh"
2019-08-26 11:44:51 +00:00
# Initialize one node
$tinc $c1 init foo
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Name | sed 's/\r//'`" = "foo"
2019-08-26 11:44:51 +00:00
# Test case sensitivity
$tinc $c1 set Mode switch
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Mode | sed 's/\r//'`" = "switch"
test "`$tinc $c1 get mode | sed 's/\r//'`" = "switch"
2019-08-26 11:44:51 +00:00
$tinc $c1 set mode router
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Mode | sed 's/\r//'`" = "router"
test "`$tinc $c1 get mode | sed 's/\r//'`" = "router"
2019-08-26 11:44:51 +00:00
$tinc $c1 set Mode Switch
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Mode | sed 's/\r//'`" = "Switch"
2019-08-26 11:44:51 +00:00
# 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
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Mode | sed 's/\r//'`" = "hub"
2019-08-26 11:44:51 +00:00
# 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
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Subnet | sed 's/\r//'`" = "1
2019-08-26 11:44:51 +00:00
2
3"
$tinc $c1 del Subnet 2
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get Subnet | sed 's/\r//'`" = "1
2019-08-26 11:44:51 +00:00
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
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get bar.PMTU | sed 's/\r//'`" = "2"
2019-08-26 11:44:51 +00:00
$tinc $c1 add bar.Subnet 1
$tinc $c1 add bar.Subnet 2
$tinc $c1 add bar.Subnet 2
$tinc $c1 add bar.Subnet 3
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get bar.Subnet | sed 's/\r//'`" = "1
2019-08-26 11:44:51 +00:00
2
3"
$tinc $c1 del bar.Subnet 2
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get bar.Subnet | sed 's/\r//'`" = "1
2019-08-26 11:44:51 +00:00
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
2022-04-22 18:24:15 +00:00
test "`$tinc $c1 get PrivateKey | sed 's/\r//'`" = "12345"
2019-08-26 11:44:51 +00:00
$tinc $c1 del PrivateKey
test -z "`$tinc $c1 get PrivateKey`"