Skip to content

Commit 8f8b048

Browse files
committed
Add testing of database for assert_container_success
function Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent a7a86fd commit 8f8b048

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

test/test_container_configuration.py

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,34 @@ def test_invalid_configuration_tests(
125125
"psql_user, psql_password, psql_database, psql_admin_password",
126126
[
127127
[
128-
"-e POSTGRESQL_USER=user",
129-
"-e POSTGRESQL_PASSWORD=",
130-
"-e POSTGRESQL_DATABASE=db",
131-
"-e POSTGRESQL_ADMIN_PASSWORD=admin_pass",
128+
"user",
129+
"pass",
130+
"db",
131+
"admin_pass",
132132
],
133133
[
134-
"-e POSTGRESQL_USER=user",
135-
"-e POSTGRESQL_PASSWORD=pass",
136-
"-e POSTGRESQL_DATABASE=9invalid",
137-
"-e POSTGRESQL_ADMIN_PASSWORD=admin_pass",
134+
"user",
135+
"pass",
136+
"9invalid",
137+
"admin_pass",
138138
],
139139
[
140-
"-e POSTGRESQL_USER=user",
141-
"-e POSTGRESQL_PASSWORD=pass",
142-
"-e POSTGRESQL_DATABASE=db",
143-
"-e POSTGRESQL_ADMIN_PASSWORD=",
140+
"user",
141+
"pass",
142+
"db",
143+
"",
144144
],
145145
[
146146
"",
147147
"",
148148
"",
149-
'-e POSTGRESQL_ADMIN_PASSWORD="the @password"',
149+
'"the @password"',
150150
],
151151
[
152-
'-e POSTGRESQL_USER="the user"',
153-
'-e POSTGRESQL_PASSWORD="the pass"',
154-
'-e POSTGRESQL_DATABASE="the db"',
155-
"-e POSTGRESQL_ADMIN_PASSWORD=",
152+
'"the user"',
153+
'"the pass"',
154+
'"the db"',
155+
"",
156156
],
157157
],
158158
)
@@ -166,15 +166,52 @@ def test_correct_configuration_tests(
166166
"""
167167
Test correct configuration combinations for PostgreSQL container.
168168
"""
169+
psql_admin_password_arg = ""
170+
psql_user_arg = ""
171+
psql_password_arg = ""
172+
psql_database_arg = ""
173+
if psql_user:
174+
psql_user_arg = f"-e POSTGRESQL_USER={psql_user}"
175+
if psql_password:
176+
psql_password_arg = f"-e POSTGRESQL_PASSWORD={psql_password}"
177+
if psql_database:
178+
psql_database_arg = f"-e POSTGRESQL_DATABASE={psql_database}"
179+
if psql_admin_password:
180+
psql_admin_password_arg = (
181+
f"-e POSTGRESQL_ADMIN_PASSWORD={psql_admin_password}"
182+
)
183+
container_args = [
184+
psql_user_arg,
185+
psql_password_arg,
186+
psql_database_arg,
187+
psql_admin_password_arg,
188+
]
169189
assert self.db.assert_container_creation_succeeds(
170-
container_args=[
171-
psql_user,
172-
psql_password,
173-
psql_database,
174-
psql_admin_password,
175-
],
190+
container_args=container_args,
176191
command="",
177192
)
193+
cid_file_name = "cid_success_test"
194+
assert self.db.create_container(
195+
cid_file_name=cid_file_name,
196+
container_args=container_args,
197+
command="",
198+
)
199+
cip = self.db.get_cip(cid_file_name=cid_file_name)
200+
assert cip
201+
if psql_user and psql_password:
202+
assert self.db.test_db_connection(
203+
container_ip=cip,
204+
username=psql_user,
205+
password=psql_password,
206+
database=psql_database,
207+
)
208+
if psql_admin_password:
209+
assert self.db.test_db_connection(
210+
container_ip=cip,
211+
username="postgres",
212+
password=psql_admin_password,
213+
database=psql_database,
214+
)
178215

179216
def test_configuration_hook(self):
180217
"""

test/test_container_extensions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def test_pgaudit_extension_installation(self, env_load):
7979
docker_args=docker_args,
8080
command="",
8181
)
82-
cip = self.db.get_cip(cid_file_name=cid_file_name)
83-
assert cip
8482
cid = self.db.get_cid(cid_file_name=cid_file_name)
8583
assert cid
8684
assert self.db_api.wait_for_database(
@@ -151,8 +149,6 @@ def test_pgvector(self):
151149
docker_args=docker_args,
152150
command="",
153151
)
154-
cip = self.db.get_cip(cid_file_name=cid_file_name)
155-
assert cip
156152
cid = self.db.get_cid(cid_file_name=cid_file_name)
157153
assert cid
158154
assert self.db_api.wait_for_database(

test/test_container_logging.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def test_logging_destination(self):
4444
docker_args=docker_args,
4545
command="",
4646
)
47-
cip = self.db.get_cip(cid_file_name=cid_file_name)
48-
assert cip
4947
cid = self.db.get_cid(cid_file_name=cid_file_name)
5048
assert cid
5149
assert self.db_api.wait_for_database(

0 commit comments

Comments
 (0)