freedombone-tests 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Run tests on the system
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-tests
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. function show_help {
  33. echo ''
  34. echo $"${PROJECT_NAME}-tests"
  35. echo ''
  36. echo $'Runs tests on the system'
  37. echo ''
  38. echo $' --help Show help'
  39. echo ''
  40. exit 0
  41. }
  42. function test_app_function_type {
  43. filename=$1
  44. fn_type=$2
  45. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  46. app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
  47. if [ ! ${app_function} ]; then
  48. echo $"Application ${app_name} does not contain a function called '${fn_type}_${app_name}'"
  49. echo ''
  50. echo "See ${filename}"
  51. exit 72852
  52. fi
  53. }
  54. function test_app_functions {
  55. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  56. # check that these functions exist
  57. interface_functions=( install remove backup_local backup_remote restore_local restore_remote upgrade reconfigure )
  58. # for all the app scripts
  59. for filename in $FILES
  60. do
  61. # for each expected interface function
  62. for f in "${interface_functions[@]}"
  63. do
  64. test_app_function_type ${filename} $f
  65. done
  66. done
  67. }
  68. function test_unique_onion_ports {
  69. # test that some services are not assigned the same onion port
  70. FILES=src/${PROJECT_NAME}-app-*
  71. ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}')
  72. unique_ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}' | uniq)
  73. if [[ "$ports" != "$unique_ports" ]]; then
  74. echo $'Some onion ports are clashing'
  75. grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq
  76. exit 637252
  77. fi
  78. }
  79. while [[ $# > 1 ]]
  80. do
  81. key="$1"
  82. case $key in
  83. -h|--help)
  84. show_help
  85. ;;
  86. *)
  87. # unknown option
  88. ;;
  89. esac
  90. shift
  91. done
  92. echo $'Running tests'
  93. test_app_functions
  94. test_unique_onion_ports
  95. echo $'All tests passed'
  96. exit 0