Debian Codegraph @

test/integration/targets/ansible-test-git/collection-tests/git-common.bash

raw
1 #!/usr/bin/env bash
2
3 set -eux -o pipefail
4
5 # make sure git is installed
6 set +e
7 git --version
8 gitres=$?
9 set -e
10
11 if [[ $gitres -ne 0 ]]; then
12 ansible-playbook collection-tests/install-git.yml -i ../../inventory "$@"
13 fi
14
15 dir="$(pwd)"
16
17 uninstall_git() {
18 cd "$dir"
19 ansible-playbook collection-tests/uninstall-git.yml -i ../../inventory "$@"
20 }
21
22 # This is kind of a hack. The uninstall playbook has no way to know the result
23 # of the install playbook to determine if it changed. So instead, we assume
24 # that if git wasn't found to begin with, it was installed by the playbook and
25 # and needs to be removed when we exit.
26 if [[ $gitres -ne 0 ]]; then
27 trap uninstall_git EXIT
28 fi
29
30 # init sub project
31 mkdir "${WORK_DIR}/sub"
32 cd "${WORK_DIR}/sub"
33 touch "README.md"
34 git init
35 git config user.name 'Ansible Test'
36 git config user.email '[email protected]'
37 git add "README.md"
38 git commit -m "Initial commit."
39
40 # copy sub project
41 cp -a "${WORK_DIR}/sub" "${WORK_DIR}/sub-copy"
42
43 # init super project
44 rm -rf "${WORK_DIR}/super" # needed when re-creating in place
45 mkdir "${WORK_DIR}/super"
46 cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}/super"
47 cd "${GIT_TOP_LEVEL}"
48 git init
49
50 # add submodule
51 git -c protocol.file.allow=always submodule add "${WORK_DIR}/sub" "${SUBMODULE_DST}"
52
53 # add a second submodule and then remove the directory to verify the error is handled gracefully
54 git -c protocol.file.allow=always submodule add "${WORK_DIR}/sub-copy" "${SUBMODULE_DST}-copy"
55 rm -rf "${SUBMODULE_DST}-copy"
56
57 # prepare for tests
58 expected="${WORK_DIR}/expected.txt"
59 actual="${WORK_DIR}/actual.txt"
60 expected_warnings="${TEST_DIR}/expected-warnings.txt"
61 actual_warnings="${WORK_DIR}/actual-warnings.txt"
62 cd "${WORK_DIR}/super/ansible_collections/ns/col"
63 mkdir tests/.git
64 touch tests/.git/keep.txt # make sure ansible-test correctly ignores version control within collection subdirectories
65 find . -type f ! -path '*/.git/*' ! -name .git | sed 's|^\./||' | sort >"${expected}"
66 set -x
67
68 # test at the collection base
69 ansible-test env --list-files 2>"${actual_warnings}" | sort >"${actual}"
70 diff --unified "${expected}" "${actual}"
71 diff --unified "${expected_warnings}" "${actual_warnings}"
72
73 # test at the submodule base
74 (cd sub && ansible-test env --list-files 2>"${actual_warnings}" | sort >"${actual}")
75 diff --unified "${expected}" "${actual}"
76 diff --unified "${expected_warnings}" "${actual_warnings}"