Browse Source
new: added ``cached_wget`` utility function to compose intended for charms to use.
test
new: added ``cached_wget`` utility function to compose intended for charms to use.
test
Valentin Lab
6 years ago
2 changed files with 127 additions and 0 deletions
-
18bin/compose
-
109test/wget
@ -0,0 +1,109 @@ |
|||||
|
#!/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 $* |
Write
Preview
Loading…
Cancel
Save
Reference in new issue