1+ """
2+ Integration tests for Docker image build.
3+
4+ These tests verify that the Docker image can be built successfully.
5+ """
6+ import subprocess
7+ import pytest
8+ import shutil
9+
10+
11+ # Check if Docker is available
12+ def docker_available ():
13+ """Check if Docker is available on the system."""
14+ if not shutil .which ("docker" ):
15+ return False
16+ # Try to run docker version to ensure it's working
17+ try :
18+ result = subprocess .run (
19+ ["docker" , "version" ],
20+ capture_output = True ,
21+ text = True ,
22+ timeout = 5
23+ )
24+ return result .returncode == 0
25+ except (subprocess .TimeoutExpired , FileNotFoundError ):
26+ return False
27+
28+
29+ # Skip all tests in this module if Docker is not available
30+ pytestmark = pytest .mark .skipif (
31+ not docker_available (),
32+ reason = "Docker not available on this system"
33+ )
34+
35+
36+ def test_docker_build ():
37+ """Test that the Docker image can be built successfully."""
38+ result = subprocess .run (
39+ ["docker" , "build" , "-t" , "meilisearch-mcp-test" , "." ],
40+ capture_output = True ,
41+ text = True
42+ )
43+ assert result .returncode == 0 , f"Docker build failed: { result .stderr } "
44+
45+
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" , "." ],
51+ capture_output = True ,
52+ text = True
53+ )
54+ if build_result .returncode != 0 :
55+ pytest .skip (f"Docker build failed: { build_result .stderr } " )
56+
57+ # Try to run the container and check it starts
58+ result = subprocess .run (
59+ [
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')"
65+ ],
66+ capture_output = True ,
67+ text = True ,
68+ timeout = 30
69+ )
70+
71+ assert result .returncode == 0 , f"Docker run failed: { result .stderr } "
72+ assert "MCP module loaded successfully" in result .stdout
73+
74+
75+ if __name__ == "__main__" :
76+ # Run tests
77+ pytest .main ([__file__ , "-v" ])
0 commit comments