diff options
author | Sam Doran <sdoran@redhat.com> | 2019-06-28 16:19:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-28 16:19:27 -0400 |
commit | 6cf6f5a34bebe01f96782a171db8d83d4e7828ca (patch) | |
tree | 90eb9cb093c52d067bab0846ab91a4735d5fe253 /test/integration/targets/ansible | |
parent | 875e7c3e5036b1410e4170c4ff2589c3f12e5ac7 (diff) | |
download | ansible-6cf6f5a34bebe01f96782a171db8d83d4e7828ca.tar.gz |
Use atexit to cleanup tmp dirs (#56532)
* Wrap everything in try/except to avoid leaving files behind
* Add unit tests, integration tests, and changelog
* Do text the correct way
Diffstat (limited to 'test/integration/targets/ansible')
-rwxr-xr-x | test/integration/targets/ansible/runme.sh | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/integration/targets/ansible/runme.sh b/test/integration/targets/ansible/runme.sh index b3ddb65fd7..e9554934ba 100755 --- a/test/integration/targets/ansible/runme.sh +++ b/test/integration/targets/ansible/runme.sh @@ -13,5 +13,26 @@ ansible-config dump -c ./ansible-testé.cfg | grep 'DEFAULT_REMOTE_USER([^)]*) = ANSIBLE_REMOTE_USER=administrator ansible-config dump| grep 'DEFAULT_REMOTE_USER([^)]*) = administrator\>' ansible-config list | grep 'DEFAULT_REMOTE_USER' -# 'view' command must fail when config file is missing -ansible-config view -c ./ansible-non-existent.cfg && exit 1 || echo 'Failure is expected' +# 'view' command must fail when config file is missing or has an invalid file extension +ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq '(FileNotFoundError|IOError): \[Errno [0-9]+\] No such file or directory' err1.txt || (cat err*.txt; rm -f err1.txt; exit 1) +ansible-config view -c ./no-extension 2> err2.txt || grep -q 'Unsupported configuration file extension' err2.txt || (cat err2.txt; rm -f err*.txt; exit 1) +rm -f err*.txt + +# Test that no tmp dirs are left behind when running ansible-config +TMP_DIR=~/.ansible/tmptest +if [[ -d "$TMP_DIR" ]]; then + rm -rf "$TMP_DIR" +fi +ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config list > /dev/null +ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config dump > /dev/null +ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config view > /dev/null + +# wc on macOS is dumb and returns leading spaces +file_count=$(find "$TMP_DIR" -type d -maxdepth 1 | wc -l | sed 's/^ *//') +if [[ $file_count -ne 1 ]]; then + echo "$file_count temporary files were left behind by ansible-config" + if [[ -d "$TMP_DIR" ]]; then + rm -rf "$TMP_DIR" + fi + exit 1 +fi |