summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-test-git
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/ansible-test-git')
-rw-r--r--test/integration/targets/ansible-test-git/aliases4
-rw-r--r--test/integration/targets/ansible-test-git/ansible_collections/ns/col/tests/.keep0
-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
-rwxr-xr-xtest/integration/targets/ansible-test-git/runme.sh24
8 files changed, 136 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-test-git/aliases b/test/integration/targets/ansible-test-git/aliases
new file mode 100644
index 0000000..7741d44
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/aliases
@@ -0,0 +1,4 @@
+shippable/posix/group3 # runs in the distro test containers
+shippable/generic/group1 # runs in the default test container
+context/controller
+needs/target/collection
diff --git a/test/integration/targets/ansible-test-git/ansible_collections/ns/col/tests/.keep b/test/integration/targets/ansible-test-git/ansible_collections/ns/col/tests/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/ansible_collections/ns/col/tests/.keep
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
diff --git a/test/integration/targets/ansible-test-git/runme.sh b/test/integration/targets/ansible-test-git/runme.sh
new file mode 100755
index 0000000..04e8844
--- /dev/null
+++ b/test/integration/targets/ansible-test-git/runme.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+set -eux -o pipefail
+
+# tests must be executed outside of the ansible source tree
+# otherwise ansible-test will test the ansible source instead of the test collection
+# the temporary directory provided by ansible-test resides within the ansible source tree
+tmp_dir=$(mktemp -d)
+
+trap 'rm -rf "${tmp_dir}"' EXIT
+
+export TEST_DIR
+export WORK_DIR
+
+TEST_DIR="$PWD"
+
+for test in collection-tests/*.sh; do
+ WORK_DIR="${tmp_dir}/$(basename "${test}" ".sh")"
+ mkdir "${WORK_DIR}"
+ echo "**********************************************************************"
+ echo "TEST: ${test}: STARTING"
+ "${test}" "${@}" || (echo "TEST: ${test}: FAILED" && exit 1)
+ echo "TEST: ${test}: PASSED"
+done