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.

112 lines
1.8 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_direct_action {
  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. EOF2
  35. cat <<EOF2 > $test_tmpdir/www/actions/foo
  36. #!/bin/bash
  37. echo 'hello from foo:' "\$@"
  38. EOF2
  39. chmod +x $test_tmpdir/www/actions/foo
  40. cat <<EOF2 > $test_tmpdir/compose.yml
  41. web_site:
  42. charm: www
  43. EOF2
  44. export DISABLE_SYSTEM_CONFIG_FILE=true
  45. assert_list <<EOF
  46. ### Testing charm action detection
  47. ## -- direct charm action
  48. cd "$test_tmpdir"
  49. out=\$("$tprog" foo web_site a b c -y -z j --help 2>&1 >/dev/null ) || exit 1
  50. expected="hello from foo: a b c -y -z j --help"
  51. [[ "\$out" == *"\$expected" ]] || {
  52. echo "doesn't end with: \$expected" >&2
  53. echo "\$out"
  54. exit 1
  55. }
  56. ## -- direct charm access to \$COMPOSE_YML_FILE
  57. cat <<'EOF2' > $test_tmpdir/www/actions/foo
  58. #!/bin/bash
  59. printf "COMPOSE_YML_FILE: '%s'" "\$COMPOSE_YML_FILE"
  60. EOF2
  61. cd "$test_tmpdir"
  62. out=\$("$tprog" foo web_site a b c -y -z j --help 2>&1 >/dev/null ) || exit 1
  63. expected="COMPOSE_YML_FILE: '$test_tmpdir/compose.yml'"
  64. [[ "\$out" == *"\$expected" ]] || {
  65. echo "doesn't end with: \$expected" >&2
  66. echo "\$out"
  67. exit 1
  68. }
  69. EOF
  70. tear_test
  71. }
  72. continue_on_error="0" testbench $*