postgresql_idx: added CI tests for check_mode, rewrite code related with check_mode, misc fixes (#54848)

* postgresql_idx: added CI tests, misc fixes

* postgresql_idx: fix sanity
This commit is contained in:
Andrey Klychkov 2019-04-04 15:31:14 +03:00 committed by John R Barker
parent 6a10c2a5f4
commit 2fbac8948d
2 changed files with 156 additions and 25 deletions

View file

@ -59,6 +59,46 @@
# Do main tests
#
# Create index in check_mode
- name: postgresql_idx - create btree index in check_mode
become_user: "{{ pg_user }}"
become: yes
postgresql_idx:
db: postgres
login_user: "{{ pg_user }}"
table: test_table
columns: id, story
idxname: test0_idx
check_mode: yes
register: result
ignore_errors: yes
- assert:
that:
- result.changed == true
- result.tblname == ''
- result.name == 'test0_idx'
- result.state == 'absent'
- result.valid != ''
- result.tblspace == ''
- result.storage_params == []
- result.schema == ''
- result.query == ''
# Check that actually nothing changed, rowcount must be 0
- name: postgresql_idx - check nothing changed after the previous step
become_user: "{{ pg_user }}"
become: yes
postgresql_query:
db: postgres
login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'test0_idx'"
register: result
- assert:
that:
- result.rowcount == 0
# Create btree index if not exists test_idx concurrently covering id and story columns
- name: postgresql_idx - create btree index concurrently
become_user: "{{ pg_user }}"
@ -84,6 +124,20 @@
- result.schema == 'public'
- result.query == 'CREATE INDEX CONCURRENTLY test0_idx ON public.test_table USING BTREE (id, story)'
# Check that the index exists after the previous step, rowcount must be 1
- name: postgresql_idx - check the index exists after the previous step
become_user: "{{ pg_user }}"
become: yes
postgresql_query:
db: postgres
login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'test0_idx'"
register: result
- assert:
that:
- result.rowcount == 1
# Check that if index exists that changes nothing
- name: postgresql_idx - try to create existing index again
become_user: "{{ pg_user }}"
@ -198,6 +252,47 @@
- result.schema == 'public'
- result.query == 'CREATE INDEX CONCURRENTLY test1_idx ON public.test_table USING BTREE (id) WHERE id > 1 AND id != 10'
# Drop index from spacific schema with cascade in check_mode
- name: postgresql_idx - drop index from specific schema cascade in check_mode
become_user: "{{ pg_user }}"
become: yes
postgresql_idx:
db: postgres
login_user: "{{ pg_user }}"
schema: foo
name: foo_test_idx
cascade: yes
state: absent
concurrent: no
check_mode: yes
register: result
ignore_errors: yes
- assert:
that:
- result.changed == true
- result.name == 'foo_test_idx'
- result.state == 'present'
- result.schema == 'foo'
- result.query == ''
when: tablespace.rc == 0
# Check that the index exists after the previous step, rowcount must be 1
- name: postgresql_idx - check the index exists after the previous step
become_user: "{{ pg_user }}"
become: yes
postgresql_query:
db: postgres
login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx'"
register: result
when: tablespace.rc == 0
- assert:
that:
- result.rowcount == 1
when: tablespace.rc == 0
# Drop index from spacific schema with cascade
- name: postgresql_idx - drop index from specific schema cascade
become_user: "{{ pg_user }}"
@ -222,6 +317,22 @@
- result.query == 'DROP INDEX foo.foo_test_idx CASCADE'
when: tablespace.rc == 0
# Check that the index doesn't exist after the previous step, rowcount must be 0
- name: postgresql_idx - check the index doesn't exist after the previous step
become_user: "{{ pg_user }}"
become: yes
postgresql_query:
db: postgres
login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx'"
register: result
when: tablespace.rc == 0
- assert:
that:
- result.rowcount == 0
when: tablespace.rc == 0
# Try to drop not existing index
- name: postgresql_idx - try to drop not existing index
become_user: "{{ pg_user }}"