89 lines
1.0 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. compose_core=$(which compose-core) || {
  4. echo "Requires compose-core executable to be in \$PATH." >&2
  5. exit 1
  6. }
  7. fetch-def() {
  8. local path="$1" fname="$2"
  9. ( . "$path" 1>&2 || {
  10. echo "Failed to load '$path'." >&2
  11. exit 1
  12. }
  13. declare -f "$fname"
  14. )
  15. }
  16. prefix_cmd="
  17. . /etc/shlib
  18. include common
  19. include parse
  20. . ../lib/common
  21. $(fetch-def "$compose_core" yaml_get_values)
  22. $(fetch-def "$compose_core" yaml_get_interpret)
  23. " || {
  24. echo "Couldn't build prefix cmd" >&2
  25. exit 1
  26. }
  27. # mock
  28. cfg-get-value() {
  29. local key="$1"
  30. shyaml get-value "$key" 2>/dev/null
  31. }
  32. export -f cfg-get-value
  33. yaml_get_interpret() {
  34. shyaml get-value
  35. }
  36. export -f yaml_get_interpret
  37. ##
  38. ## Tests
  39. ##
  40. try "
  41. _get_custom_rules '
  42. '"
  43. noerror
  44. is out ''
  45. try "
  46. _get_custom_rules '
  47. apache-custom-rules:
  48. '"
  49. noerror
  50. is out ''
  51. try "
  52. _get_custom_rules '
  53. apache-custom-rules:
  54. - a
  55. - b
  56. '"
  57. noerror
  58. is out 'a
  59. b'
  60. try "
  61. _get_custom_rules '
  62. apache-custom-rules:
  63. a: x
  64. b: y
  65. '"
  66. noerror
  67. is out '
  68. x
  69. y'