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.

200 lines
3.2 KiB

  1. #!/usr/bin/env bash-shlib
  2. # -*- mode: shell-script -*-
  3. include shunit
  4. depends sed grep git mkdir readlink
  5. export -f matches
  6. export grep
  7. tmp=/tmp
  8. tprog="../bin/compose-core"
  9. tprog=$(readlink -f $tprog)
  10. export PATH=".:$PATH"
  11. short_tprog=$(basename "$tprog")
  12. ##
  13. ## Convenience function
  14. ##
  15. init_test() {
  16. test_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  17. cd "$test_tmpdir"
  18. export CACHEDIR="$test_tmpdir/.cache"
  19. export VARDIR="$test_tmpdir/.var"
  20. mkdir -p "$CACHEDIR"
  21. }
  22. tear_test() {
  23. rm -rf "$test_tmpdir"
  24. }
  25. ##
  26. ## Tests
  27. ##
  28. function test_uses {
  29. init_test
  30. export CHARM_STORE=$test_tmpdir
  31. mkdir -p $test_tmpdir/www/actions
  32. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  33. docker-image: bar ## required as we want relation to know the base image
  34. uses:
  35. myrelation: myrelationdef
  36. EOF2
  37. cat <<EOF2 > $test_tmpdir/compose.yml
  38. web_site:
  39. charm: www
  40. EOF2
  41. export DISABLE_SYSTEM_CONFIG_FILE=true
  42. assert_list <<EOF
  43. ### Testing _get_services_uses
  44. ## -- simple case with only one service with one relation
  45. cd "$test_tmpdir"
  46. . "$tprog" || exit 1
  47. _setup_state_dir
  48. out=\$(_get_services_uses web_site | tr '\0' ':')
  49. expected="web_site:myrelation:myrelationdef:"
  50. [[ "\$out" == "\$expected" ]] || {
  51. echo "doesn't end with: \$expected" >&2
  52. echo "\$out"
  53. exit 1
  54. }
  55. ## -- service not defined in compose, but has charm
  56. cd "$test_tmpdir"
  57. . "$tprog" || exit 1
  58. _setup_state_dir
  59. out=\$(_get_services_uses www | tr '\0' ':') || exit 2
  60. expected="www:myrelation:myrelationdef:"
  61. [[ "\$out" == "\$expected" ]] || {
  62. echo "doesn't end with: \$expected" >&2
  63. echo "\$out"
  64. exit 1
  65. }
  66. ## -- service not defined in compose, nor has charm should fail
  67. cd "$test_tmpdir"
  68. . "$tprog" || exit 1
  69. _setup_state_dir
  70. _get_services_uses xxx || exit 0
  71. echo "Expected it to fail"
  72. exit 1
  73. EOF
  74. tear_test
  75. }
  76. function test_provides {
  77. init_test
  78. export CHARM_STORE=$test_tmpdir
  79. mkdir -p $test_tmpdir/www/actions
  80. cat <<EOF2 > $test_tmpdir/www/metadata.yml
  81. docker-image: bar ## required as we want relation to know the base image
  82. provides:
  83. myrelation: myrelationdef
  84. EOF2
  85. cat <<EOF2 > $test_tmpdir/compose.yml
  86. web_site:
  87. charm: www
  88. EOF2
  89. export DISABLE_SYSTEM_CONFIG_FILE=true
  90. assert_list <<EOF
  91. ### Testing _get_services_provides
  92. ## -- simple case with only one service with one relation
  93. cd "$test_tmpdir"
  94. . "$tprog" || exit 1
  95. _setup_state_dir
  96. out=\$(_get_services_provides web_site | tr '\0' ':')
  97. expected="web_site:myrelation:myrelationdef:"
  98. [[ "\$out" == "\$expected" ]] || {
  99. echo "doesn't end with: \$expected" >&2
  100. echo "\$out"
  101. exit 1
  102. }
  103. ## -- service not defined in compose, but has charm
  104. cd "$test_tmpdir"
  105. . "$tprog" || exit 1
  106. _setup_state_dir
  107. out=\$(_get_services_provides www | tr '\0' ':')
  108. expected="www:myrelation:myrelationdef:"
  109. [[ "\$out" == "\$expected" ]] || {
  110. echo "doesn't end with: \$expected" >&2
  111. echo "\$out"
  112. exit 1
  113. }
  114. ## -- service not defined in compose, nor has charm should fail
  115. cd "$test_tmpdir"
  116. . "$tprog" || exit 1
  117. _setup_state_dir
  118. out=\$(set -o pipefail
  119. _get_provides_uses xxx | tr '\0' :) || exit 0
  120. echo "Expected it to fail"
  121. exit 1
  122. EOF
  123. tear_test
  124. }
  125. continue_on_error="0" testbench $*