11"""
2- Integration tests for Docker setup .
2+ Integration tests for Docker image build .
33
4- These tests verify that the Docker container works correctly and can
5- communicate with Meilisearch.
4+ These tests verify that the Docker image can be built successfully.
65"""
7- import os
86import subprocess
9- import time
107import pytest
11- import requests
128import shutil
139
1410
@@ -17,9 +13,6 @@ def docker_available():
1713 """Check if Docker is available on the system."""
1814 if not shutil .which ("docker" ):
1915 return False
20- # Also check if docker-compose.yml exists
21- if not os .path .exists ("docker-compose.yml" ):
22- return False
2316 # Try to run docker version to ensure it's working
2417 try :
2518 result = subprocess .run (
@@ -36,41 +29,10 @@ def docker_available():
3629# Skip all tests in this module if Docker is not available
3730pytestmark = pytest .mark .skipif (
3831 not docker_available (),
39- reason = "Docker not available on this system or docker-compose.yml not found "
32+ reason = "Docker not available on this system"
4033)
4134
4235
43- def wait_for_service (url , timeout = 30 ):
44- """Wait for a service to become available."""
45- start_time = time .time ()
46- while time .time () - start_time < timeout :
47- try :
48- response = requests .get (f"{ url } /health" )
49- if response .status_code == 200 :
50- return True
51- except requests .exceptions .ConnectionError :
52- pass
53- time .sleep (1 )
54- return False
55-
56-
57- @pytest .fixture (scope = "module" )
58- def docker_services ():
59- """Start Docker services for testing."""
60- # Start services
61- subprocess .run (["docker" , "compose" , "up" , "-d" ], check = True )
62-
63- # Wait for Meilisearch to be ready
64- if not wait_for_service ("http://localhost:7700" ):
65- subprocess .run (["docker" , "compose" , "down" ], check = True )
66- pytest .fail ("Meilisearch failed to start" )
67-
68- yield
69-
70- # Cleanup
71- subprocess .run (["docker" , "compose" , "down" , "-v" ], check = True )
72-
73-
7436def test_docker_build ():
7537 """Test that the Docker image can be built successfully."""
7638 result = subprocess .run (
@@ -81,69 +43,33 @@ def test_docker_build():
8143 assert result .returncode == 0 , f"Docker build failed: { result .stderr } "
8244
8345
84- def test_meilisearch_connectivity (docker_services ):
85- """Test that the MCP container can connect to Meilisearch."""
86- # Run a simple connectivity test in the container
87- result = subprocess .run (
88- [
89- "docker" , "compose" , "run" , "--rm" , "meilisearch-mcp" ,
90- "python" , "-c" ,
91- """
92- import os
93- from meilisearch import Client
94- client = Client(os.getenv('MEILI_HTTP_ADDR'), os.getenv('MEILI_MASTER_KEY'))
95- health = client.health()
96- assert health['status'] == 'available'
97- print('SUCCESS: Connected to Meilisearch')
98- """
99- ],
100- capture_output = True ,
101- text = True
102- )
103-
104- assert result .returncode == 0 , f"Connectivity test failed: { result .stderr } "
105- assert "SUCCESS: Connected to Meilisearch" in result .stdout
106-
107-
108- def test_mcp_server_import (docker_services ):
109- """Test that the MCP server module can be imported in the container."""
110- result = subprocess .run (
111- [
112- "docker" , "compose" , "run" , "--rm" , "meilisearch-mcp" ,
113- "python" , "-c" ,
114- """
115- import src.meilisearch_mcp
116- from src.meilisearch_mcp.server import MeilisearchMCPServer
117- print('SUCCESS: MCP server imported')
118- """
119- ],
46+ def test_docker_image_runs ():
47+ """Test that the Docker image can run and show help."""
48+ # First build the image
49+ build_result = subprocess .run (
50+ ["docker" , "build" , "-t" , "meilisearch-mcp-test" , "." ],
12051 capture_output = True ,
12152 text = True
12253 )
54+ if build_result .returncode != 0 :
55+ pytest .skip (f"Docker build failed: { build_result .stderr } " )
12356
124- assert result .returncode == 0 , f"Import test failed: { result .stderr } "
125- assert "SUCCESS: MCP server imported" in result .stdout
126-
127-
128- def test_environment_variables (docker_services ):
129- """Test that environment variables are correctly set in the container."""
57+ # Try to run the container and check it starts
13058 result = subprocess .run (
13159 [
132- "docker" , "compose" , "run" , "--rm" , "meilisearch-mcp" ,
133- "python" , "-c" ,
134- """
135- import os
136- assert os.getenv('MEILI_HTTP_ADDR') == 'http://meilisearch:7700'
137- assert os.getenv('MEILI_MASTER_KEY') == 'masterKey'
138- print('SUCCESS: Environment variables are correct')
139- """
60+ "docker" , "run" , "--rm" ,
61+ "-e" , "MEILI_HTTP_ADDR=http://localhost:7700" ,
62+ "-e" , "MEILI_MASTER_KEY=test" ,
63+ "meilisearch-mcp-test" ,
64+ "python" , "-c" , "import src.meilisearch_mcp; print('MCP module loaded successfully')"
14065 ],
14166 capture_output = True ,
142- text = True
67+ text = True ,
68+ timeout = 30
14369 )
14470
145- assert result .returncode == 0 , f"Environment test failed: { result .stderr } "
146- assert "SUCCESS: Environment variables are correct " in result .stdout
71+ assert result .returncode == 0 , f"Docker run failed: { result .stderr } "
72+ assert "MCP module loaded successfully " in result .stdout
14773
14874
14975if __name__ == "__main__" :
0 commit comments