summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy/runme.sh
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2020-02-14 21:00:00 +0100
committerGitHub <noreply@github.com>2020-02-14 21:00:00 +0100
commitf506fd4730aec842294933ea2c6656470a09a87a (patch)
tree6cd0b1f07bc4210fce0aab0568a271cb94c839a3 /test/integration/targets/ansible-galaxy/runme.sh
parentUpdate YAMLSyntax.rst with yamllint (#66622) (diff)
downloadansible-f506fd4730aec842294933ea2c6656470a09a87a.tar.xz
ansible-f506fd4730aec842294933ea2c6656470a09a87a.zip
Add ansible-galaxy collection list command (#65022)
* Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
Diffstat (limited to 'test/integration/targets/ansible-galaxy/runme.sh')
-rwxr-xr-xtest/integration/targets/ansible-galaxy/runme.sh85
1 files changed, 83 insertions, 2 deletions
diff --git a/test/integration/targets/ansible-galaxy/runme.sh b/test/integration/targets/ansible-galaxy/runme.sh
index f815eccc2a..97b04234f6 100755
--- a/test/integration/targets/ansible-galaxy/runme.sh
+++ b/test/integration/targets/ansible-galaxy/runme.sh
@@ -4,7 +4,7 @@ set -eux -o pipefail
ansible-playbook setup.yml "$@"
-trap 'ansible-playbook cleanup.yml' EXIT
+trap 'ansible-playbook ${ANSIBLE_PLAYBOOK_DIR}/cleanup.yml' EXIT
# Very simple version test
ansible-galaxy --version
@@ -39,7 +39,6 @@ popd # "${galaxy_local_test_role_dir}"
# Status message function (f_ to designate that it's a function)
f_ansible_galaxy_status()
{
-
printf "\n\n\n### Testing ansible-galaxy: %s\n" "${@}"
}
@@ -208,6 +207,88 @@ f_ansible_galaxy_status \
[[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]]
grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt
+
+## ansible-galaxy collection list tests
+
+# Create more collections and put them in various places
+f_ansible_galaxy_status \
+ "setting up for collection list tests"
+
+rm -rf ansible_test/* install/*
+
+NAMES=(zoo museum airport)
+for n in "${NAMES[@]}"; do
+ ansible-galaxy collection init "ansible_test.$n"
+ ansible-galaxy collection build "ansible_test/$n"
+done
+
+ansible-galaxy collection install ansible_test-zoo-1.0.0.tar.gz
+ansible-galaxy collection install ansible_test-museum-1.0.0.tar.gz -p ./install
+ansible-galaxy collection install ansible_test-airport-1.0.0.tar.gz -p ./local
+
+# Change the collection version and install to another location
+sed -i -e 's#^version:.*#version: 2.5.0#' ansible_test/zoo/galaxy.yml
+ansible-galaxy collection build ansible_test/zoo
+ansible-galaxy collection install ansible_test-zoo-2.5.0.tar.gz -p ./local
+
+export ANSIBLE_COLLECTIONS_PATHS=~/.ansible/collections:${galaxy_testdir}/local
+
+f_ansible_galaxy_status \
+ "collection list all collections"
+
+ ansible-galaxy collection list -p ./install | tee out.txt
+
+ [[ $(grep -c ansible_test out.txt) -eq 4 ]]
+
+f_ansible_galaxy_status \
+ "collection list specific collection"
+
+ ansible-galaxy collection list -p ./install ansible_test.airport | tee out.txt
+
+ [[ $(grep -c 'ansible_test\.airport' out.txt) -eq 1 ]]
+
+f_ansible_galaxy_status \
+ "collection list specific collection found in multiple places"
+
+ ansible-galaxy collection list -p ./install ansible_test.zoo | tee out.txt
+
+ [[ $(grep -c 'ansible_test\.zoo' out.txt) -eq 2 ]]
+
+f_ansible_galaxy_status \
+ "collection list all with duplicate paths"
+
+ ansible-galaxy collection list -p ~/.ansible/collections | tee out.txt
+
+ [[ $(grep -c '# /root/.ansible/collections/ansible_collections' out.txt) -eq 1 ]]
+
+f_ansible_galaxy_status \
+ "collection list invalid collection name"
+
+ ansible-galaxy collection list -p ./install dirty.wraughten.name "$@" 2>&1 | tee out.txt || echo "expected failure"
+
+ grep 'ERROR! Invalid collection name' out.txt
+
+f_ansible_galaxy_status \
+ "collection list path not found"
+
+ ansible-galaxy collection list -p ./nope "$@" 2>&1 | tee out.txt || echo "expected failure"
+
+ grep '\[WARNING\]: - the configured path' out.txt
+
+f_ansible_galaxy_status \
+ "collection list missing ansible_collections dir inside path"
+
+ mkdir emptydir
+
+ ansible-galaxy collection list -p ./emptydir "$@"
+
+ rmdir emptydir
+
+unset ANSIBLE_COLLECTIONS_PATHS
+
+## end ansible-galaxy collection list
+
+
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"