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:
parent
2cc4a372c5
commit
1e76fe2569
4 changed files with 136 additions and 1 deletions
|
@ -98,5 +98,7 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
# Delete matching instances
|
# Delete matching instances
|
||||||
delete_gce_resources(gce.list_nodes, 'name', opts)
|
delete_gce_resources(gce.list_nodes, 'name', opts)
|
||||||
|
# Delete matching disks
|
||||||
|
delete_gce_resources(gce.list_volumes, 'name', opts)
|
||||||
except KeyboardInterrupt, e:
|
except KeyboardInterrupt, e:
|
||||||
print "\nExiting on user command."
|
print "\nExiting on user command."
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
roles:
|
roles:
|
||||||
- { role: test_gce, tags: test_gce }
|
- { 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
|
||||||
|
|
6
test/integration/roles/test_gce_pd/defaults/main.yml
Normal file
6
test/integration/roles/test_gce_pd/defaults/main.yml
Normal 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 }}"
|
126
test/integration/roles/test_gce_pd/tasks/main.yml
Normal file
126
test/integration/roles/test_gce_pd/tasks/main.yml
Normal 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"'
|
Loading…
Reference in a new issue