Debian Codegraph @

test/integration/targets/collection/setup.sh

raw
1 #!/usr/bin/env bash
2 # Source this file from collection integration tests.
3 #
4 # It simplifies several aspects of collection testing:
5 #
6 # 1) Collection tests must be executed outside of the ansible source tree.
7 # Otherwise ansible-test will test the ansible source instead of the test collection.
8 # The temporary directory provided by ansible-test resides within the ansible source tree.
9 #
10 # 2) Sanity test ignore files for collections must be versioned based on the ansible-core version being used.
11 # This script generates an ignore file with the correct filename for the current ansible-core version.
12 #
13 # 3) Sanity tests which are multi-version require an ignore entry per Python version.
14 # This script replicates these ignore entries for each supported Python version based on the ignored path.
15 #
16 # 4) Windows tests need access to the ansible.windows vendored collection.
17 # This script copies any of the existing collections in ANSIBLE_COLLECTIONS_PATH to the temporary directory.
18 #
19 set -eu -o pipefail
20
21 export TEST_DIR
22 export WORK_DIR
23
24 TEST_DIR="$PWD"
25 WORK_DIR="$(mktemp -d)"
26
27 trap 'rm -rf "${WORK_DIR}"' EXIT
28
29 cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
30 cd "${WORK_DIR}/ansible_collections/ns/${COLLECTION_NAME:-col}"
31
32 if [ "${ANSIBLE_COLLECTIONS_PATH:+set}" = "set" ]; then
33 IFS=':' read -ra collections_paths <<< "${ANSIBLE_COLLECTIONS_PATH}"
34
35 for collections_path in "${collections_paths[@]}"; do
36 if [ -d "${collections_path}/ansible_collections" ]; then
37 cp -aL "${collections_path}"/ansible_collections/* "${WORK_DIR}/ansible_collections"
38 fi
39 done
40 fi
41
42 "${TEST_DIR}/../collection/update-ignore.py"