From 471506c5d4e3fb53eacd599196229859182c25a9 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 3 Jan 2022 18:43:17 +0100 Subject: [PATCH] Improve changed / nonchanged validations by using new modules from community.internal_test_tools (#183) * Use modules from internal_test_tools instead of stat workaround to check whether file actually changed. * Properly add testing dependency. --- .../targets/openssl_privatekey/tasks/impl.yml | 20 ++++++++++++------- .../openssl_privatekey/tests/validate.yml | 2 +- tests/requirements.yml | 1 + tests/utils/shippable/shippable.sh | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/integration/targets/openssl_privatekey/tasks/impl.yml b/tests/integration/targets/openssl_privatekey/tasks/impl.yml index 70f57019..a9f8327a 100644 --- a/tests/integration/targets/openssl_privatekey/tasks/impl.yml +++ b/tests/integration/targets/openssl_privatekey/tasks/impl.yml @@ -299,11 +299,18 @@ size: '{{ default_rsa_key_size }}' select_crypto_backend: '{{ select_crypto_backend }}' register: privatekey_mode_1 + - name: "({{ select_crypto_backend }}) Stat for privatekey_mode" stat: path: '{{ remote_tmp_dir }}/privatekey_mode.pem' register: privatekey_mode_1_stat +- name: "({{ select_crypto_backend }}) Collect file information" + community.internal_test_tools.files_collect: + files: + - path: '{{ remote_tmp_dir }}/privatekey_mode.pem' + register: privatekey_mode_1_fileinfo + - name: "({{ select_crypto_backend }}) Generate privatekey_mode (mode 0400, idempotency)" openssl_privatekey: path: '{{ remote_tmp_dir }}/privatekey_mode.pem' @@ -312,13 +319,6 @@ select_crypto_backend: '{{ select_crypto_backend }}' register: privatekey_mode_2 -- name: Make sure that mtime actually changes. - # The "privatekey_mode_1_stat.stat.mtime != privatekey_mode_3_stat.stat.mtime" test should be - # changed to compare content instead of mtime. On macOS 10.15, mtime resolution is one second, - # and the machine (VM) is fast enough that both modifications can happen in the same second. - pause: - seconds: 1 - - name: "({{ select_crypto_backend }}) Generate privatekey_mode (mode 0400, force)" openssl_privatekey: path: '{{ remote_tmp_dir }}/privatekey_mode.pem' @@ -327,11 +327,17 @@ size: '{{ default_rsa_key_size }}' select_crypto_backend: '{{ select_crypto_backend }}' register: privatekey_mode_3 + - name: "({{ select_crypto_backend }}) Stat for privatekey_mode" stat: path: '{{ remote_tmp_dir }}/privatekey_mode.pem' register: privatekey_mode_3_stat +- name: "({{ select_crypto_backend }}) Make sure that file changed" + community.internal_test_tools.files_diff: + state: '{{ privatekey_mode_1_fileinfo }}' + register: privatekey_mode_3_file_change + - block: - name: "({{ select_crypto_backend }}) Generate privatekey_fmt_1 - auto format" openssl_privatekey: diff --git a/tests/integration/targets/openssl_privatekey/tests/validate.yml b/tests/integration/targets/openssl_privatekey/tests/validate.yml index 7cbb2d2d..5b7aca1e 100644 --- a/tests/integration/targets/openssl_privatekey/tests/validate.yml +++ b/tests/integration/targets/openssl_privatekey/tests/validate.yml @@ -186,7 +186,7 @@ - privatekey_mode_2 is not changed - privatekey_mode_3 is changed - privatekey_mode_3_stat.stat.mode == '0400' - - privatekey_mode_1_stat.stat.mtime != privatekey_mode_3_stat.stat.mtime + - privatekey_mode_3_file_change is changed - name: "({{ select_crypto_backend }}) Validate format 1" assert: diff --git a/tests/requirements.yml b/tests/requirements.yml index 5a2c9c80..df5f6395 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,3 +1,4 @@ integration_tests_dependencies: - community.general +- community.internal_test_tools unit_tests_dependencies: [] diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 6a178ffe..41dc97ef 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -89,7 +89,7 @@ if [ "${test}" == "sanity/extra" ]; then fi # START: HACK install integration test dependencies -if [ "${test}" == "sanity/extra" ]; then +if [ "${script}" != "units" ] && [ "${script}" != "sanity" ] || [ "${test}" == "sanity/extra" ]; then # Nothing further should be added to this list. # This is to prevent modules or plugins in this collection having a runtime dependency on other collections. retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/internal_test_tools"