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.
|
|
#!/usr/bin/env bash-shlib # -*- mode: shell-script -*-
include shunit
depends sed grep git mkdir readlink
export -f matches export grep
tmp=/tmp tprog="../bin/compose" tprog=$(readlink -f $tprog)
export PATH=".:$PATH" short_tprog=$(basename "$tprog")
## ## Convenience function ##
init_test() { test_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX) cd "$test_tmpdir" export CACHEDIR="$test_tmpdir/.cache" mkdir -p "$CACHEDIR" }
tear_test() { rm -rf "$test_tmpdir" }
## ## Tests ##
function test_wget {
init_test PORT=45467 assert_list <<EOF
### cached wget
## -- should be able to fetch URL
. "$tprog"
echo -e "HTTP/1.1 200 OK\n\ntoto" | nc -l localhost $PORT &
out=\$(cached_wget http://localhost:$PORT) || exit 1 expected="toto"
[ "\$out" == "\$expected" ] || { echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" exit 1 }
## -- same URL should not try again to join server
. "$tprog"
out=\$(cached_wget http://localhost:$PORT) || exit 1 expected="toto"
[ "\$out" == "\$expected" ] || { echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" exit 1 }
## -- wrong URL should complain
. "$tprog"
out=\$(cached_wget http://localhost:$PORT/foo) || exit 0 echo "Was expected to fail." exit 1
## -- and be retested
. "$tprog"
echo -e "HTTP/1.1 200 OK\n\ntiti" | nc -l localhost $PORT &
out=\$(cached_wget http://localhost:$PORT/foo) || exit 1 expected="titi"
[ "\$out" == "\$expected" ] || { echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" exit 1 }
EOF
tear_test }
continue_on_error="0" testbench $*
|