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.

1098 lines
17 KiB

  1. #!/bin/bash
  2. #!- Library include
  3. . /etc/shlib
  4. #!-
  5. include shunit
  6. depends sed grep git mkdir readlink
  7. export -f matches
  8. export grep
  9. tmp=/tmp
  10. tprog="../bin/compose"
  11. tprog=$(readlink -f $tprog)
  12. export PATH=".:$PATH"
  13. short_tprog=$(basename "$tprog")
  14. ##
  15. ## Convenience function
  16. ##
  17. function init_test() {
  18. test_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  19. cd "$test_tmpdir"
  20. }
  21. function tear_test() {
  22. rm -rf "$test_tmpdir"
  23. }
  24. ##
  25. ## Tests
  26. ##
  27. ##
  28. # Checking arguments
  29. function test_calling_sourcing {
  30. assert_list <<EOF
  31. ### Calling and sourcing
  32. ## -- call of '$short_tprog' with no arg fails (errlvl != 0)
  33. ! "$tprog"
  34. ## -- source '$short_tprog' should not fail
  35. . "$tprog"
  36. EOF
  37. }
  38. function test_mixin_functions {
  39. init_test
  40. assert_list <<EOF
  41. ### Testing get_docker_compose_mixin_from_metadata
  42. ## -- Empty metadata.yml
  43. export CHARM_STORE=$test_tmpdir
  44. mkdir $test_tmpdir/testcharm
  45. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  46. EOF2
  47. . "$tprog"
  48. _setup_state_dir
  49. test -z "\$(get_docker_compose_mixin_from_metadata testcharm)"
  50. ## -- volumes
  51. export CHARM_STORE=$test_tmpdir
  52. export CONFIGSTORE=/tmp/CONFIG
  53. export DATASTORE=/tmp/DATA
  54. mkdir -p $test_tmpdir/testcharm
  55. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  56. data-resources:
  57. - /a
  58. config-resources:
  59. - /b
  60. host-resources:
  61. - /tmp:/tmp
  62. EOF2
  63. . "$tprog"
  64. _setup_state_dir
  65. test "\$(get_docker_compose_mixin_from_metadata testcharm)" == "volumes:
  66. - /tmp/DATA/testcharm/a:/a:rw
  67. - /tmp/CONFIG/testcharm/b:/b:rw
  68. - /tmp:/tmp:rw"
  69. ## -- docker-compose
  70. export CHARM_STORE=$test_tmpdir
  71. mkdir -p $test_tmpdir/testcharm
  72. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  73. docker-compose:
  74. volumes:
  75. - /any:/vol
  76. entrypoint: any
  77. EOF2
  78. . "$tprog"
  79. _setup_state_dir
  80. test "\$(get_docker_compose_mixin_from_metadata testcharm)" == "entrypoint: any
  81. volumes:
  82. - /any:/vol"
  83. ## -- image
  84. export CHARM_STORE=$test_tmpdir
  85. mkdir -p $test_tmpdir/testcharm
  86. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  87. docker-image: toto
  88. EOF2
  89. . "$tprog"
  90. _setup_state_dir
  91. test "\$(get_docker_compose_mixin_from_metadata testcharm)" == "image: toto"
  92. ## -- build
  93. export CHARM_STORE=$test_tmpdir
  94. mkdir -p $test_tmpdir/testcharm/build
  95. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  96. EOF2
  97. . "$tprog"
  98. _setup_state_dir
  99. out="\$(get_docker_compose_mixin_from_metadata testcharm)" || {
  100. echo "Failed"
  101. exit 1
  102. }
  103. echo "\$out"
  104. test "\$out" == "build: testcharm/build"
  105. ## -- subordinate with image
  106. export CHARM_STORE=$test_tmpdir
  107. mkdir -p $test_tmpdir/testcharm
  108. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  109. subordinate: true
  110. docker-image: toto
  111. EOF2
  112. . "$tprog"
  113. _setup_state_dir
  114. ! get_docker_compose_mixin_from_metadata testcharm
  115. ## -- subordinate with build subdir
  116. export CHARM_STORE=$test_tmpdir
  117. mkdir -p $test_tmpdir/testcharm/build
  118. cat <<EOF2 > $test_tmpdir/testcharm/metadata.yml
  119. subordinate: true
  120. EOF2
  121. . "$tprog"
  122. _setup_state_dir
  123. ! get_docker_compose_mixin_from_metadata testcharm
  124. EOF
  125. tear_test
  126. }
  127. function test_merge_yaml {
  128. init_test
  129. assert_list <<EOF
  130. ### Testing merge_yaml
  131. ## -- basic example
  132. . "$tprog"
  133. _setup_state_dir
  134. test "\$(merge_yaml <(echo "
  135. a:
  136. b: 1
  137. c:
  138. - d
  139. - e
  140. ") <(echo "
  141. a:
  142. y: 3
  143. b: 2
  144. c:
  145. - new
  146. x:
  147. 1
  148. "))" == "a:
  149. b: 2
  150. c:
  151. - d
  152. - e
  153. - new
  154. y: 3
  155. x: 1"
  156. ## -- Nothing
  157. . "$tprog"
  158. _setup_state_dir
  159. test -z "\$(merge_yaml <(echo) <(echo))"
  160. ## -- No variable expansions
  161. . "$tprog"
  162. _setup_state_dir
  163. out=\$(merge_yaml <(echo '- \$\$') <(echo "- a"))
  164. test "\$out" == '- \$\$
  165. - a' || {
  166. echo -e "** merge_yaml:\n\$out"; exit 1
  167. }
  168. EOF
  169. }
  170. function test_merge_yaml_str {
  171. init_test
  172. assert_list <<EOF
  173. ### Testing merge_yaml_str
  174. ## -- basic example
  175. . "$tprog"
  176. _setup_state_dir
  177. test "\$(merge_yaml_str "
  178. a:
  179. b: 1
  180. c:
  181. - d
  182. - e
  183. " "
  184. a:
  185. y: 3
  186. b: 2
  187. c:
  188. - new
  189. x:
  190. 1
  191. ")" == "a:
  192. b: 2
  193. c:
  194. - d
  195. - e
  196. - new
  197. y: 3
  198. x: 1"
  199. ## -- Nothing
  200. . "$tprog"
  201. _setup_state_dir
  202. test -z "\$(merge_yaml_str "" "")"
  203. ## -- No variable expansions
  204. . "$tprog"
  205. _setup_state_dir
  206. out=\$(merge_yaml_str '- \$\$' "- a")
  207. test "\$out" == '- \$\$
  208. - a' || {
  209. echo -e "** merge_yaml_str:\n\$out"; exit 1
  210. }
  211. EOF
  212. }
  213. function test_merge_yaml_str {
  214. init_test
  215. assert_list <<EOF
  216. ### Testing merge_yaml_str
  217. ## -- basic example
  218. . "$tprog"
  219. _setup_state_dir
  220. test "\$(merge_yaml_str "
  221. a:
  222. b: 1
  223. c:
  224. - d
  225. - e
  226. " "
  227. a:
  228. y: 3
  229. b: 2
  230. c:
  231. - new
  232. x:
  233. 1
  234. ")" == "a:
  235. b: 2
  236. c:
  237. - d
  238. - e
  239. - new
  240. y: 3
  241. x: 1"
  242. ## -- Nothing
  243. . "$tprog"
  244. _setup_state_dir
  245. test -z "\$(merge_yaml_str "" "")"
  246. ## -- No variable expansions
  247. . "$tprog"
  248. _setup_state_dir
  249. out=\$(merge_yaml_str '- \$\$' "- a")
  250. test "\$out" == '- \$\$
  251. - a' || {
  252. echo -e "** merge_yaml_str:\n\$out"; exit 1
  253. }
  254. EOF
  255. }
  256. function test_get_compose_service_def {
  257. init_test
  258. assert_list <<EOF
  259. ### Testing get_compose_service_def
  260. ## -- Simple (no docker-compose)
  261. export CHARM_STORE=$test_tmpdir
  262. mkdir $test_tmpdir/www
  263. . "$tprog"
  264. _setup_state_dir
  265. test "\$(get_compose_service_def www)" == "charm: www"
  266. ## -- Simple (no docker-compose, no charm dir)
  267. export CHARM_STORE=$test_tmpdir
  268. . "$tprog"
  269. _setup_state_dir
  270. ! get_compose_service_def www_not_existent
  271. ## -- Simple (compose is self sufficient)
  272. export CHARM_STORE=$test_tmpdir
  273. mkdir -p $test_tmpdir/www
  274. cat <<EOF2 > $test_tmpdir/compose.yml
  275. toto:
  276. charm: www
  277. blabla: xxx
  278. EOF2
  279. . "$tprog"
  280. _setup_state_dir
  281. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  282. test "\$(get_compose_service_def toto)" == "blabla: xxx
  283. charm: www"
  284. ## -- Addition of default charm
  285. export CHARM_STORE=$test_tmpdir
  286. mkdir -p $test_tmpdir/www
  287. cat <<EOF2 > $test_tmpdir/compose.yml
  288. www:
  289. blabla: xxx
  290. EOF2
  291. . "$tprog"
  292. _setup_state_dir
  293. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  294. test "\$(get_compose_service_def www)" == "blabla: xxx
  295. charm: www"
  296. EOF
  297. }
  298. ##
  299. ##
  300. ##
  301. function test_get_master_charm_for_service() {
  302. init_test
  303. assert_list <<EOF
  304. ### Testing get_master_charm_for_service
  305. ## -- Simple (no subordinate)
  306. export CHARM_STORE=$test_tmpdir
  307. mkdir $test_tmpdir/www
  308. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  309. EOF2
  310. . "$tprog"
  311. _setup_state_dir
  312. test "\$(_get_master_charm_for_service www)" == "www"
  313. ## -- subordinate
  314. export CHARM_STORE=$test_tmpdir
  315. mkdir -p $test_tmpdir/{www,mysql}
  316. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  317. subordinate: true
  318. requires:
  319. a-label-for-relation:
  320. interface: a-name-relation
  321. scope: container
  322. EOF2
  323. cat <<EOF2 > $test_tmpdir/compose.yml
  324. www:
  325. charm: www
  326. relations:
  327. a-name-relation:
  328. mysql:
  329. label: value
  330. EOF2
  331. . "$tprog"
  332. _setup_state_dir
  333. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  334. test "\$(_get_master_charm_for_service www)" == "mysql"
  335. EOF
  336. }
  337. ##
  338. ##
  339. ##
  340. function test_get_docker_compose_service_mixin() {
  341. init_test
  342. assert_list <<EOF
  343. ### Testing get_docker_compose_service_mixin
  344. ## -- Simple (no compose, no subordinate)
  345. export CHARM_STORE=$test_tmpdir
  346. mkdir $test_tmpdir/{www,mysql}
  347. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  348. data-resources:
  349. - /tmp/a
  350. config-resources:
  351. - /tmp/b
  352. EOF2
  353. . "$tprog"
  354. _setup_state_dir
  355. out=\$(_get_docker_compose_service_mixin www)
  356. test "\$out" == "www:
  357. volumes:
  358. - /www/tmp/a:/tmp/a:rw
  359. - /www/tmp/b:/tmp/b:rw" || {
  360. echo -e "** _get_docker_compose_service_mixin www:\n\$out"; exit 1
  361. }
  362. ## -- Simple (compose, but no subordinate)
  363. export CHARM_STORE=$test_tmpdir
  364. mkdir -p $test_tmpdir/{www,mysql}
  365. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  366. data-resources:
  367. - /tmp/a
  368. config-resources:
  369. - /tmp/b
  370. EOF2
  371. cat <<EOF2 > $test_tmpdir/compose.yml
  372. www:
  373. charm: www
  374. relations:
  375. a-name-relation:
  376. mysql:
  377. label: value
  378. EOF2
  379. . "$tprog"
  380. _setup_state_dir
  381. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  382. test "\$(_get_docker_compose_service_mixin www)" == "www:
  383. links:
  384. - mysql
  385. volumes:
  386. - /www/tmp/a:/tmp/a:rw
  387. - /www/tmp/b:/tmp/b:rw"
  388. ## -- compose, subordinate
  389. export CHARM_STORE=$test_tmpdir
  390. mkdir -p $test_tmpdir/{www,mysql}
  391. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  392. subordinate: true
  393. data-resources:
  394. - /tmp/a
  395. config-resources:
  396. - /tmp/b
  397. requires:
  398. a-name-relation:
  399. interface: a-name-relation
  400. scope: container
  401. EOF2
  402. cat <<EOF2 > $test_tmpdir/compose.yml
  403. www:
  404. charm: www
  405. relations:
  406. a-name-relation:
  407. mysql:
  408. label: value
  409. EOF2
  410. . "$tprog"
  411. _setup_state_dir
  412. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  413. test "\$(_get_docker_compose_service_mixin www)" == "mysql:
  414. volumes:
  415. - /www/tmp/a:/tmp/a:rw
  416. - /www/tmp/b:/tmp/b:rw"
  417. EOF
  418. }
  419. function test_get_docker_compose {
  420. init_test
  421. assert_list <<EOF
  422. ### Testing get_docker_compose
  423. ## -- no docker-compose
  424. export CHARM_STORE=$test_tmpdir
  425. mkdir $test_tmpdir/{www,mysql}
  426. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  427. data-resources:
  428. - /tmp/a
  429. config-resources:
  430. - /tmp/b
  431. EOF2
  432. . "$tprog"
  433. _setup_state_dir
  434. out=\$(get_docker_compose www)
  435. echo "OUT:"
  436. echo "\$out"
  437. test "\$out" == "www:
  438. volumes:
  439. - /www/tmp/a:/tmp/a:rw
  440. - /www/tmp/b:/tmp/b:rw"
  441. ## -- simple with docker-compose
  442. export CHARM_STORE=$test_tmpdir
  443. mkdir -p $test_tmpdir/{www,mysql}
  444. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  445. data-resources:
  446. - /tmp/a
  447. config-resources:
  448. - /tmp/b
  449. EOF2
  450. cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  451. data-resources:
  452. - /tmp/c
  453. config-resources:
  454. - /tmp/d
  455. EOF2
  456. cat <<EOF2 > $test_tmpdir/compose.yml
  457. web_site:
  458. charm: www
  459. relations:
  460. db-connection:
  461. mysql:
  462. user: toto
  463. dbname: tata
  464. EOF2
  465. . "$tprog"
  466. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  467. _setup_state_dir
  468. out=\$(get_docker_compose www)
  469. test "\$out" == "www:
  470. volumes:
  471. - /www/tmp/a:/tmp/a:rw
  472. - /www/tmp/b:/tmp/b:rw" || {
  473. echo -e "** get_docker_compose www:\n\$out"
  474. exit 1
  475. }
  476. out=\$(_get_docker_compose_links web_site)
  477. test "\$out" == "www:
  478. links:
  479. - mysql" || {
  480. echo -e "** _get_docker_compose_links web_site:\n\$out"
  481. exit 1
  482. }
  483. out=\$(get_docker_compose web_site)
  484. test "\$out" == "\
  485. mysql:
  486. volumes:
  487. - /mysql/tmp/c:/tmp/c:rw
  488. - /mysql/tmp/d:/tmp/d:rw
  489. www:
  490. links:
  491. - mysql
  492. volumes:
  493. - /www/tmp/a:/tmp/a:rw
  494. - /www/tmp/b:/tmp/b:rw" || {
  495. echo -e "** get_docker_compose web_site:\n\$out"
  496. exit 1
  497. }
  498. ## -- subordinate
  499. export CHARM_STORE=$test_tmpdir
  500. mkdir -p $test_tmpdir/{www,mysql}
  501. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  502. subordinate: true
  503. data-resources:
  504. - /tmp/a
  505. config-resources:
  506. - /tmp/b
  507. requires:
  508. my-db-connection:
  509. interface: db-connection
  510. scope: container
  511. EOF2
  512. cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  513. data-resources:
  514. - /tmp/c
  515. config-resources:
  516. - /tmp/d
  517. EOF2
  518. cat <<EOF2 > $test_tmpdir/compose.yml
  519. web_site:
  520. charm: www
  521. relations:
  522. db-connection:
  523. mysql:
  524. user: toto
  525. dbname: tata
  526. EOF2
  527. . "$tprog"
  528. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  529. _setup_state_dir
  530. # should fail because of missing relations
  531. ! get_docker_compose www || exit 1
  532. # volumes gets mixed
  533. test "\$(get_docker_compose web_site)" == "mysql:
  534. volumes:
  535. - /www/tmp/a:/tmp/a:rw
  536. - /www/tmp/b:/tmp/b:rw
  537. - /mysql/tmp/c:/tmp/c:rw
  538. - /mysql/tmp/d:/tmp/d:rw"
  539. ## -- subordinate with complex features
  540. export CHARM_STORE=$test_tmpdir
  541. mkdir -p $test_tmpdir/{www,mysql}
  542. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  543. subordinate: true
  544. data-resources:
  545. - /tmp/a
  546. config-resources:
  547. - /tmp/b
  548. requires:
  549. my-db-connection:
  550. interface: db-connection
  551. scope: container
  552. docker-compose:
  553. volumes:
  554. - /special-volume-from-www:/special-volume-from-www
  555. EOF2
  556. cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  557. data-resources:
  558. - /tmp/c
  559. config-resources:
  560. - /tmp/d
  561. docker-compose:
  562. entrypoint: custom-entrypoint
  563. volumes:
  564. - /special-volume-from-mysql:/special-volume-from-mysql
  565. EOF2
  566. cat <<EOF2 > $test_tmpdir/compose.yml
  567. web_site:
  568. charm: www
  569. relations:
  570. db-connection:
  571. mysql:
  572. user: toto
  573. dbname: tata
  574. EOF2
  575. . "$tprog"
  576. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  577. _setup_state_dir
  578. # should fail because of missing relations
  579. #! get_docker_compose www || exit 1
  580. # volumes gets mixed
  581. test "\$(get_docker_compose web_site)" == "mysql:
  582. entrypoint: custom-entrypoint
  583. volumes:
  584. - /www/tmp/a:/tmp/a:rw
  585. - /www/tmp/b:/tmp/b:rw
  586. - /special-volume-from-www:/special-volume-from-www
  587. - /mysql/tmp/c:/tmp/c:rw
  588. - /mysql/tmp/d:/tmp/d:rw
  589. - /special-volume-from-mysql:/special-volume-from-mysql"
  590. EOF
  591. tear_test
  592. }
  593. ## XXXvlab: only broken due to Wrap being used for relations
  594. # function test_run_service_relations {
  595. # init_test
  596. # assert_list <<EOF
  597. # ### Testing run_service_relations
  598. # ## -- no docker-compose
  599. # export CHARM_STORE=$test_tmpdir
  600. # mkdir $test_tmpdir/{www,mysql}
  601. # cat <<EOF2 > $test_tmpdir/www/metadata.yml
  602. # data-resources:
  603. # - /tmp/a
  604. # config-resources:
  605. # - /tmp/b
  606. # EOF2
  607. # . "$tprog"
  608. # _setup_state_dir
  609. # echo "Docker Compose:"
  610. # get_docker_compose www
  611. # echo "Run Service relations:"
  612. # _run_service_relation() {
  613. # echo "\$FUNCNAME: received $*"
  614. # }
  615. # out=\$(run_service_relations www)
  616. # test -z "\$out"
  617. # ## -- simple with docker-compose
  618. # export CHARM_STORE=$test_tmpdir
  619. # mkdir -p $test_tmpdir/{www,mysql}
  620. # cat <<EOF2 > $test_tmpdir/www/metadata.yml
  621. # data-resources:
  622. # - /tmp/a
  623. # config-resources:
  624. # - /tmp/b
  625. # EOF2
  626. # cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  627. # data-resources:
  628. # - /tmp/c
  629. # config-resources:
  630. # - /tmp/d
  631. # EOF2
  632. # cat <<EOF2 > $test_tmpdir/compose.yml
  633. # web_site:
  634. # charm: www
  635. # relations:
  636. # db-connection:
  637. # mysql:
  638. # user: toto
  639. # dbname: tata
  640. # EOF2
  641. # . "$tprog"
  642. # COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  643. # _setup_state_dir
  644. # _setup_state_dir
  645. # echo "Docker Compose:"
  646. # get_docker_compose web_site
  647. # echo "Run Service relations:"
  648. # _run_service_relation() {
  649. # echo "\$FUNCNAME \$2 <-- \$1 --> \$3"
  650. # }
  651. # export -f _run_service_relation
  652. # out=\$(run_service_relations www)
  653. # test -z "\$out" || exit 1
  654. # out=\$(run_service_relations web_site)
  655. # echo "OUT: \$out"
  656. # test "\$out" == "_run_service_relation web_site <-- db-connection --> mysql"
  657. # ## -- subordinate
  658. # export CHARM_STORE=$test_tmpdir
  659. # mkdir -p $test_tmpdir/{www,mysql}
  660. # cat <<EOF2 > $test_tmpdir/www/metadata.yml
  661. # subordinate: true
  662. # data-resources:
  663. # - /tmp/a
  664. # config-resources:
  665. # - /tmp/b
  666. # requires:
  667. # my-db-connection:
  668. # interface: db-connection
  669. # scope: container
  670. # EOF2
  671. # cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  672. # data-resources:
  673. # - /tmp/c
  674. # config-resources:
  675. # - /tmp/d
  676. # EOF2
  677. # cat <<EOF2 > $test_tmpdir/compose.yml
  678. # web_site:
  679. # charm: www
  680. # relations:
  681. # db-connection:
  682. # mysql:
  683. # user: toto
  684. # dbname: tata
  685. # EOF2
  686. # . "$tprog"
  687. # COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  688. # _setup_state_dir
  689. # echo "Docker Compose:"
  690. # get_docker_compose web_site
  691. # echo "Run Service relations:"
  692. # _run_service_relation() {
  693. # echo "\$FUNCNAME \$2 <-- \$1 --> \$3"
  694. # }
  695. # export -f _run_service_relation
  696. # out=\$(run_service_relations www)
  697. # test -z "\$out" || exit 1
  698. # out=\$(run_service_relations web_site)
  699. # echo "\$out"
  700. # test "\$out" == "_run_service_relation web_site <-- db-connection --> mysql"
  701. # EOF
  702. # tear_test
  703. # }
  704. function test_get_docker_compose_2() {
  705. init_test
  706. assert_list <<EOF
  707. ## -- reverse-tech-dep
  708. export CHARM_STORE=$test_tmpdir
  709. mkdir -p $test_tmpdir/{www,mysql}
  710. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  711. provides:
  712. web-proxy:
  713. reverse-tech-dep: true
  714. EOF2
  715. touch $test_tmpdir/mysql/metadata.yml
  716. cat <<EOF2 > $test_tmpdir/compose.yml
  717. web_site:
  718. charm: mysql
  719. relations:
  720. web-proxy:
  721. www:
  722. user: toto
  723. EOF2
  724. . "$tprog"
  725. COMPOSE_YML_FILE=$test_tmpdir/compose.yml
  726. _setup_state_dir
  727. out=\$(get_charm_relation_def "www" "web-proxy") || exit 1
  728. test "\$out" == "reverse-tech-dep: true" || {
  729. echo -e "** get_charm_relation_def:\n\$out"; exit 1
  730. }
  731. out=\$(get_charm_reverse_tech_dep_relation "www" "web-proxy")
  732. test "\$out" == "True" || {
  733. echo -e "** get_charm_reverse_tech_dep_relation:\n\$out"; exit 1
  734. }
  735. out=\$(_get_docker_compose_links "web_site")
  736. test "\$out" == "www:
  737. links:
  738. - mysql" || {
  739. echo -e "** _get_docker_compose_links:\n\$out"; exit 1
  740. }
  741. out=\$(get_docker_compose web_site)
  742. test "\$out" == "www:
  743. links:
  744. - mysql" || {
  745. echo -e "** get_docker_compose:\n\$out"; exit 1
  746. }
  747. EOF
  748. tear_test
  749. }
  750. function test_compose_config {
  751. init_test
  752. export CHARM_STORE=$test_tmpdir
  753. mkdir -p $test_tmpdir/{www,mysql}
  754. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  755. subordinate: true
  756. data-resources:
  757. - /tmp/a
  758. config-resources:
  759. - /tmp/b
  760. requires:
  761. my-db-connection:
  762. interface: db-connection
  763. scope: container
  764. docker-compose:
  765. volumes:
  766. - /special-volume-from-www:/special-volume-from-www
  767. EOF2
  768. cat <<EOF2 > $test_tmpdir/mysql/metadata.yml
  769. docker-image:
  770. docker.0k.io/mysql
  771. data-resources:
  772. - /tmp/c
  773. config-resources:
  774. - /tmp/d
  775. docker-compose:
  776. entrypoint: custom-entrypoint
  777. volumes:
  778. - /special-volume-from-mysql:/special-volume-from-mysql
  779. EOF2
  780. cat <<EOF2 > $test_tmpdir/compose.yml
  781. web_site:
  782. charm: www
  783. relations:
  784. db-connection:
  785. mysql:
  786. user: toto
  787. dbname: tata
  788. EOF2
  789. assert_list <<EOF
  790. ### Testing get_compose_config
  791. ## -- no service provided (syntax validation from docker-compose)
  792. cd "$test_tmpdir"
  793. export DISABLE_SYSTEM_CONFIG_FILE=true
  794. ! "$tprog" config
  795. ## -- simple service provided (syntax validation from docker-compose)
  796. cd "$test_tmpdir"
  797. export DISABLE_SYSTEM_CONFIG_FILE=true
  798. "$tprog" config mysql
  799. ## -- complex service provided (syntax validation from docker-compose)
  800. cd "$test_tmpdir"
  801. export DISABLE_SYSTEM_CONFIG_FILE=true
  802. "$tprog" config web_site
  803. EOF
  804. tear_test
  805. }
  806. continue_on_error="0" testbench $*