Compare commits
merge into: 0k:master
0k:cache-relation
0k:checking
0k:fix-host-charm-resources
0k:hostresources
0k:lokavaluto/dev/master
0k:master
0k:myceliandre/dev/mac-compat
0k:raw-remaining-args
0k:test
0k:test1
pull from: 0k:raw-remaining-args
0k:cache-relation
0k:checking
0k:fix-host-charm-resources
0k:hostresources
0k:lokavaluto/dev/master
0k:master
0k:myceliandre/dev/mac-compat
0k:raw-remaining-args
0k:test
0k:test1
14 Commits
master
...
raw-remain
5 changed files with 1056 additions and 338 deletions
-
0.package
-
821bin/compose
-
29bin/test
-
258test/args
-
286test/base
821
bin/compose
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,29 @@ |
|||
#!/usr/bin/env bash-shlib |
|||
# -*- mode: shell-script -*- |
|||
|
|||
|
|||
include common |
|||
|
|||
exname="$(basename $0)" |
|||
|
|||
if ! [ -e "../.package" ]; then |
|||
echo "Please execute this in test directory, with '../bin/$exname'." >&2 |
|||
echo "Or, if pkgcmd is installed, use 't'..." |
|||
exit 1 |
|||
fi |
|||
|
|||
base=$(realpath "$PWD/..") |
|||
export base |
|||
|
|||
cd "$base/test" |
|||
|
|||
for tfile in *; do |
|||
[ -e "$tfile" ] || continue |
|||
[ -d "$tfile" ] && continue |
|||
( |
|||
/usr/bin/env bash-shlib "$tfile" "$@" |
|||
) && continue |
|||
exit "$?" |
|||
done |
|||
|
|||
|
@ -0,0 +1,258 @@ |
|||
#!/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" |
|||
export VARDIR="$test_tmpdir/.var" |
|||
mkdir -p "$CACHEDIR" |
|||
} |
|||
|
|||
|
|||
|
|||
tear_test() { |
|||
rm -rf "$test_tmpdir" |
|||
} |
|||
|
|||
|
|||
## |
|||
## Tests |
|||
## |
|||
|
|||
|
|||
function test_compose_run_args { |
|||
|
|||
init_test |
|||
|
|||
export CHARM_STORE=$test_tmpdir |
|||
mkdir -p $test_tmpdir/{www,mysql} |
|||
cat <<EOF2 > $test_tmpdir/www/metadata.yml |
|||
EOF2 |
|||
|
|||
cat <<EOF2 > $test_tmpdir/mysql/metadata.yml |
|||
EOF2 |
|||
|
|||
cat <<EOF2 > $test_tmpdir/compose.yml |
|||
web_site: |
|||
charm: www |
|||
EOF2 |
|||
|
|||
export DISABLE_SYSTEM_CONFIG_FILE=true |
|||
|
|||
assert_list <<EOF |
|||
|
|||
### Testing args passing to docker-compose |
|||
|
|||
## -- simple action |
|||
|
|||
cd "$test_tmpdir" |
|||
out=\$("$tprog" --dry-compose-run run web_site 2>&1 >/dev/null ) |
|||
expected="docker-compose run web_site" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- simple single dash arg |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run -T web_site 2>&1 >/dev/null ) |
|||
expected="docker-compose run -T web_site" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- desaggregation of combined single char args |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run logs -ft --tail 20 web_site 2>&1 >/dev/null) |
|||
expected="docker-compose logs -f -t --tail 20 web_site" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- desaggregation of combined single char option and valued option char |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run -Tv x:y web_site 2>&1 >/dev/null) |
|||
expected="docker-compose run -T -v x:y web_site" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- simple unexpected single dash arg |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run -Z web_site 2>&1) |
|||
expected_reg="Unknown option '-Z'" |
|||
|
|||
[[ "\$out" =~ \$expected_reg ]] || { |
|||
echo -e "Can't find '\$expected_reg' in out:\n\$out" |
|||
exit 1 |
|||
} |
|||
|
|||
## -- simple unexpected single dash arg after expected one |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run -T -Z web_site 2>&1) |
|||
expected_reg="Unknown option '-Z'" |
|||
|
|||
[[ "\$out" =~ \$expected_reg ]] || { |
|||
echo -e "Can't find '\$expected_reg' in out:\n\$out" |
|||
exit 1 |
|||
} |
|||
|
|||
## -- simple unexpected single dash arg after expected aggregated one |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run -TZ web_site 2>&1) |
|||
expected_reg="Unknown option '-Z'" |
|||
|
|||
[[ "\$out" =~ \$expected_reg ]] || { |
|||
echo -e "Can't find '\$expected_reg' in out:\n\$out" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- multiple services |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run logs --tail 15 web_site mysql 2>&1 >/dev/null) |
|||
expected="docker-compose logs --tail 15 web_site mysql" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
## -- single services |
|||
|
|||
cd "$test_tmpdir" |
|||
|
|||
out=\$("$tprog" --dry-compose-run run web_site mysql 2>&1 >/dev/null) |
|||
expected="docker-compose run web_site mysql" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
EOF |
|||
|
|||
tear_test |
|||
} |
|||
|
|||
|
|||
function test_filter_opts { |
|||
|
|||
src=$(cat <<'EOF' |
|||
-d, --detach |
|||
--name NAME |
|||
--entrypoint CMD |
|||
-e KEY=VAL |
|||
-l, --label KEY=VAL |
|||
-u, --user="" |
|||
--no-deps |
|||
--rm |
|||
-p, --publish=[] |
|||
--service-ports |
|||
--use-aliases |
|||
-v, --volume=[] |
|||
-T |
|||
-w, --workdir="" |
|||
EOF |
|||
) |
|||
|
|||
export src |
|||
|
|||
assert_list <<EOF |
|||
|
|||
### Testing filtering opts |
|||
|
|||
## -- multi_opts_filter should find opts with args |
|||
|
|||
. "$tprog" |
|||
out=\$(echo "\$src" | multi_opts_filter | tr " " "\n") || exit 12 |
|||
expected="--name |
|||
--entrypoint |
|||
-e |
|||
-l |
|||
--label |
|||
-u |
|||
--user |
|||
-p |
|||
--publish |
|||
-v |
|||
--volume |
|||
-w |
|||
--workdir" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
## -- single_opts_filter should find opts with args |
|||
|
|||
. "$tprog" |
|||
out=\$(echo "\$src" | single_opts_filter | tr " " "\n") || exit 12 |
|||
expected="-d |
|||
--detach |
|||
--no-deps |
|||
--rm |
|||
--service-ports |
|||
--use-aliases |
|||
-T" |
|||
|
|||
[ "\$out" == "\$expected" ] || { |
|||
echo -e "DIFF:\n\$(diff <(echo "\$out") <(echo "\$expected"))" |
|||
exit 1 |
|||
} |
|||
|
|||
|
|||
EOF |
|||
|
|||
} |
|||
|
|||
continue_on_error="0" testbench $* |
Write
Preview
Loading…
Cancel
Save
Reference in new issue