Skip to content

Commit

Permalink
add collection_* tests
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Sep 17, 2024
1 parent be4cbb9 commit 1c6933a
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ jobs:
- name: Run integration test - ah_collection_upload
run: ansible-test integration ah_collection_upload
working-directory: /home/runner/collections/ansible_collections/ansible/hub

- name: Run integration test - collection_remote
run: ansible-test integration collection_remote
working-directory: /home/runner/collections/ansible_collections/ansible/hub

- name: Run integration test - collection_repository
run: ansible-test integration collection_repository
working-directory: /home/runner/collections/ansible_collections/ansible/hub

- name: Run integration test - collection_repository_sync
run: ansible-test integration collection_repository_sync
working-directory: /home/runner/collections/ansible_collections/ansible/hub
28 changes: 0 additions & 28 deletions tests/integration/targets/ah_collection_upload/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,7 @@
that:
- r.changed

- name: Delete a collection to the given collection
ansible.hub.ah_collection:
namespace: "{{ namespace }}"
name: "{{ collection_name }}"
version: 1.0.0
state: absent
register: r

- name: Check if the collection is deleted successfully
assert:
that:
- r.changed
- r.deleted

always:
- name: Delete a collection to the given collection
ansible.hub.ah_collection:
namespace: "{{ namespace }}"
name: "{{ collection_name }}"
version: 1.0.0
state: absent
ignore_errors: true

- name: Delete namespace
ansible.hub.ah_namespace:
name: "{{ namespace }}"
state: absent
ignore_errors: true

- name: Remove built collection
ansible.builtin.file:
path: "{{ build_path }}/sample-sample-1.0.0.tar.gz"
Expand Down
57 changes: 57 additions & 0 deletions tests/integration/targets/collection_remote/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- name: collection_remote integration tests
module_defaults:
group/ansible.hub.hub:
ah_host: "{{ ah_host }}"
ah_username: "{{ ah_username }}"
ah_password: "{{ ah_password }}"
validate_certs: "{{ ah_verify_ssl }}"
block:
- name: Generate a test_id for the test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}"
when: test_id is not defined

- name: Define variables
set_fact:
collection_repo_name: "sample_{{ test_id }}"
distribution: "sample_{{ test_id }}"

- name: Create a collection repository
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
description: "description of the repository"
pulp_labels:
pipeline: "approved"
distribution:
name: "{{ distribution }}"
state: present
remote: community
wait: true
register: r

- name: Check if the collection repository is created
assert:
that:
- r.changed

- name: Configure collection
collection_remote:
name: "{{ collection_repo_name }}"
url: https://galaxy.ansible.com/api/
requirements:
- galaxy.galaxy
- infra.controller_configuration
register: r

- name: Check if the collection_remote works
assert:
that:
- r.changed

always:
- name: Cleanup - Delete collection repository
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
state: absent
ignore_errors: true
114 changes: 114 additions & 0 deletions tests/integration/targets/collection_repository/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
- name: collection_repository integration tests
module_defaults:
group/ansible.hub.hub:
ah_host: "{{ ah_host }}"
ah_username: "{{ ah_username }}"
ah_password: "{{ ah_password }}"
validate_certs: "{{ ah_verify_ssl }}"
block:
- name: Generate a test_id for the test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}"
when: test_id is not defined

- name: Define variables
set_fact:
collection_repo_name: "sample_{{ test_id }}"
distribution: "sample_{{ test_id }}"

- name: Create a collection repository in check mode
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
description: "description of the repository"
pulp_labels:
pipeline: "approved"
distribution:
name: "{{ distribution }}"
state: present
remote: community
wait: true
register: r
check_mode: yes

- name: Check if the collection repository is created in check mode
assert:
that:
- r.changed

- name: Create a collection repository
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
description: "description of the repository"
pulp_labels:
pipeline: "approved"
distribution:
name: "{{ distribution }}"
state: present
remote: community
wait: true
register: r

- name: Check if the collection repository is created
assert:
that:
- r.changed

- name: Create a collection repository again
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
description: "description of the repository"
pulp_labels:
pipeline: "approved"
distribution:
name: "{{ distribution }}"
state: present
remote: community
wait: true
register: r

- name: Check if the collection repository is not created again
assert:
that:
- not r.changed

- name: Delete collection repository in check mode
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
state: absent
check_mode: yes
register: r

- name: Check if the collection is deleted in check mode
assert:
that:
- r.changed

- name: Delete collection repository
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
state: absent
register: r

- name: Check if the collection is deleted
assert:
that:
- r.changed

- name: Delete collection repository again
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
state: absent
register: r

- name: Check if the collection is not deleted again
assert:
that:
- not r.changed

always:
- name: Cleanup - Delete collection repository
ansible.hub.collection_repository:
name: "{{ collection_repo_name }}"
state: absent
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: collection_repository_sync integration tests
module_defaults:
group/ansible.hub.hub:
ah_host: "{{ ah_host }}"
ah_username: "{{ ah_username }}"
ah_password: "{{ ah_password }}"
validate_certs: "{{ ah_verify_ssl }}"
block:
- name: Sync rh-certified in check mode
ansible.hub.collection_repository_sync:
name: rh-certified
wait: false
check_mode: yes
register: r

- name: Check if sync is successful
assert:
that:
- r.changed

- name: Sync rh-certified
ansible.hub.collection_repository_sync:
name: rh-certified
wait: false
register: r

- name: Check if sync is successful
assert:
that:
- r.changed

0 comments on commit 1c6933a

Please sign in to comment.