Clean up shellcheck issues in tests

pull/82477/head
Matt Clay 5 months ago
parent e1bcb8a534
commit 630e5dda25

@ -6,7 +6,7 @@ set -eu
verbosity=0 verbosity=0
# default to silent output for naked grep; -vvv+ will adjust this # default to silent output for naked grep; -vvv+ will adjust this
export GREP_OPTS=-q GREP_OPTS=(-q)
# shell tracing output is very large from this script; only enable if >= -vvv was passed # shell tracing output is very large from this script; only enable if >= -vvv was passed
while getopts :v opt while getopts :v opt
@ -18,17 +18,17 @@ done
if (( verbosity >= 3 )); if (( verbosity >= 3 ));
then then
set -x; set -x
export GREP_OPTS= ; GREP_OPTS=()
fi fi
echo "running playbook-backed docs tests" echo "running playbook-backed docs tests"
ansible-playbook test.yml -i inventory "$@" ansible-playbook test.yml -i inventory "$@"
# test keyword docs # test keyword docs
ansible-doc -t keyword -l | grep $GREP_OPTS 'vars_prompt: list of variables to prompt for.' ansible-doc -t keyword -l | grep "${GREP_OPTS[@]}" 'vars_prompt: list of variables to prompt for.'
ansible-doc -t keyword vars_prompt | grep $GREP_OPTS 'description: list of variables to prompt for.' ansible-doc -t keyword vars_prompt | grep "${GREP_OPTS[@]}" 'description: list of variables to prompt for.'
ansible-doc -t keyword asldkfjaslidfhals 2>&1 | grep $GREP_OPTS 'Skipping Invalid keyword' ansible-doc -t keyword asldkfjaslidfhals 2>&1 | grep "${GREP_OPTS[@]}" 'Skipping Invalid keyword'
# collections testing # collections testing
( (
@ -55,10 +55,10 @@ expected_out="$(sed '1 s/\(^> TESTNS\.TESTCOL\.YOLO\).*(.*)$/\1/' yolo-text.outp
test "$current_out" == "$expected_out" test "$current_out" == "$expected_out"
echo "ensure we do work with valid collection name for list" echo "ensure we do work with valid collection name for list"
ansible-doc --list testns.testcol --playbook-dir ./ 2>&1 | grep $GREP_OPTS -v "Invalid collection name" ansible-doc --list testns.testcol --playbook-dir ./ 2>&1 | grep "${GREP_OPTS[@]}" -v "Invalid collection name"
echo "ensure we dont break on invalid collection name for list" echo "ensure we dont break on invalid collection name for list"
ansible-doc --list testns.testcol.fakemodule --playbook-dir ./ 2>&1 | grep $GREP_OPTS "Invalid collection name" ansible-doc --list testns.testcol.fakemodule --playbook-dir ./ 2>&1 | grep "${GREP_OPTS[@]}" "Invalid collection name"
echo "filter list with more than one collection (1/2)" echo "filter list with more than one collection (1/2)"
output=$(ansible-doc --list testns.testcol3 testns.testcol4 --playbook-dir ./ 2>&1 | wc -l) output=$(ansible-doc --list testns.testcol3 testns.testcol4 --playbook-dir ./ 2>&1 | wc -l)
@ -96,12 +96,12 @@ do
list_result=$(ansible-doc -l -t ${ptype} --playbook-dir ./ testns.testcol) list_result=$(ansible-doc -l -t ${ptype} --playbook-dir ./ testns.testcol)
metadata_result=$(ansible-doc --metadata-dump --no-fail-on-errors -t ${ptype} --playbook-dir ./ testns.testcol) metadata_result=$(ansible-doc --metadata-dump --no-fail-on-errors -t ${ptype} --playbook-dir ./ testns.testcol)
for name in "${expected_names[@]}"; do for name in "${expected_names[@]}"; do
echo "${list_result}" | grep $GREP_OPTS "testns.testcol.${name}" echo "${list_result}" | grep "${GREP_OPTS[@]}" "testns.testcol.${name}"
echo "${metadata_result}" | grep $GREP_OPTS "testns.testcol.${name}" echo "${metadata_result}" | grep "${GREP_OPTS[@]}" "testns.testcol.${name}"
done done
# ensure we get error if passing invalid collection, much less any plugins # ensure we get error if passing invalid collection, much less any plugins
ansible-doc -l -t ${ptype} bogus.boguscoll 2>&1 | grep $GREP_OPTS "unable to locate collection" ansible-doc -l -t ${ptype} bogus.boguscoll 2>&1 | grep "${GREP_OPTS[@]}" "unable to locate collection"
# TODO: do we want per namespace? # TODO: do we want per namespace?
# ensure we get 1 plugins when restricting namespace # ensure we get 1 plugins when restricting namespace
@ -230,7 +230,7 @@ echo "testing sidecar docs for jinja plugins"
[ "$(ansible-doc -t filter --playbook-dir ./ ansible.legacy.donothing| wc -l)" -gt "0" ] [ "$(ansible-doc -t filter --playbook-dir ./ ansible.legacy.donothing| wc -l)" -gt "0" ]
echo "testing no docs and no sidecar" echo "testing no docs and no sidecar"
ansible-doc -t filter --playbook-dir ./ nodocs 2>&1| grep $GREP_OPTS -c 'missing documentation' || true ansible-doc -t filter --playbook-dir ./ nodocs 2>&1| grep "${GREP_OPTS[@]}" -c 'missing documentation' || true
echo "testing sidecar docs for module" echo "testing sidecar docs for module"
[ "$(ansible-doc -M ./library test_win_module| wc -l)" -gt "0" ] [ "$(ansible-doc -M ./library test_win_module| wc -l)" -gt "0" ]
@ -249,7 +249,7 @@ echo "testing no duplicates for plugins that only exist in ansible.builtin when
[ "$(ansible-doc -l -t filter --playbook-dir ./ |grep -c 'b64encode')" -eq "1" ] [ "$(ansible-doc -l -t filter --playbook-dir ./ |grep -c 'b64encode')" -eq "1" ]
echo "testing with playbook dir, legacy should override" echo "testing with playbook dir, legacy should override"
ansible-doc -t filter split --playbook-dir ./ |grep $GREP_OPTS histerical ansible-doc -t filter split --playbook-dir ./ |grep "${GREP_OPTS[@]}" histerical
pyc_src="$(pwd)/filter_plugins/other.py" pyc_src="$(pwd)/filter_plugins/other.py"
pyc_1="$(pwd)/filter_plugins/split.pyc" pyc_1="$(pwd)/filter_plugins/split.pyc"
@ -258,11 +258,11 @@ trap 'rm -rf "$pyc_1" "$pyc_2"' EXIT
echo "testing pyc files are not used as adjacent documentation" echo "testing pyc files are not used as adjacent documentation"
python -c "import py_compile; py_compile.compile('$pyc_src', cfile='$pyc_1')" python -c "import py_compile; py_compile.compile('$pyc_src', cfile='$pyc_1')"
ansible-doc -t filter split --playbook-dir ./ |grep $GREP_OPTS histerical ansible-doc -t filter split --playbook-dir ./ |grep "${GREP_OPTS[@]}" histerical
echo "testing pyc files are not listed as plugins" echo "testing pyc files are not listed as plugins"
python -c "import py_compile; py_compile.compile('$pyc_src', cfile='$pyc_2')" python -c "import py_compile; py_compile.compile('$pyc_src', cfile='$pyc_2')"
test "$(ansible-doc -l -t module --playbook-dir ./ 2>&1 1>/dev/null |grep -c "notaplugin")" == 0 test "$(ansible-doc -l -t module --playbook-dir ./ 2>&1 1>/dev/null |grep -c "notaplugin")" == 0
echo "testing without playbook dir, builtin should return" echo "testing without playbook dir, builtin should return"
ansible-doc -t filter split 2>&1 |grep $GREP_OPTS -v histerical ansible-doc -t filter split 2>&1 |grep "${GREP_OPTS[@]}" -v histerical

@ -2,17 +2,14 @@
set -eu set -eu
# shellcheck disable=SC2086 basename="$(basename "$0")"
basename="$(basename $0)" dirname="$(basename "$(dirname "$0")")"
# shellcheck disable=SC2046
# shellcheck disable=SC2086
dirname="$(basename $(dirname $0))"
basename_prefix="get-password" basename_prefix="get-password"
default_password="foo-bar" default_password="foo-bar"
case "${basename}" in case "${basename}" in
"${basename_prefix}"-*) "${basename_prefix}"-*)
password="${default_password}-${basename#${basename_prefix}-}" password="${default_password}-${basename#"${basename_prefix}-"}"
;; ;;
*) *)
password="${default_password}" password="${default_password}"

