summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-test-git/collection-tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/ansible-test-git/collection-tests')
-rwxr-xr-xtest/integration/targets/ansible-test-git/collection-tests/git-at-collection-base.sh10
-rwxr-xr-xtest/integration/targets/ansible-test-git/collection-tests/git-at-collection-root.sh10
-rwxr-xr-xtest/integration/targets/ansible-test-git/collection-tests/git-common.bash65
-rw-r--r--test/integration/targets/ansible-test-git/collection-tests/install-git.yml5
-rw-r--r--test/integration/targets/ansible-test-git/collection-tests/uninstall-git.yml18
5 files changed, 108 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-base.sh b/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-base.sh
new file mode 100755
index 0000000..31ebfbb
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-base.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+set -eux -o pipefail
+
+export GIT_TOP_LEVEL SUBMODULE_DST
+
+GIT_TOP_LEVEL="${WORK_DIR}/super/ansible_collections/ns/col"
+SUBMODULE_DST="sub"
+
+source collection-tests/git-common.bash
diff --git a/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-root.sh b/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-root.sh
new file mode 100755
index 0000000..8af4387
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/collection-tests/git-at-collection-root.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+set -eux -o pipefail
+
+export GIT_TOP_LEVEL SUBMODULE_DST
+
+GIT_TOP_LEVEL="${WORK_DIR}/super"
+SUBMODULE_DST="ansible_collections/ns/col/sub"
+
+source collection-tests/git-common.bash
diff --git a/test/integration/targets/ansible-test-git/collection-tests/git-common.bash b/test/integration/targets/ansible-test-git/collection-tests/git-common.bash
new file mode 100755
index 0000000..340b311
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/collection-tests/git-common.bash
@@ -0,0 +1,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}"
diff --git a/test/integration/targets/ansible-test-git/collection-tests/install-git.yml b/test/integration/targets/ansible-test-git/collection-tests/install-git.yml
new file mode 100644
index 0000000..29adead
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/collection-tests/install-git.yml
@@ -0,0 +1,5 @@
+- hosts: localhost
+ tasks:
+ - name: Make sure git is installed
+ package:
+ name: git
diff --git a/test/integration/targets/ansible-test-git/collection-tests/uninstall-git.yml b/test/integration/targets/ansible-test-git/collection-tests/uninstall-git.yml
new file mode 100644
index 0000000..f94caea
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/collection-tests/uninstall-git.yml
@@ -0,0 +1,18 @@
+- hosts: localhost
+ tasks:
+ - name: Make sure git is uninstalled
+ package:
+ name: git
+ state: absent
+ register: git_remove
+
+ # This gets dragged in as a dependency of git on FreeBSD.
+ # We need to remove it too when done.
+ - name: remove python37 if necessary
+ package:
+ name: python37
+ state: absent
+ when:
+ - git_remove is changed
+ - ansible_distribution == 'FreeBSD'
+ - ansible_python.version.major == 2