summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-test-git/collection-tests/git-common.bash
blob: 340b311f3035cfa148c2996f77d7c62b5e7cf98e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash

set -eux -o pipefail

# make sure git is installed
set +e
git --version
gitres=$?
set -e

if [[ $gitres -ne 0 ]]; then
  ansible-playbook collection-tests/install-git.yml -i ../../inventory "$@"
fi

dir="$(pwd)"

uninstall_git() {
  cd "$dir"
  ansible-playbook collection-tests/uninstall-git.yml -i ../../inventory "$@"
}

# This is kind of a hack. The uninstall playbook has no way to know the result
# of the install playbook to determine if it changed. So instead, we assume
# that if git wasn't found to begin with, it was installed by the playbook and
# and needs to be removed when we exit.
if [[ $gitres -ne 0 ]]; then
  trap uninstall_git EXIT
fi

# init sub project
mkdir "${WORK_DIR}/sub"
cd "${WORK_DIR}/sub"
touch "README.md"
git init
git config user.name 'Ansible Test'
git config user.email 'ansible-test@ansible.com'
git add "README.md"
git commit -m "Initial commit."

# init super project
rm -rf "${WORK_DIR}/super" # needed when re-creating in place
mkdir "${WORK_DIR}/super"
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}/super"
cd "${GIT_TOP_LEVEL}"
git init

# add submodule
git -c protocol.file.allow=always submodule add "${WORK_DIR}/sub" "${SUBMODULE_DST}"

# prepare for tests
expected="${WORK_DIR}/expected.txt"
actual="${WORK_DIR}/actual.txt"
cd "${WORK_DIR}/super/ansible_collections/ns/col"
mkdir tests/.git
touch tests/.git/keep.txt  # make sure ansible-test correctly ignores version control within collection subdirectories
find . -type f ! -path '*/.git/*' ! -name .git | sed 's|^\./||' | sort >"${expected}"
set -x

# test at the collection base
ansible-test env --list-files | sort >"${actual}"
diff --unified "${expected}" "${actual}"

# test at the submodule base
(cd sub && ansible-test env --list-files | sort >"${actual}")
diff --unified "${expected}" "${actual}"