variables.test 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. . ./testlib.sh
  3. # Initialize one node
  4. $tinc $c1 init foo
  5. test "`$tinc $c1 get Name`" = "foo"
  6. # Test case sensitivity
  7. $tinc $c1 set Mode switch
  8. test "`$tinc $c1 get Mode`" = "switch"
  9. test "`$tinc $c1 get mode`" = "switch"
  10. $tinc $c1 set mode router
  11. test "`$tinc $c1 get Mode`" = "router"
  12. test "`$tinc $c1 get mode`" = "router"
  13. $tinc $c1 set Mode Switch
  14. test "`$tinc $c1 get Mode`" = "Switch"
  15. # Test deletion
  16. $tinc $c1 del Mode hub && exit 1 || true
  17. $tinc $c1 del Mode switch
  18. test -z "`$tinc $c1 get Mode`"
  19. # There can only be one Mode variable
  20. $tinc $c1 add Mode switch
  21. $tinc $c1 add Mode hub
  22. test "`$tinc $c1 get Mode`" = "hub"
  23. # Test addition/deletion of multivalued variables
  24. $tinc $c1 add Subnet 1
  25. $tinc $c1 add Subnet 2
  26. $tinc $c1 add Subnet 2
  27. $tinc $c1 add Subnet 3
  28. test "`$tinc $c1 get Subnet`" = "1
  29. 2
  30. 2
  31. 3"
  32. $tinc $c1 del Subnet 2
  33. test "`$tinc $c1 get Subnet`" = "1
  34. 3"
  35. $tinc $c1 del Subnet
  36. test -z "`$tinc $c1 get Subnet`"
  37. # We should not be able to get/set server variables using node.variable syntax
  38. test -z "`$tinc $c1 get foo.Name`"
  39. $tinc $c1 set foo.Name bar && exit 1 || true
  40. # Test getting/setting host variables for other nodes
  41. touch $d1/hosts/bar
  42. $tinc $c1 add bar.PMTU 1
  43. $tinc $c1 add bar.PMTU 2
  44. test "`$tinc $c1 get bar.PMTU`" = "2"
  45. $tinc $c1 add bar.Subnet 1
  46. $tinc $c1 add bar.Subnet 2
  47. $tinc $c1 add bar.Subnet 2
  48. $tinc $c1 add bar.Subnet 3
  49. test "`$tinc $c1 get bar.Subnet`" = "1
  50. 2
  51. 2
  52. 3"
  53. $tinc $c1 del bar.Subnet 2
  54. test "`$tinc $c1 get bar.Subnet`" = "1
  55. 3"
  56. $tinc $c1 del bar.Subnet
  57. test -z "`$tinc $c1 get bar.Subnet`"
  58. # We should not be able to get/set for nodes with invalid names
  59. touch $d1/hosts/qu-ux
  60. $tinc $c1 set qu-ux.Subnet 1 && exit 1 || true
  61. # We should not be able to set obsolete variables unless forced
  62. $tinc $c1 set PrivateKey 12345 && exit 1 || true
  63. $tinc $c1 --force set PrivateKey 12345
  64. test "`$tinc $c1 get PrivateKey`" = "12345"
  65. $tinc $c1 del PrivateKey
  66. test -z "`$tinc $c1 get PrivateKey`"