freedombone-tests 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 change_password )
  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. while [[ $# > 1 ]]
  69. do
  70. key="$1"
  71. case $key in
  72. -h|--help)
  73. show_help
  74. ;;
  75. *)
  76. # unknown option
  77. ;;
  78. esac
  79. shift
  80. done
  81. echo $'Running tests'
  82. test_app_functions
  83. echo $'All tests passed'
  84. exit 0