1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adds integration tests for gce_pd module.

This commit is contained in:
Chris Conway 2014-03-30 14:49:55 -07:00
parent 2cc4a372c5
commit 1e76fe2569
4 changed files with 136 additions and 1 deletions

View file

@ -98,5 +98,7 @@ if __name__ == '__main__':
try:
# Delete matching instances
delete_gce_resources(gce.list_nodes, 'name', opts)
# Delete matching disks
delete_gce_resources(gce.list_volumes, 'name', opts)
except KeyboardInterrupt, e:
print "\nExiting on user command."

View file

@ -2,4 +2,5 @@
gather_facts: true
roles:
- { role: test_gce, tags: test_gce }
# TODO: tests for gce_net, gce_pd, etc.
- { role: test_gce_pd, tags: test_gce_pd }
# TODO: tests for gce_lb, gce_net, gc_storage

View file

@ -0,0 +1,6 @@
---
# defaults file for test_gce
instance_name: "{{ resource_prefix|lower }}"
service_account_email: "{{ gce_service_account_email }}"
pem_file: "{{ gce_pem_file }}"
project_id: "{{ gce_project_id }}"

View file

@ -0,0 +1,126 @@
# TODO: need tests for read/write mode.
# ============================================================
- name: test missing name
gce_pd:
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
register: result
ignore_errors: true
- name: assert failure when called with no parameters
assert:
that:
- 'result.failed'
- 'result.msg == "missing required arguments: name"'
# ============================================================
- name: test state=present (expected changed=true)
gce_pd:
name: "{{ instance_name }}"
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: present
register: result
- name: assert state=present (expected changed=true)
assert:
that:
- 'result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.size_gb == 10' # default size
- 'result.zone == "us-central1-b"' # default zone
- 'result.state == "present"'
# ============================================================
- name: test state=present (expected changed=false)
gce_pd:
name: "{{ instance_name }}"
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: present
register: result
- name: assert state=present (expected changed=false)
assert:
that:
- 'not result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.state == "present"'
# ============================================================
- name: test state=absent (expected changed=true)
gce_pd:
name: "{{ instance_name }}"
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: absent
register: result
- name: assert state=absent (expected changed=true)
assert:
that:
- 'result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.state == "absent"'
# ============================================================
- name: test state=absent (expected changed=false)
gce_pd:
name: "{{ instance_name }}"
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: absent
register: result
- name: assert state=absent (expected changed=false)
assert:
that:
- 'not result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.state == "absent"'
# ============================================================
- name: test non-default size/zone
gce_pd:
name: "{{ instance_name }}"
size_gb: 5
zone: us-central1-a
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: present
register: result
- name: assert non-default size/zone
assert:
that:
- 'result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.size_gb == 5'
- 'result.zone == "us-central1-a"'
- 'result.state == "present"'
# ============================================================
- name: test non-default size/zone (state=absent)
gce_pd:
name: "{{ instance_name }}"
size_gb: 5
zone: us-central1-a
service_account_email: "{{ service_account_email }}"
pem_file: "{{ pem_file }}"
project_id: "{{ project_id }}"
state: absent
register: result
- name: assert non-default size/zone (state=absent)
assert:
that:
- 'result.changed'
- 'result.name == "{{ instance_name }}"'
- 'result.state == "absent"'