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.

92 lines
1.4 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"
  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_injection {
  29. init_test
  30. export CHARM_STORE=$test_tmpdir
  31. mkdir -p $test_tmpdir/{toto,titi}
  32. cat <<EOF2 > $test_tmpdir/toto/metadata.yml
  33. docker-image: toto
  34. EOF2
  35. cat <<EOF2 > $test_tmpdir/titi/metadata.yml
  36. docker-image: titi
  37. EOF2
  38. cat <<EOF2 > $test_tmpdir/compose.yml
  39. web_site:
  40. charm: toto
  41. EOF2
  42. export DISABLE_SYSTEM_CONFIG_FILE=true
  43. assert_list <<EOF
  44. ### Testing injection of run-time compose code
  45. ## -- simple injection, replacing charm
  46. cd "$test_tmpdir"
  47. injection='
  48. web_site:
  49. charm: titi
  50. '
  51. out=\$("$tprog" -Y "\$injection" config web_site 2>/dev/null) || exit 1
  52. out=\$(echo "\$out" | shyaml get-value services.web_site.image) || exit 1
  53. expected="titi"
  54. [ "\$out" == "\$expected" ] || {
  55. echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))"
  56. exit 1
  57. }
  58. EOF
  59. tear_test
  60. }
  61. continue_on_error="0" testbench $*