From 6a3e948a7c5a2f8c3c5c0445f2d5de7aedc0b817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Tue, 13 Sep 2016 16:03:58 +0200 Subject: [PATCH] jenkins_job: add integration tests (#17499) --- test/integration/Makefile | 5 + test/integration/jenkins.yml | 8 + .../roles/test_jenkins_job/defaults/main.yml | 5 + .../roles/test_jenkins_job/tasks/main.yml | 157 ++++++++++++++++++ .../test_jenkins_job/templates/config.xml.j2 | 29 ++++ 5 files changed, 204 insertions(+) create mode 100644 test/integration/jenkins.yml create mode 100644 test/integration/roles/test_jenkins_job/defaults/main.yml create mode 100644 test/integration/roles/test_jenkins_job/tasks/main.yml create mode 100644 test/integration/roles/test_jenkins_job/templates/config.xml.j2 diff --git a/test/integration/Makefile b/test/integration/Makefile index b735331037..857b70e1a0 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -272,6 +272,11 @@ exoscale: RC=$$? ; \ exit $$RC; +jenkins: + ansible-playbook jenkins.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS) ; \ + RC=$$? ; \ + exit $$RC; + cloudflare: $(CREDENTIALS_FILE) ansible-playbook cloudflare.yml -i $(INVENTORY) -e @$(VARS_FILE) -e @$(CREDENTIALS_FILE) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \ RC=$$? ; \ diff --git a/test/integration/jenkins.yml b/test/integration/jenkins.yml new file mode 100644 index 0000000000..a20e4bdc2b --- /dev/null +++ b/test/integration/jenkins.yml @@ -0,0 +1,8 @@ +--- +- hosts: localhost + connection: local + gather_facts: no + tags: + - jenkins + roles: + - test_jenkins_job diff --git a/test/integration/roles/test_jenkins_job/defaults/main.yml b/test/integration/roles/test_jenkins_job/defaults/main.yml new file mode 100644 index 0000000000..ab05bc3096 --- /dev/null +++ b/test/integration/roles/test_jenkins_job/defaults/main.yml @@ -0,0 +1,5 @@ +--- +jenkins_url: http://localhost:8080 +jenkins_user: admin +jenkins_password: "" +jenkins_days_to_keep: 20 diff --git a/test/integration/roles/test_jenkins_job/tasks/main.yml b/test/integration/roles/test_jenkins_job/tasks/main.yml new file mode 100644 index 0000000000..21962d8007 --- /dev/null +++ b/test/integration/roles/test_jenkins_job/tasks/main.yml @@ -0,0 +1,157 @@ +--- +- name: setup + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + state: absent + register: result +- name: verify setup + assert: + that: + - result|success + +- name: test create a job + local_action: + module: jenkins_job + config: "{{ lookup('template', 'config.xml.j2') }}" + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + register: result +- name: verify test create a job + assert: + that: + - result|success + - result|changed + - result.enabled + +- name: test create a job idempotence + local_action: + module: jenkins_job + config: "{{ lookup('template', 'config.xml.j2') }}" + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + register: result +- name: verify test create a job idempotence + assert: + that: + - result|success + - not result|changed + - result.enabled + +- name: test create a enabled job idempotence + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + enabled: true + register: result +- name: verify test create a enabled job idempotence + assert: + that: + - result|success + - not result|changed + - result.enabled + +- name: test update a job + local_action: + module: jenkins_job + config: "{{ lookup('template', 'config.xml.j2') }}" + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + register: result + vars: + jenkins_days_to_keep: 10 +- name: verify test create a enabled job idempotence + assert: + that: + - result|success + - result|changed + - result.enabled + +- name: test disable an exising job without config + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + enabled: false + register: result +- name: verify test disable an exising job without config + assert: + that: + - result|success + - result|changed + - not result.enabled + +- name: test disable an exising job without config idempotence + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + enabled: false + register: result +- name: verify test disable an exising job without config idempotence + assert: + that: + - result|success + - not result|changed + - not result.enabled + +- name: test reset to config job + local_action: + module: jenkins_job + config: "{{ lookup('template', 'config.xml.j2') }}" + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + register: result +- name: verify test reset to config job + assert: + that: + - result|success + - result|changed + +- name: test remove job + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + state: absent + register: result +- name: verify test remove job + assert: + that: + - result|success + - result|changed + +- name: test remove job idempotence + local_action: + module: jenkins_job + name: test.job + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_password }}" + state: absent + register: result +- name: verify test remove job idempotence + assert: + that: + - result|success + - not result|changed diff --git a/test/integration/roles/test_jenkins_job/templates/config.xml.j2 b/test/integration/roles/test_jenkins_job/templates/config.xml.j2 new file mode 100644 index 0000000000..c7249198b8 --- /dev/null +++ b/test/integration/roles/test_jenkins_job/templates/config.xml.j2 @@ -0,0 +1,29 @@ + + + + + false + + + + {{ jenkins_days_to_keep }} + 20 + -1 + -1 + + + + false + + + + true + false + false + false + + false + + + +