Skip to content

Commit

Permalink
Integration tests for quay_repository_prune
Browse files Browse the repository at this point in the history
  • Loading branch information
Hervé Quatremain committed Nov 22, 2024
1 parent 2f71a64 commit 92cc2c5
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/modules/quay_repository_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def main():
if append and policy_details:
module.exit_json(changed=False, id=policy_details.get("uuid"))

if not policies:
module.fail_json(
msg="The {repo} repository does not exist.".format(repo=full_repo_name)
)

# Remove all the auto-pruning policies, except the one that the user
# specifies
if not append:
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/targets/quay_registry_prune/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies:
- setup_organization
...
235 changes: 235 additions & 0 deletions tests/integration/targets/quay_registry_prune/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
# Supporting repository
- name: Ensure repository ansibletestrepo exists
infra.quay_configuration.quay_repository:
name: ansibletestorg/ansibletestrepo
visibility: private
state: present
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: ERROR EXPECTED Non-existing namespace
infra.quay_configuration.quay_repository_prune:
repository: nonexisting/ansibletestrepo
method: tags
value: 5
tag_pattern: "unstable"
tag_pattern_matches: true
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 Wrong number of tags
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: wrong
tag_pattern: "unstable"
tag_pattern_matches: true
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 (wrong number of tags)

- name: ERROR EXPECTED Wrong date
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: date
value: wrong
tag_pattern: "unstable"
tag_pattern_matches: true
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 (wrong date)

- name: Ensure a policy does not exist in a non-existing repository (no change)
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/nonexisting
method: tags
value: 5
tag_pattern: "unstable"
tag_pattern_matches: true
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
state: absent
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: Ensure a tag auto-pruning policy exists
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 5
tag_pattern: "unstable"
tag_pattern_matches: false
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure a tag auto-pruning policy exists (no change)
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 5
tag_pattern: "unstable"
tag_pattern_matches: false
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: Ensure a date auto-pruning policy exists 1
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: date
value: 5d
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure a date auto-pruning policy exists 2
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: date
value: 6w
tag_pattern: "nightly"
tag_pattern_matches: true
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure non-existing policy is removed (no change)
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: date
value: 42w
tag_pattern: "nightly"
tag_pattern_matches: false
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: Ensure a tag auto-pruning policy is removed
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 5
tag_pattern: "unstable"
tag_pattern_matches: false
state: absent
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure only one tag auto-pruning policy exists
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 50
tag_pattern: "foobar"
tag_pattern_matches: true
append: false
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure only one tag auto-pruning policy exists (no change)
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 50
tag_pattern: "foobar"
tag_pattern_matches: true
append: false
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: Ensure a date auto-pruning policy exists
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: date
value: 42w
tag_pattern: "nightly"
tag_pattern_matches: false
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure only one tag auto-pruning policy is set
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 50
tag_pattern: "foobar"
tag_pattern_matches: true
append: false
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false

- name: Ensure the tag auto-pruning policy is removed
infra.quay_configuration.quay_repository_prune:
repository: ansibletestorg/ansibletestrepo
method: tags
value: 50
tag_pattern: "foobar"
tag_pattern_matches: true
append: false
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
state: absent

- name: Ensure the repository is removed
infra.quay_configuration.quay_repository:
name: ansibletestorg/ansibletestrepo
state: absent
quay_host: "{{ quay_url }}"
quay_token: "{{ quay_token }}"
validate_certs: false
...

0 comments on commit 92cc2c5

Please sign in to comment.