# Unsorted tests that were moved from here to unsorted.yml
- import_tasks: unsorted.yml

# Test ssl.
# Restricted using Debian family because of there are errors on other distributions
# that not related with PostgreSQL or psycopg2 SSL support.
# The tests' key point is to be sure that ssl options work in general
- import_tasks: ssl.yml
  when:
  - ansible_os_family == 'Debian'
  - postgres_version_resp.stdout is version('9.4', '>=')

# Test postgresql_publication
- import_tasks: postgresql_publication.yml
  when: postgres_version_resp.stdout is version('10', '>=')

- include_tasks: '{{ loop_item }}'
  loop:
  # Test postgresql_set
  - postgresql_set.yml

  # Test postgresql_copy module
  - postgresql_copy.yml

  # Test postgresql_slot module.
  # Physical replication slots are available from PostgreSQL 9.4
  - postgresql_slot.yml
  loop_control:
    loop_var: loop_item
  when: postgres_version_resp.stdout is version('9.4', '>=')

- include_tasks: '{{ loop_item }}'
  loop:
  # Test postgresql_user module
  - postgresql_user.yml

  # Verify different session_role scenarios
  - session_role.yml

  # Test postgresql_idx module
  - postgresql_idx.yml

  # Test postgresql_query module
  - postgresql_query.yml

  # Test postgresql_tablespace module
  - postgresql_tablespace.yml

  # Test postgresql_db module, specific options
  - postgresql_db.yml

  # Test postgresql_privs
  - postgresql_privs.yml

  # Test postgresql_info module
  - postgresql_info.yml

  # Test postgresql_schema module
  - postgresql_schema.yml

  # Test postgresql_membership module
  - postgresql_membership.yml

  # Test postgresql_table module
  - postgresql_table.yml

  # Test postgresql_owner module
  - postgresql_owner.yml

  # Test postgres_pg_hba module
  - postgresql_pg_hba.yml
  loop_control:
    loop_var: loop_item

# Test postgresql_ping module
- import_tasks: postgresql_ping.yml
  vars:
    db_name_nonexist: fake_db

# Test default_privs with target_role
- import_tasks: test_target_role.yml
  when: postgres_version_resp.stdout is version('9.1', '>=')

# Test postgresql_sequence module
- import_tasks: postgresql_sequence.yml
  when: postgres_version_resp.stdout is version('9.0', '>=')

# Test postgresql_ext.
# pg_extension system view is available from PG 9.1.
# The tests are restricted by Fedora because there will be errors related with
# attempts to change the environment during postgis installation or
# missing postgis package in repositories.
# Anyway, these tests completely depend on Postgres version,
# not specific distributions.
- import_tasks: postgresql_ext.yml
  when:
  - postgres_version_resp.stdout is version('9.1', '>=')
  - ansible_distribution == 'Fedora'

- import_tasks: postgresql_ext_version_opt.yml
  when: ansible_distribution == 'Ubuntu'

# Test postgresql_lang module.
# To implement tests, it needs to install some additional packages
# that may cause problems on different distributions,
# so I restricted the tests using CentOS because the results
# depend only on Postgres version
# (CentOS 6 repo contains the oldest PG version in these tests - 9.0):
- import_tasks: postgresql_lang.yml
  when:
  - ansible_distribution == 'CentOS'
  - postgres_version_resp.stdout is version('9.4', '>=')

# dump/restore tests per format
# ============================================================
- include_tasks: state_dump_restore.yml
  vars:
    test_fixture: user
    file: '{{ loop_item }}'
  loop:
  - dbdata.sql
  - dbdata.sql.gz
  - dbdata.sql.bz2
  - dbdata.sql.xz
  - dbdata.tar
  - dbdata.tar.gz
  - dbdata.tar.bz2
  - dbdata.tar.xz
  loop_control:
    loop_var: loop_item

# dump/restore tests per other logins
# ============================================================
- import_tasks: state_dump_restore.yml
  vars:
    file: dbdata.tar
    test_fixture: admin
