From c3e45b2a4ea63fee98610716c2a30bc70f0bc34b Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 12 Nov 2018 15:09:05 +0100 Subject: [PATCH] chg: test: move argument test in its own file !minor --- test/args | 258 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/base | 212 -------------------------------------------- 2 files changed, 258 insertions(+), 212 deletions(-) create mode 100755 test/args diff --git a/test/args b/test/args new file mode 100755 index 0000000..00dac70 --- /dev/null +++ b/test/args @@ -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 < $test_tmpdir/www/metadata.yml +EOF2 + + cat < $test_tmpdir/mysql/metadata.yml +EOF2 + + cat < $test_tmpdir/compose.yml +web_site: + charm: www +EOF2 + + export DISABLE_SYSTEM_CONFIG_FILE=true + + assert_list <&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 < $test_tmpdir/www/metadata.yml -EOF2 - - cat < $test_tmpdir/mysql/metadata.yml -EOF2 - - cat < $test_tmpdir/compose.yml -web_site: - charm: www -EOF2 - - export DISABLE_SYSTEM_CONFIG_FILE=true - - assert_list <&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 <