Skip to content

Commit

Permalink
More integration tests (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
herve4m authored Aug 7, 2024
1 parent 2d18565 commit 9d3a0a0
Show file tree
Hide file tree
Showing 13 changed files with 1,097 additions and 21 deletions.
8 changes: 4 additions & 4 deletions plugins/modules/quay_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def main():
new_fields["name"] = new_name
# The original application does not exists...
if not app_details:
# and neither the new organization. Create that new organization.
# and neither the new application. Create that new application.
if not new_app_details:
data = module.create(
"application",
Expand All @@ -297,8 +297,8 @@ def main():
)
exit_module(module, True, data)

# The original organization does not exists but the new one does.
# Update that new organization.
# The original application does not exists but the new one does.
# Update that new application.
updated, data = module.update(
new_app_details,
"application",
Expand All @@ -310,7 +310,7 @@ def main():
id=new_app_details.get("client_id", ""),
)
exit_module(module, updated, data if updated else new_app_details)
# The original organization exists. Rename it.
# The original application exists. Rename it.
updated, data = module.update(
app_details,
"application",
Expand Down
81 changes: 81 additions & 0 deletions tests/integration/targets/quay_api_token/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,87 @@
quay_host: "{{ quay_url }}"
validate_certs: false

- name: ERROR EXPECTED Non-existing user
infra.quay_configuration.quay_api_token:
for_user: nonexistinguser
quay_username: testuser1
quay_password: vs9mrD55NP
client_id: "{{ app_details['client_id'] }}"
rights:
- org:admin
- repo:admin
- repo:create
- repo:read
- repo:write
- user:admin
- user:read
quay_host: "{{ quay_url }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing user)

- name: ERROR EXPECTED No rights specified
infra.quay_configuration.quay_api_token:
quay_username: testuser1
quay_password: vs9mrD55NP
client_id: "{{ app_details['client_id'] }}"
rights: []
quay_host: "{{ quay_url }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing organization)

- name: Generate an OAuth access token for the current user (check mode)
infra.quay_configuration.quay_api_token:
quay_username: testuser1
quay_password: vs9mrD55NP
client_id: "{{ app_details['client_id'] }}"
rights:
- all
quay_host: "{{ quay_url }}"
validate_certs: false
check_mode: true
register: result

- name: Ensure that the returned data has the access_token key
ansible.builtin.assert:
that: "'access_token' in result"
fail_msg: The result should have the access_token key

- name: Generate an OAuth access token for ansibletestuser1 (check mode)
infra.quay_configuration.quay_api_token:
for_user: ansibletestuser1
quay_username: testuser1
quay_password: vs9mrD55NP
client_id: "{{ app_details['client_id'] }}"
rights:
- org:admin
- repo:admin
- repo:create
- repo:read
- repo:write
- user:admin
- user:read
quay_host: "{{ quay_url }}"
validate_certs: false
check_mode: true
register: result

- name: Ensure that the task did change something
ansible.builtin.assert:
that: result['changed']
fail_msg: The preceding task should created the token

- name: Ensure testteam1 team is removed
infra.quay_configuration.quay_team:
name: testteam1
Expand Down
70 changes: 70 additions & 0 deletions tests/integration/targets/quay_application/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,76 @@
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Non-existing organization and state=absent (no change)
infra.quay_configuration.quay_application:
organization: nonexisting
name: ansibletestapp1
state: absent
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
register: result

- name: Ensure that the task did not change anything
ansible.builtin.assert:
that: not result['changed']
fail_msg: The preceding task should not have changed anything

- name: ERROR EXPECTED Non-existing organization
infra.quay_configuration.quay_application:
organization: nonexisting
name: ansibletestapp1
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing organization)

- name: ERROR EXPECTED Already existing application
infra.quay_configuration.quay_application:
organization: ansibletestorg
name: ansibletestapp2
new_name: ansibletestapp3
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (application exists)

- name: Ensure the application ansibletestapp2 is updated (new_name)
infra.quay_configuration.quay_application:
organization: ansibletestorg
name: doesnotexist
new_name: ansibletestapp2
description: Application 2 description
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure the application ansibletestapp3 is removed
infra.quay_configuration.quay_application:
organization: ansibletestorg
name: doesnotexist
new_name: ansibletestapp3
description: "New ansibletestapp3 application"
state: absent
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure the applications are removed
infra.quay_configuration.quay_application:
organization: ansibletestorg
Expand Down
111 changes: 111 additions & 0 deletions tests/integration/targets/quay_default_perm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,117 @@
that: not result['changed']
fail_msg: The preceding task should not have changed anything

- name: Missing organization and state=absent (no change)
infra.quay_configuration.quay_default_perm:
organization: nonexisting
name: ansibletestteam1
type: team
role: admin
creator: ansibletestuser2
state: absent
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
register: result

- name: Ensure that the task did not change anything
ansible.builtin.assert:
that: not result['changed']
fail_msg: The preceding task should not have changed anything

- name: ERROR EXPECTED Non-existing organization
infra.quay_configuration.quay_default_perm:
organization: nonexisting
name: ansibletestteam1
type: team
role: admin
creator: ansibletestuser2
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing organization)

- name: ERROR EXPECTED Non-existing user
infra.quay_configuration.quay_default_perm:
organization: ansibletestorg
name: nonexistinguser
type: user
role: admin
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing user)

- name: ERROR EXPECTED Non-existing team
infra.quay_configuration.quay_default_perm:
organization: ansibletestorg
name: nonexistingteam
type: team
role: admin
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing team)

- name: ERROR EXPECTED Non-existing creator
infra.quay_configuration.quay_default_perm:
organization: ansibletestorg
name: ansibletestteam1
type: team
role: admin
creator: nonexistingcreator
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (non-existing creator)

- name: ERROR EXPECTED Creator is a robot account
infra.quay_configuration.quay_default_perm:
organization: ansibletestorg
name: ansibletestteam1
type: team
role: admin
creator: ansibletestorg+ansibletestrobot1
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
ignore_errors: true
register: result

- name: Ensure that the task failed
ansible.builtin.assert:
that: result['failed']
fail_msg: The preceding task should have failed (creator is a robot)

- name: Ensure default perm anon-read-ansibletestuser1 is removed
infra.quay_configuration.quay_default_perm:
organization: ansibletestorg
Expand Down
15 changes: 14 additions & 1 deletion tests/integration/targets/quay_layer_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
that: layers1['layers']|length == layers2['layers']|length
fail_msg: The same image should have been returned

- name: Retrieve an image with no namespace (error)
- name: ERROR EXPECTED Retrieve an image with no namespace
infra.quay_configuration.quay_layer_info:
image: nosuchimageipresume
quay_host: quay.io
Expand All @@ -32,6 +32,19 @@
that: result['failed']
fail_msg: The preceding task should have failed

- name: Retrieve an image in a non-existing namespace
infra.quay_configuration.quay_layer_info:
image: nonexisting/ansibletestrepo:latest
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
register: result

- name: Ensure that the task did not change anything
ansible.builtin.assert:
that: not result['changed']
fail_msg: The preceding task should not have changed anything

- name: Retrieve a non-existing image in my namespace (no change)
infra.quay_configuration.quay_layer_info:
image: dnsmasq:v1.0.0
Expand Down
Loading

0 comments on commit 9d3a0a0

Please sign in to comment.