Fix callback_default integration test for non-root users

This test compares the test output to previously collected output. However, this
previously assumed that the tests are run as root, even though needs/root in
aliases is not set.

So instead parameterize the output, and use sed to replace the value that
diverge when running it as different users.
pull/83844/head
Lee Garrett 3 months ago
parent 746e6584a0
commit be073c4bea

@ -1,6 +1,6 @@
+ ansible-playbook -i inventory test_include_role_fails.yml
++ set +x
ERROR! the role 'does-not-exist' was not found in TEST_PATH/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH
ERROR! the role 'does-not-exist' was not found in TEST_PATH/roles:/<<HOMEDIR>>/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH
The error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may
be elsewhere in the file depending on the exact syntax problem.

@ -2,7 +2,7 @@
PLAY [testhost] ****************************************************************
TASK [include_role : does-not-exist] *******************************************
fatal: [testhost]: FAILED! => {"changed": false, "reason": "the role 'does-not-exist' was not found in TEST_PATH/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH\n\nThe error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - include_role:\n name: does-not-exist\n ^ here\n"}
fatal: [testhost]: FAILED! => {"changed": false, "reason": "the role 'does-not-exist' was not found in TEST_PATH/roles:/<<HOMEDIR>>/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH\n\nThe error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - include_role:\n name: does-not-exist\n ^ here\n"}
PLAY RECAP *********************************************************************
testhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

@ -160,15 +160,15 @@ changed: [testhost] =>
changed: true
checksum: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
dest: .../test_diff.txt
gid: 0
group: root
gid: <<GID>>
group: <<GROUP>>
md5sum: acbd18db4cc2f85cedef654fccc4a4d8
mode: '0644'
owner: root
owner: <<OWNER>>
size: 3
src: .../.source.txt
state: file
uid: 0
uid: <<UID>>
TASK [replace] *****************************************************************
--- before: .../test_diff.txt

@ -167,15 +167,15 @@ changed: [testhost] =>
changed: true
checksum: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
dest: .../test_diff.txt
gid: 0
group: root
gid: <<GID>>
group: <<GROUP>>
md5sum: acbd18db4cc2f85cedef654fccc4a4d8
mode: '0644'
owner: root
owner: <<OWNER>>
size: 3
src: .../.source.txt
state: file
uid: 0
uid: <<UID>>
TASK [replace] *****************************************************************
--- before: .../test_diff.txt

@ -13,6 +13,8 @@
set -eux
umask 0022
run_test() {
local testname=$1
local playbook=$2
@ -37,6 +39,15 @@ run_test() {
sed -i -e '/secontext:/d' "${OUTFILE}.${testname}.stdout"
sed -i -e 's/group: wheel/group: root/g' "${OUTFILE}.${testname}.stdout"
# normalize gid/group/owner/uid/homedir so tests can run as non-root user
ESC_HOME=$(echo "${HOME}" | sed -e 's/\//\\\//g')
sed -i -e "s/${ESC_HOME}/\/<<HOMEDIR>>/g" "${OUTFILE}.${testname}.stdout"
sed -i -e "s/${ESC_HOME}/\/<<HOMEDIR>>/g" "${OUTFILE}.${testname}.stderr"
sed -i -e "s/gid: $(id -g)/gid: <<GID>>/g" "${OUTFILE}.${testname}.stdout"
sed -i -e "s/group: $(id -gn)/group: <<GROUP>>/g" "${OUTFILE}.${testname}.stdout"
sed -i -e "s/owner: $(id -un)/owner: <<OWNER>>/g" "${OUTFILE}.${testname}.stdout"
sed -i -e "s/uid: $(id -u)/uid: <<UID>>/g" "${OUTFILE}.${testname}.stdout"
diff -u "${ORIGFILE}.${testname}.stdout" "${OUTFILE}.${testname}.stdout" || diff_failure
diff -u "${ORIGFILE}.${testname}.stderr" "${OUTFILE}.${testname}.stderr" || diff_failure
}

Loading…
Cancel
Save