| 1 |
#################################################################### |
| 2 |
# WARNING: These are designed specifically for Ansible tests # |
| 3 |
# and should not be used as examples of how to write Ansible roles # |
| 4 |
#################################################################### |
| 5 |
|
| 6 |
# Test code for gitlab_project_members module |
| 7 |
# |
| 8 |
# Copyright (c) 2021, Sergey Mikhaltsov <[email protected]> |
| 9 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 10 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 11 |
|
| 12 |
- name: Install required library |
| 13 |
ansible.builtin.pip: |
| 14 |
name: python-gitlab |
| 15 |
state: present |
| 16 |
|
| 17 |
- name: Clean UP before tests |
| 18 |
community.general.gitlab_project_members: |
| 19 |
api_url: "{{ gitlab_server_url }}" |
| 20 |
api_token: "{{ gitlab_api_access_token }}" |
| 21 |
project: "{{ gitlab_project }}" |
| 22 |
gitlab_user: "{{ username }}" |
| 23 |
access_level: "{{ gitlab_access_level }}" |
| 24 |
state: absent |
| 25 |
|
| 26 |
- name: Add a User to A GitLab Project |
| 27 |
community.general.gitlab_project_members: |
| 28 |
api_url: "{{ gitlab_server_url }}" |
| 29 |
api_token: "{{ gitlab_api_access_token }}" |
| 30 |
project: "{{ gitlab_project }}" |
| 31 |
gitlab_user: "{{ username }}" |
| 32 |
access_level: "{{ gitlab_access_level }}" |
| 33 |
state: present |
| 34 |
register: gitlab_project_members_state |
| 35 |
|
| 36 |
- name: Test member added to project |
| 37 |
assert: |
| 38 |
that: |
| 39 |
- gitlab_project_members_state is changed |
| 40 |
|
| 41 |
- name: Add a User to A GitLab Project ( Idempotency test ) |
| 42 |
community.general.gitlab_project_members: |
| 43 |
api_url: "{{ gitlab_server_url }}" |
| 44 |
api_token: "{{ gitlab_api_access_token }}" |
| 45 |
project: "{{ gitlab_project }}" |
| 46 |
gitlab_user: "{{ username }}" |
| 47 |
access_level: "{{ gitlab_access_level }}" |
| 48 |
state: present |
| 49 |
register: gitlab_project_members_state_again |
| 50 |
|
| 51 |
- name: Test module is idempotent |
| 52 |
assert: |
| 53 |
that: |
| 54 |
- gitlab_project_members_state_again is not changed |
| 55 |
|
| 56 |
- name: Remove a User from A GitLab Project |
| 57 |
community.general.gitlab_project_members: |
| 58 |
api_url: "{{ gitlab_server_url }}" |
| 59 |
api_token: "{{ gitlab_api_access_token }}" |
| 60 |
project: "{{ gitlab_project }}" |
| 61 |
gitlab_user: "{{ username }}" |
| 62 |
access_level: "{{ gitlab_access_level }}" |
| 63 |
state: absent |
| 64 |
register: remove_gitlab_project_members_state |
| 65 |
|
| 66 |
- name: Test member removed from project |
| 67 |
assert: |
| 68 |
that: |
| 69 |
- remove_gitlab_project_members_state is changed |
| 70 |
|
| 71 |
- name: Remove a User from A GitLab Project ( Idempotency test ) |
| 72 |
community.general.gitlab_project_members: |
| 73 |
api_url: "{{ gitlab_server_url }}" |
| 74 |
api_token: "{{ gitlab_api_access_token }}" |
| 75 |
project: "{{ gitlab_project }}" |
| 76 |
gitlab_user: "{{ username }}" |
| 77 |
access_level: "{{ gitlab_access_level }}" |
| 78 |
state: absent |
| 79 |
register: remove_gitlab_project_members_state_again |
| 80 |
|
| 81 |
- name: Test module is idempotent |
| 82 |
assert: |
| 83 |
that: |
| 84 |
- remove_gitlab_project_members_state_again is not changed |
| 85 |
|
| 86 |
- name: Add a list of Users to A GitLab Project |
| 87 |
community.general.gitlab_project_members: |
| 88 |
api_url: "{{ gitlab_server_url }}" |
| 89 |
api_token: "{{ gitlab_api_access_token }}" |
| 90 |
project: "{{ gitlab_project }}" |
| 91 |
gitlab_user: "{{ userlist }}" |
| 92 |
access_level: "{{ gitlab_access_level }}" |
| 93 |
state: present |
| 94 |
|
| 95 |
- name: Remove a list of Users to A GitLab Project |
| 96 |
community.general.gitlab_project_members: |
| 97 |
api_url: "{{ gitlab_server_url }}" |
| 98 |
api_token: "{{ gitlab_api_access_token }}" |
| 99 |
project: "{{ gitlab_project }}" |
| 100 |
gitlab_user: "{{ userlist }}" |
| 101 |
access_level: "{{ gitlab_access_level }}" |
| 102 |
state: absent |
| 103 |
|
| 104 |
- name: Add a list of Users with Dedicated Access Levels to A GitLab Project |
| 105 |
community.general.gitlab_project_members: |
| 106 |
api_url: "{{ gitlab_server_url }}" |
| 107 |
api_token: "{{ gitlab_api_access_token }}" |
| 108 |
project: "{{ gitlab_project }}" |
| 109 |
gitlab_users_access: "{{ dedicated_access_users }}" |
| 110 |
state: present |
| 111 |
|
| 112 |
- name: Remove a list of Users with Dedicated Access Levels to A GitLab Project |
| 113 |
community.general.gitlab_project_members: |
| 114 |
api_url: "{{ gitlab_server_url }}" |
| 115 |
api_token: "{{ gitlab_api_access_token }}" |
| 116 |
project: "{{ gitlab_project }}" |
| 117 |
gitlab_users_access: "{{ dedicated_access_users }}" |
| 118 |
state: absent |
| 119 |
|
| 120 |
- name: Add a user, remove all others which might be on this access level |
| 121 |
community.general.gitlab_project_members: |
| 122 |
api_url: "{{ gitlab_server_url }}" |
| 123 |
api_token: "{{ gitlab_api_access_token }}" |
| 124 |
project: "{{ gitlab_project }}" |
| 125 |
gitlab_user: "{{ username }}" |
| 126 |
access_level: "{{ gitlab_access_level }}" |
| 127 |
purge_users: "{{ gitlab_access_level }}" |
| 128 |
state: present |