11"""Integration tests for Docker services."""
22
3- import pytest
4- import time
53import socket
6- import subprocess
7- import requests
8- from pathlib import Path
4+ import time
5+
96import docker
10- import os
7+ import pytest
8+ import requests
119
1210
1311class TestDockerServices :
@@ -57,9 +55,7 @@ def running_services(self, docker_client, project_root):
5755 """Ensure Docker services are running for integration tests."""
5856 # Check if services are already running
5957 try :
60- containers = docker_client .containers .list (
61- filters = {"label" : "com.docker.compose.project=irc.atl.chat" }
62- )
58+ containers = docker_client .containers .list (filters = {"label" : "com.docker.compose.project=irc.atl.chat" })
6359
6460 if not containers :
6561 pytest .skip ("Docker services not running. Run 'make up' first." )
@@ -81,18 +77,14 @@ def test_unrealircd_container_running(self, running_services):
8177 unrealircd_container = container
8278 break
8379
84- assert unrealircd_container is not None , (
85- "UnrealIRCd container should be running"
86- )
80+ assert unrealircd_container is not None , "UnrealIRCd container should be running"
8781 assert unrealircd_container .status == "running" , "UnrealIRCd should be running"
8882
8983 # Check health status if available
9084 container_info = unrealircd_container .attrs
9185 health = container_info .get ("State" , {}).get ("Health" , {}).get ("Status" )
9286 if health :
93- assert health in ["healthy" , "starting" ], (
94- f"UnrealIRCd health status: { health } "
95- )
87+ assert health in ["healthy" , "starting" ], f"UnrealIRCd health status: { health } "
9688
9789 @pytest .mark .integration
9890 @pytest .mark .docker
@@ -125,15 +117,15 @@ def test_webpanel_container_running(self, running_services):
125117 @pytest .mark .slow
126118 def test_irc_ports_open (self , running_services ):
127119 """Test that IRC ports are open and accepting connections."""
128- ports_to_test = [6667 , 6697 ] # Standard IRC and SSL ports
120+ ports_to_test = [6697 ] # TLS only
129121
130122 for port in ports_to_test :
131123 with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as sock :
132124 sock .settimeout (5 )
133125 try :
134126 result = sock .connect_ex (("localhost" , port ))
135127 assert result == 0 , f"Port { port } should be open"
136- except socket . error :
128+ except OSError :
137129 pytest .fail (f"Could not connect to port { port } " )
138130
139131 @pytest .mark .integration
@@ -165,9 +157,7 @@ def test_container_logs_accessible(self, running_services):
165157 for container in running_services :
166158 try :
167159 logs = container .logs (tail = 10 )
168- assert logs is not None , (
169- f"Logs should be accessible for { container .name } "
170- )
160+ assert logs is not None , f"Logs should be accessible for { container .name } "
171161 except docker .errors .DockerException :
172162 pytest .fail (f"Could not access logs for { container .name } " )
173163
@@ -188,9 +178,7 @@ def test_service_dependencies(self, running_services):
188178
189179 if unrealircd_start and atheme_start :
190180 # Atheme should start after UnrealIRCd
191- assert atheme_start > unrealircd_start , (
192- "Atheme should start after UnrealIRCd"
193- )
181+ assert atheme_start > unrealircd_start , "Atheme should start after UnrealIRCd"
194182
195183 @pytest .mark .integration
196184 @pytest .mark .docker
@@ -202,9 +190,7 @@ def test_container_resource_limits(self, running_services):
202190 # Check if memory limits are set (optional but good practice)
203191 memory_limit = config .get ("Memory" )
204192 if memory_limit :
205- assert memory_limit > 0 , (
206- f"Container { container .name } should have memory limit"
207- )
193+ assert memory_limit > 0 , f"Container { container .name } should have memory limit"
208194
209195 @pytest .mark .integration
210196 @pytest .mark .docker
@@ -215,7 +201,7 @@ def test_environment_variables_passed(self, running_services, project_root):
215201 if env_file .exists ():
216202 # Read expected variables
217203 expected_vars = {}
218- with open (env_file , "r" ) as f :
204+ with open (env_file ) as f :
219205 for line in f :
220206 line = line .strip ()
221207 if line and not line .startswith ("#" ) and "=" in line :
@@ -234,24 +220,18 @@ def test_environment_variables_passed(self, running_services, project_root):
234220
235221 # Check some key variables are present
236222 for var in ["TZ" , "PUID" , "PGID" ]:
237- assert var in env_dict , (
238- f"Environment variable { var } should be set"
239- )
223+ assert var in env_dict , f"Environment variable { var } should be set"
240224
241225 @pytest .mark .integration
242226 @pytest .mark .docker
243227 @pytest .mark .slow
244228 def test_container_restart_policy (self , running_services ):
245229 """Test that containers have appropriate restart policies."""
246230 for container in running_services :
247- restart_policy = container .attrs .get ("HostConfig" , {}).get (
248- "RestartPolicy" , {}
249- )
231+ restart_policy = container .attrs .get ("HostConfig" , {}).get ("RestartPolicy" , {})
250232
251233 # Most services should have unless-stopped policy
252- if (
253- "ssl-monitor" not in container .name
254- ): # SSL monitor might have different policy
234+ if "ssl-monitor" not in container .name : # SSL monitor might have different policy
255235 assert restart_policy .get ("Name" ) in ["unless-stopped" , "always" ], (
256236 f"Container { container .name } should have restart policy"
257237 )
0 commit comments