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.

109 lines
1.6 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. mkdir -p "$CACHEDIR"
  20. }
  21. tear_test() {
  22. rm -rf "$test_tmpdir"
  23. }
  24. ##
  25. ## Tests
  26. ##
  27. function test_wget {
  28. init_test
  29. PORT=45467
  30. assert_list <<EOF
  31. ### cached wget
  32. ## -- should be able to fetch URL
  33. . "$tprog"
  34. echo -e "HTTP/1.1 200 OK\n\ntoto" | nc -l localhost $PORT &
  35. out=\$(cached_wget http://localhost:$PORT) || exit 1
  36. expected="toto"
  37. [ "\$out" == "\$expected" ] || {
  38. echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))"
  39. exit 1
  40. }
  41. ## -- same URL should not try again to join server
  42. . "$tprog"
  43. out=\$(cached_wget http://localhost:$PORT) || exit 1
  44. expected="toto"
  45. [ "\$out" == "\$expected" ] || {
  46. echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))"
  47. exit 1
  48. }
  49. ## -- wrong URL should complain
  50. . "$tprog"
  51. out=\$(cached_wget http://localhost:$PORT/foo) || exit 0
  52. echo "Was expected to fail."
  53. exit 1
  54. ## -- and be retested
  55. . "$tprog"
  56. echo -e "HTTP/1.1 200 OK\n\ntiti" | nc -l localhost $PORT &
  57. out=\$(cached_wget http://localhost:$PORT/foo) || exit 1
  58. expected="titi"
  59. [ "\$out" == "\$expected" ] || {
  60. echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))"
  61. exit 1
  62. }
  63. EOF
  64. tear_test
  65. }
  66. continue_on_error="0" testbench $*