Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ansible-galaxy-collection-scm tests for requirements.yml #73029

Merged
merged 2 commits into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,6 +12,7 @@
block:

- include_tasks: ./setup.yml
- include_tasks: ./requirements.yml
- include_tasks: ./individual_collection_repo.yml
- include_tasks: ./setup_multi_collection_repo.yml
- include_tasks: ./multi_collection_repo_all.yml
Expand Down
@@ -0,0 +1,89 @@
- name: make a requirements directory
file:
state: directory
path: '{{ galaxy_dir }}/requirements'

- name: populate requirement templates
template:
src: "{{ item }}"
dest: "{{ galaxy_dir }}/requirements/{{ item }}"
loop:
- source_only.yml
- source_and_name.yml
- source_and_name_and_type.yml
- name_without_type.yml
- git_prefix_name.yml
- name_and_type.yml

- name: test source is not a git repo
command: 'ansible-galaxy collection install -r source_only.yml'
register: result
ignore_errors: true
args:
chdir: '{{ galaxy_dir }}/requirements'

- assert:
that:
- result.failed
- '"ERROR! Collections requirement entry should contain the key name." in result.stderr'

- name: test source is not a git repo even if name is provided
command: 'ansible-galaxy collection install -r source_and_name.yml'
register: result
ignore_errors: true
args:
chdir: '{{ galaxy_dir }}/requirements'

- assert:
that:
- result.failed
- '"ERROR! Unknown error when attempting to call Galaxy" in result.stderr'

- name: test source is not a git repo even if name and type is provided
command: 'ansible-galaxy collection install -r source_and_name_and_type.yml'
register: result
ignore_errors: true
args:
chdir: '{{ galaxy_dir }}/requirements'

- assert:
that:
- result.failed
- 'result.stderr is search("ERROR! - command /.*/git clone ansible.nope ansible.nope failed")'

- name: test using name as a git repo without git+ prefix
command: 'ansible-galaxy collection install -r name_without_type.yml'
register: result
ignore_errors: true
args:
chdir: '{{ galaxy_dir }}/requirements'

- assert:
that:
- result.failed
- '"name must be in the format <namespace>.<collection>" in result.stderr'

- name: Clone a git repository
git:
repo: https://github.com/ansible-collections/amazon.aws.git
dest: '{{ galaxy_dir }}/development/amazon.aws/'

- name: test using name as a git repo
command: 'ansible-galaxy collection install -r git_prefix_name.yml'
register: result
args:
chdir: '{{ galaxy_dir }}/requirements'

- name: test using name plus type as a git repo
command: 'ansible-galaxy collection install -r name_and_type.yml --force'
register: result
args:
chdir: '{{ galaxy_dir }}/requirements'

- name: remove the test repo and requirements dir
file:
path: '{{ item }}'
state: absent
loop:
- '{{ galaxy_dir }}/development/amazon.aws/'
- '{{ galaxy_dir }}/requirements'
@@ -1,3 +1,18 @@
- name: test installing one collection that has a SCM dep with --no-deps
command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/ --no-deps'

- name: list installed collections
command: 'ansible-galaxy collection list'
register: installed_collections

- assert:
that:
- "'ansible_test.collection_1' in installed_collections.stdout"
- "'ansible_test.collection_2' not in installed_collections.stdout"

- name: remove collections to test installing with the dependency
include_tasks: ./empty_installed_collections.yml

- name: test installing one collection that has a SCM dep
command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/'

Expand Down
@@ -0,0 +1,2 @@
collections:
- name: git+file://{{ galaxy_dir }}/development/amazon.aws/.git
@@ -0,0 +1,3 @@
collections:
- name: file://{{ galaxy_dir }}/development/amazon.aws/.git
type: git
@@ -0,0 +1,3 @@
collections:
# should not work: git prefix or type is required
- name: file://{{ galaxy_dir }}/development/amazon.aws/.git
@@ -0,0 +1,4 @@
collections:
# should not work: source is expected to be a galaxy server name or URL
- source: git+file://{{ galaxy_dir }}/development/amazon.aws/.git
name: ansible.nope
@@ -0,0 +1,5 @@
collections:
# should not work: source is expected to be a galaxy server name or URL
- source: git+file://{{ galaxy_dir }}/development/amazon.aws/.git
name: ansible.nope
type: git
@@ -0,0 +1,3 @@
collections:
# should not work: source is expected to be a galaxy server name or URL
- source: git+file://{{ galaxy_dir }}/development/amazon.aws/.git