126 lines
3.6 KiB
YAML
126 lines
3.6 KiB
YAML
# 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"'
|