Skip to content

Commit

Permalink
Base integration test for gitlab modules (ansible#51490)
Browse files Browse the repository at this point in the history
* Added basic integration test targets for gitlab modules

* Removed cloud/gitlab config from aliases, it doesn't exist yet

* Fixed CI issues
  • Loading branch information
Shaps authored and gundalow committed Jan 31, 2019
1 parent 6a2aac4 commit 042aeba
Show file tree
Hide file tree
Showing 19 changed files with 353 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/integration/cloud-config-gitlab.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is the configuration template for ansible-test Gitlab integration tests.
#
# You do not need this template if you are:
#
# 1) Running integration tests without using ansible-test.
# 2) Using the automatically provisioned gitlab docker container in ansible-test.
#
# If you do not want to use the automatically provided Gitlab container,
# fill in the @VAR placeholders below and save this file without the .template extension.
# This will cause ansible-test to use the given configuration and not launch the simulator.
#
# It is recommended that you DO NOT use this template unless you cannot use the simulator.

gitlab_host: http://@HOST:@PORT
gitlab_login_token: @TOKEN
gitlab_runner_registration_token: @RUNNER_TOKEN
timeout: 60
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_deploy_key/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
2 changes: 2 additions & 0 deletions test/integration/targets/gitlab_deploy_key/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gitlab_project_name: ansible_test_project
gitlab_deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJnTYY7CYk1F/wBklpdRxudxN6KeXgfhutkiCigSfPhe ansible_test"
36 changes: 36 additions & 0 deletions test/integration/targets/gitlab_deploy_key/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Create {{ gitlab_project_name }}
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: present

- name: Cleanup deploy key to {{ gitlab_project_name }}
gitlab_deploy_key:
login_token: "{{ gitlab_login_token }}"
project: "{{ gitlab_project_name }}"
server_url: "{{ gitlab_host }}"
title: "{{ gitlab_project_name }}"
key: "{{ gitlab_deploy_key }}"
state: absent


- name: Add deploy key to {{ gitlab_project_name }}
gitlab_deploy_key:
login_token: "{{ gitlab_login_token }}"
project: "root/{{ gitlab_project_name }}"
server_url: "{{ gitlab_host }}"
title: "{{ gitlab_project_name }}"
key: "{{ gitlab_deploy_key }}"
state: present
register: deploy_key_status

- assert:
that:
- deploy_key_status is changed
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_group/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
1 change: 1 addition & 0 deletions test/integration/targets/gitlab_group/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gitlab_group: ansible_test_project
44 changes: 44 additions & 0 deletions test/integration/targets/gitlab_group/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Cleanup Gitlab Group
gitlab_group:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
name: ansible_test_group
path: ansible_test_group
state: absent

- name: Create Gitlab Group
gitlab_group:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
name: ansible_test_group
path: ansible_test_group
state: present
register: gitlab_group_state

- name: Test group created
assert:
that:
- gitlab_group_state is changed


- name: Create Gitlab Group ( Idempotency test )
gitlab_group:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
name: ansible_test_group
path: ansible_test_group
state: present
register: gitlab_group_state_again

- name: Test module is idempotent
assert:
that:
- gitlab_group_state_again is not changed
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_hooks/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
2 changes: 2 additions & 0 deletions test/integration/targets/gitlab_hooks/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gitlab_project_name: ansible_test_project
gitlab_hook_url: http://gitlab.example.com/hook
67 changes: 67 additions & 0 deletions test/integration/targets/gitlab_hooks/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Create {{ gitlab_project_name }}
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: present

- name: Cleanup Gitlab hook
gitlab_hooks:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
hook_url: "{{ gitlab_hook_url }}"
project: "{{ gitlab_project_name }}"
state: absent

- name: Create Gitlab Hook
gitlab_hooks:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
hook_url: "{{ gitlab_hook_url }}"
project: "{{ gitlab_project_name }}"
state: present
register: gitlab_hook_state

- name: Test group created
assert:
that:
- gitlab_hook_state is changed


- name: Create Gitlab Hook ( Idempotency test )
gitlab_hooks:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
hook_url: "{{ gitlab_hook_url }}"
project: "{{ gitlab_project_name }}"
state: present
register: gitlab_hook_state_again

- name: Test module is idempotent
assert:
that:
- gitlab_hook_state_again is not changed

- name: Remove Gitlab hook
gitlab_hooks:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
hook_url: "{{ gitlab_hook_url }}"
project: "{{ gitlab_project_name }}"
state: absent
register: gitlab_hook_state_absent

- name: Assert hook has been removed
assert:
that:
- gitlab_hook_state_absent is changed
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_project/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
2 changes: 2 additions & 0 deletions test/integration/targets/gitlab_project/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gitlab_project_name: ansible_test_project
gitlab_deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJnTYY7CYk1F/wBklpdRxudxN6KeXgfhutkiCigSfPhe ansible_test"
40 changes: 40 additions & 0 deletions test/integration/targets/gitlab_project/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Clean up {{ gitlab_project_name }}
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: absent

- name: Create {{ gitlab_project_name }}
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: present
register: gitlab_project_state


- assert:
that:
- gitlab_project_state is changed

- name: Create {{ gitlab_project_name }} (Test idempotency)
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: present
register: gitlab_project_state_again


- assert:
that:
- gitlab_project_state_again is not changed
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_runner/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_runner/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gitlab_project_name: ansible_test_project
gitlab_hook_url: http://gitlab.example.com/hook
gitlab_runner_name: ansible_test_runner
68 changes: 68 additions & 0 deletions test/integration/targets/gitlab_runner/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Create {{ gitlab_project_name }}
gitlab_project:
server_url: "{{ gitlab_host }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
name: "{{ gitlab_project_name }}"
state: present

- name: Cleanup Gitlab runner
gitlab_runner:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
description: "{{ gitlab_runner_name }}"
registration_token: "{{ gitlab_runner_registration_token }}"
state: absent

- name: Create Gitlab Runner
gitlab_runner:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
description: "{{ gitlab_runner_name }}"
registration_token: "{{ gitlab_runner_registration_token }}"
state: present
register: gitlab_runner_state

- name: Test group created
assert:
that:
- gitlab_runner_state is changed


#### COMMENTED AS MODULE WILL UPDATE THE RUNNER IF EXISTS. TO BE DISCUSSED ####
# - name: Create Gitlab Runner ( Idempotency test )
# gitlab_runner:
# server_url: "{{ gitlab_host }}"
# validate_certs: false
# login_token: "{{ gitlab_login_token }}"
# description: "{{ gitlab_runner_name }}"
# registration_token: "{{ gitlab_runner_registration_token }}"
# state: present
# register: gitlab_runner_state_again

# - name: Test module is idempotent
# assert:
# that:
# - gitlab_runner_state_again is not changed

- name: Remove Gitlab Runner
gitlab_runner:
server_url: "{{ gitlab_host }}"
validate_certs: false
login_token: "{{ gitlab_login_token }}"
description: "{{ gitlab_runner_name }}"
registration_token: "{{ gitlab_runner_registration_token }}"
state: absent
register: gitlab_runner_state_absent

- name: Assert runner has been removed
assert:
that:
- gitlab_runner_state_absent is changed
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_user/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
shippable/posix/group1
gitlab/ci
disabled
3 changes: 3 additions & 0 deletions test/integration/targets/gitlab_user/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gitlab_user: ansible_test_user
gitlab_user_pass: Secr3tPassw00rd
gitlab_user_email: root@localhost
50 changes: 50 additions & 0 deletions test/integration/targets/gitlab_user/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- name: Install required libs
pip:
name: python-gitlab
state: present

- name: Clean up gitlab user
gitlab_user:
server_url: "{{ gitlab_host }}"
name: ansible_test_user
username: ansible_test_user
password: Secr3tPassw00rd
email: root@localhost
validate_certs: false
login_token: "{{ gitlab_login_token }}"
state: absent


- name: Create gitlab user
gitlab_user:
server_url: "{{ gitlab_host }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: False
login_token: "{{ gitlab_login_token }}"
state: present
register: gitlab_user_state

- name: Check user has been created correctly
assert:
that:
- gitlab_user_state is changed

- name: Create gitlab user again
gitlab_user:
server_url: "{{ gitlab_host }}"
email: root@localhost
name: ansible_test_user
username: ansible_test_user
password: Secr3tPassw00rd
validate_certs: False
login_token: "{{ gitlab_login_token }}"
state: present
register: gitlab_user_state_again

- name: Check state is not changed
assert:
that:
- gitlab_user_state_again is not changed

0 comments on commit 042aeba

Please sign in to comment.