fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

316 lines
4.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. export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  38. trap "rm -rf \"$state_tmpdir\"" EXIT
  39. ##
  40. ## Tests
  41. ##
  42. try "
  43. get_domains '
  44. '"
  45. is errlvl 1
  46. is err reg 'Error: .*domain option.*'
  47. is out ''
  48. try "
  49. get_domains '
  50. domain: toto
  51. '"
  52. noerror
  53. is out 'toto
  54. '
  55. try "
  56. get_domains '
  57. domain: toto titi
  58. '"
  59. noerror
  60. is out 'toto titi
  61. '
  62. try "
  63. get_domains '
  64. domain:
  65. - toto
  66. '"
  67. noerror
  68. is out 'toto
  69. '
  70. try "
  71. get_domains '
  72. server-aliases:
  73. '"
  74. is errlvl 1
  75. is err part 'Error: '
  76. is err part 'No domain name set'
  77. try "
  78. get_domains '
  79. domain:
  80. server-aliases:
  81. '"
  82. is errlvl 1
  83. is err part 'Error: '
  84. is err part 'No domain name set'
  85. try "
  86. get_domains '
  87. domain:
  88. server-aliases:
  89. - toto
  90. '"
  91. is errlvl 1
  92. is err part 'Error: '
  93. is err part "You can't specify server aliases if you don't have a domain"
  94. try "
  95. get_domains '
  96. domain: foo
  97. server-aliases:
  98. - bar
  99. '"
  100. noerror
  101. is out 'foo bar
  102. '
  103. try "
  104. get_domains '
  105. domain: foo
  106. server-aliases: bar
  107. '"
  108. noerror
  109. is out 'foo bar
  110. '
  111. try "
  112. get_domains '
  113. domain:
  114. - foo
  115. server-aliases: bar
  116. '"
  117. noerror
  118. is out 'foo bar
  119. '
  120. try "
  121. get_domains '
  122. domain:
  123. - foo{1,2} bar
  124. server-aliases: wiz
  125. '"
  126. noerror
  127. is out 'foo1 foo2 bar wiz
  128. '
  129. try "
  130. get_domains '
  131. domain:
  132. - foo{1,2} bar
  133. server-aliases: foo1
  134. '"
  135. noerror
  136. is out 'foo1 foo2 bar
  137. '
  138. try "
  139. get_domains '
  140. domain:
  141. - foo{1,2} bar
  142. - \"*.zoo\"
  143. server-aliases: foo1
  144. '"
  145. noerror
  146. is out 'foo1 foo2 bar *.zoo
  147. '
  148. try "
  149. get_domains '
  150. domain: foo+ bar
  151. '"
  152. is errlvl 1
  153. is err part 'Error: '
  154. is err part 'Invalid domain value'
  155. try "
  156. get_domains '
  157. domain:
  158. ' '
  159. options.service-domain-map:
  160. '" "empty service-domain-map"
  161. is errlvl 1
  162. is err part 'Error: '
  163. is err part 'No domain name set'
  164. is err part 'service-domain-map'
  165. try "
  166. BASE_SERVICE_NAME=foo
  167. get_domains '
  168. domain:
  169. ' '
  170. options:
  171. service-domain-map:
  172. wiz: bar
  173. '" "no map matching in service-domain-map"
  174. is errlvl 1
  175. is err part 'Error: '
  176. is err part 'No domain name set'
  177. is err part 'service-domain-map'
  178. try "
  179. export BASE_SERVICE_NAME=wiz
  180. get_domains '
  181. domain:
  182. ' '
  183. options:
  184. service-domain-map:
  185. wiz: bar
  186. '" "matching map in service-domain-map"
  187. noerror
  188. is out 'bar
  189. '
  190. try "
  191. export BASE_SERVICE_NAME=wiz
  192. get_domains '
  193. domain:
  194. ' '
  195. options:
  196. service-domain-map:
  197. wiz?: bar
  198. wiz: bar2
  199. '" "only first matching map in service-domain-map"
  200. noerror
  201. is out 'bar
  202. '
  203. try "
  204. export BASE_SERVICE_NAME=wiz
  205. get_domains '
  206. domain:
  207. ' '
  208. options:
  209. service-domain-map:
  210. \"[w]i?zz?\": bar
  211. '" "map are regex in service-domain-map"
  212. noerror
  213. is out 'bar
  214. '
  215. try "
  216. export BASE_SERVICE_NAME=wiz
  217. get_domains '
  218. domain:
  219. ' '
  220. options:
  221. service-domain-map:
  222. (w)i(z): bar\$1\$2
  223. '" "regex capture in service-domain-map"
  224. noerror
  225. is out 'barwz
  226. '
  227. try "
  228. export BASE_SERVICE_NAME=wiz
  229. get_domains '
  230. domain:
  231. ' '
  232. options:
  233. service-domain-map:
  234. .*: \$0.shrubbery
  235. '" "regex capture 2 in service-domain-map"
  236. noerror
  237. is out 'wiz.shrubbery
  238. '
  239. try "
  240. export BASE_SERVICE_NAME=wiz
  241. get_domains '
  242. domain:
  243. ' '
  244. options:
  245. service-domain-map:
  246. .*: \$x
  247. '" "refuse other variables in service-domain-map"
  248. is errlvl 1
  249. is err part 'Error: '
  250. is err part 'Invalid mapping value'
  251. try "
  252. export BASE_SERVICE_NAME=wiz
  253. get_domains '
  254. domain:
  255. ' '
  256. options:
  257. service-domain-map:
  258. .*:
  259. - \$0.example.com
  260. - my-\$0.domain.org
  261. '" "list is possible as value of service-domain-map"
  262. noerror
  263. is out 'wiz.example.com my-wiz.domain.org
  264. '