A simple DNS hook that lets Dehydrated talk to the PowerDNS API.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123 Zeilen
2.3KB

  1. #!/usr/bin/env bash
  2. # Copyright 2016-2018 - Silke Hofstra and contributors
  3. #
  4. # Licensed under the EUPL
  5. #
  6. # You may not use this work except in compliance with the Licence.
  7. # You may obtain a copy of the Licence at:
  8. #
  9. # https://joinup.ec.europa.eu/collection/eupl
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the Licence is distributed on an "AS IS" basis,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  14. # express or implied.
  15. # See the Licence for the specific language governing
  16. # permissions and limitations under the Licence.
  17. #
  18. set -euo pipefail
  19. # Settings for the test
  20. export DEBUG=
  21. export CONFIG=./test.config
  22. # Override commands
  23. export PATH="tests:$PATH"
  24. # Go to correct directory
  25. cd $(dirname "$0")
  26. # Show bash version
  27. echo "Testing using Bash ${BASH_VERSION}"
  28. # Failure count
  29. FAILURES=0
  30. # Test utilities
  31. _TEST() {
  32. echo -e "${1}"
  33. }
  34. _SUBTEST() {
  35. echo -n " + ${1} "
  36. }
  37. _COLOR() {
  38. c="$1"
  39. shift
  40. echo -e "\\u001B[${c}m$*\\u001B[0m"
  41. }
  42. _PASS() {
  43. echo -e "\\t[$(_COLOR 32 PASS)]"
  44. }
  45. _FAIL() {
  46. echo -e "\\t[$(_COLOR 31 FAIL)]"
  47. FAILURES=$((FAILURES+1))
  48. }
  49. _EXP() {
  50. echo -e "$(_COLOR 33 EXPECTED)\\n"\
  51. "$1\\n" \
  52. "$(_COLOR 33 GOT)\\n" \
  53. "$2\\n" \
  54. "---"
  55. }
  56. _MATCH() {
  57. out="$1"
  58. shift
  59. mat="$*"
  60. _out="${out//[[:space:]]/}"
  61. _mat="${mat//[[:space:]]/}"
  62. if [ "$_out" = "$_mat" ]; then
  63. _PASS
  64. else
  65. _FAIL
  66. if [[ -n "${VERBOSE:-}" ]]; then
  67. _EXP "$mat" "$out"
  68. fi
  69. fi
  70. }
  71. _RUN() {
  72. IFS=" " read -ra args <<< "$1"
  73. out=$(./pdns_api.sh "${args[@]}" 2>&1)
  74. shift
  75. _MATCH "$out" "$@"
  76. }
  77. _RELOAD_CONFIG() {
  78. source tests/config
  79. if [[ $# -gt 0 ]]; then
  80. export PDNS_VERSION="$1"
  81. fi
  82. }
  83. # Run all tests
  84. if [ $# -eq 0 ]; then
  85. # Run the tests in the tests folder
  86. for test in tests/*.sh; do
  87. _RELOAD_CONFIG
  88. # shellcheck source=/dev/null
  89. source "${test}"
  90. done
  91. # Run the tests for API versions
  92. for version in {1..1}; do
  93. echo "=> API version ${version}"
  94. for test in tests/v${version}/*.sh; do
  95. _RELOAD_CONFIG "${version}"
  96. # shellcheck source=/dev/null
  97. source "${test}"
  98. done
  99. done
  100. else
  101. # Run the given tests
  102. for test in "$@"; do
  103. _RELOAD_CONFIG
  104. # shellcheck source=/dev/null
  105. source "${test}"
  106. done
  107. fi
  108. echo "Tests complete: ${FAILURES} failures."
  109. exit ${FAILURES}