@ -9,10 +9,7 @@ export PIP_DISABLE_PIP_VERSION_CHECK=1
source virtualenv.sh source virtualenv.sh
>&2 echo \ >&2 echo '=== Test that the module gets picked up if discoverable via PYTHONPATH env var ==='
=== Test that the module \
gets picked up if discoverable \
via PYTHONPATH env var ===
PYTHONPATH="${PWD}/ansible-collection-python-dist-boo:$PYTHONPATH" \ PYTHONPATH="${PWD}/ansible-collection-python-dist-boo:$PYTHONPATH" \
ansible \ ansible \
-m python.dist.boo \ -m python.dist.boo \
@ -21,10 +18,7 @@ ansible \
"$@" | grep -E '"greeting": "Hello, Bob!",' "$@" | grep -E '"greeting": "Hello, Bob!",'
>&2 echo \ >&2 echo '=== Test that the module gets picked up if installed into site-packages ==='
=== Test that the module \
gets picked up if installed \
into site-packages ===
python -m pip install pep517 python -m pip install pep517
( # Build a binary Python dist (a wheel) using PEP517: ( # Build a binary Python dist (a wheel) using PEP517:
cp -r ansible-collection-python-dist-boo "${OUTPUT_DIR}/" cp -r ansible-collection-python-dist-boo "${OUTPUT_DIR}/"
@ -45,10 +39,7 @@ ansible \
"$@" | grep -E '"greeting": "Hello, Frodo!",' "$@" | grep -E '"greeting": "Hello, Frodo!",'
>&2 echo \ >&2 echo '=== Test that ansible_collections root takes precedence over PYTHONPATH/site-packages ==='
=== Test that ansible_collections \
root takes precedence over \
PYTHONPATH/site-packages ===
# This is done by injecting a module with the same FQCN # This is done by injecting a module with the same FQCN
# into another collection root. # into another collection root.
ANSIBLE_COLLECTIONS_PATH="${PWD}/ansible-collection-python-dist-foo" \ ANSIBLE_COLLECTIONS_PATH="${PWD}/ansible-collection-python-dist-foo" \

@ -2,9 +2,8 @@
set -eux set -eux
# ignore empty env var and use default # use default timeout
# shellcheck disable=SC1007 ANSIBLE_TIMEOUT='' ansible -m ping testhost -i ../../inventory "$@"
ANSIBLE_TIMEOUT= ansible -m ping testhost -i ../../inventory "$@"
# env var is wrong type, this should be a fatal error pointing at the setting # env var is wrong type, this should be a fatal error pointing at the setting
ANSIBLE_TIMEOUT='lola' ansible -m ping testhost -i ../../inventory "$@" 2>&1|grep 'Invalid type for configuration option setting: DEFAULT_TIMEOUT (from env: ANSIBLE_TIMEOUT)' ANSIBLE_TIMEOUT='lola' ansible -m ping testhost -i ../../inventory "$@" 2>&1|grep 'Invalid type for configuration option setting: DEFAULT_TIMEOUT (from env: ANSIBLE_TIMEOUT)'

Loading…
Cancel
Save