ansible-role-postgresql/molecule/default/tests/test_default.py

49 lines
1.4 KiB
Python
Raw Normal View History

2021-09-10 12:09:38 +00:00
import testinfra.utils.ansible_runner
def test_packages(host):
2023-08-28 12:55:55 +00:00
for package_name in ['postgresql-15', 'python3-psycopg2']:
2021-09-10 12:09:38 +00:00
package = host.package(package_name)
assert package.is_installed
def test_config_file(host):
2023-08-28 12:55:55 +00:00
path = host.file('/etc/postgresql/15/main/postgresql.conf')
2021-09-10 12:09:38 +00:00
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains("listen_addresses = '*'")
def test_hba_file(host):
2023-08-28 12:55:55 +00:00
path = host.file('/etc/postgresql/15/main/pg_hba.conf')
2021-09-10 12:09:38 +00:00
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('local "myappli","myappli2" all md5')
2021-09-10 12:09:38 +00:00
def test_service(host):
2023-08-28 12:55:55 +00:00
service = host.service('postgresql@15-main')
2021-09-10 12:09:38 +00:00
assert service.is_running
assert service.is_enabled
def test_socket(host):
socket = host.socket('tcp://127.0.0.1:5432')
assert socket.is_listening
def test_database(host):
cmd = host.run('su - postgres -c "psql -c \'\\l\'"')
assert cmd.succeeded
assert 'myappli' in cmd.stdout
2021-09-10 12:09:38 +00:00
def test_user(host):
cmd = host.run('su - postgres -c "psql -c \'\\du\'"')
assert cmd.succeeded
assert 'myuser' in cmd.stdout
def test_grants(host):
cmd = host.run('PGPASSWORD=secret psql -U myuser -d myappli -c \'create table test ( col text);\'')
assert cmd.succeeded
assert 'CREATE TABLE' in cmd.stdout