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.

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