diff --git a/bin/compose b/bin/compose index efb1517..4ac1cfc 100755 --- a/bin/compose +++ b/bin/compose @@ -2601,6 +2601,24 @@ EOF echo "}" } +cached_wget() { + local cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ + url="$1" + if [ -e "$cache_file" ]; then + cat "$cache_file" + touch "$cache_file" + return 0 + fi + wget -O- "${url}" | + tee "$cache_file" + + if [ "${PIPESTATUS[0]}" != 0 ]; then + rm "$cache_file" + die "Unable to fetch '$url'." + return 1 + fi +} +export -f cached_wget [ "$SOURCED" ] && return 0 diff --git a/test/wget b/test/wget new file mode 100755 index 0000000..0397509 --- /dev/null +++ b/test/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 <