-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun_docker_tests.sh
More file actions
executable file
·204 lines (168 loc) · 6.05 KB
/
run_docker_tests.sh
File metadata and controls
executable file
·204 lines (168 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# Comprehensive Docker test runner for CodeDox
set -e
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
TEST_MODE=${1:-"full"} # full, quick, or health
CLEANUP=${CLEANUP:-"true"}
echo -e "${BLUE}🐋 CodeDox Docker Test Suite${NC}"
echo "=============================="
echo "Mode: $TEST_MODE"
echo ""
# Function to cleanup
cleanup() {
if [ "$CLEANUP" = "true" ]; then
echo -e "\n${YELLOW}🧹 Cleaning up...${NC}"
docker-compose down -v 2>/dev/null || true
docker-compose -f docker-compose.test.yml down -v 2>/dev/null || true
fi
}
# Set trap to cleanup on exit
trap cleanup EXIT
# Function to run tests
run_tests() {
local test_type=$1
case $test_type in
"quick")
echo -e "${BLUE}Running quick health checks...${NC}\n"
# Start services
echo "1. Starting services..."
docker-compose up -d
# Wait for services
echo -e "\n2. Waiting for services to be ready..."
sleep 10
# Run health check
echo -e "\n3. Running health checks..."
./test_docker_health.sh
;;
"health")
echo -e "${BLUE}Running service health tests...${NC}\n"
# Build if needed
echo "1. Building Docker images..."
docker-compose build
# Start services
echo -e "\n2. Starting services..."
docker-compose up -d
# Run health check
echo -e "\n3. Running health checks..."
sleep 15 # Give more time for services to start
./test_docker_health.sh
# Show logs if failed
if [ $? -ne 0 ]; then
echo -e "\n${RED}Health checks failed. Showing logs:${NC}"
docker-compose logs --tail=50
fi
;;
"full")
echo -e "${BLUE}Running full test suite...${NC}\n"
# 1. Build images
echo "1. Building Docker images..."
docker-compose build
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Build failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Images built successfully${NC}\n"
# 2. Start main services
echo "2. Starting main services..."
docker-compose up -d postgres api
sleep 10
# 3. Initialize database
echo -e "\n3. Initializing database..."
docker-compose exec -T api python cli.py init --drop
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Database initialized${NC}"
else
echo -e "${RED}✗ Database initialization failed${NC}"
exit 1
fi
# 4. Start frontend
echo -e "\n4. Starting frontend..."
docker-compose up -d frontend
# 5. Run health checks
echo -e "\n5. Running health checks..."
sleep 10
./test_docker_health.sh
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Health checks failed${NC}"
exit 1
fi
# 6. Run integration tests
echo -e "\n6. Running integration tests..."
docker-compose -f docker-compose.test.yml run --rm test
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Integration tests passed${NC}"
else
echo -e "${RED}✗ Integration tests failed${NC}"
exit 1
fi
# 7. Test MCP functionality
echo -e "\n7. Testing MCP functionality..."
echo -n " - Listing tools: "
if curl -s http://localhost:8000/mcp/tools | grep -q "search_libraries"; then
echo -e "${GREEN}✓${NC}"
else
echo -e "${RED}✗${NC}"
exit 1
fi
echo -n " - Testing search: "
response=$(curl -s -X POST http://localhost:8000/mcp/execute/search_libraries \
-H "Content-Type: application/json" \
-d '{"query": "test"}')
if echo "$response" | grep -q "libraries"; then
echo -e "${GREEN}✓${NC}"
else
echo -e "${RED}✗${NC}"
exit 1
fi
echo -e "${GREEN}✓ All MCP tests passed${NC}"
;;
*)
echo -e "${RED}Unknown test mode: $test_type${NC}"
echo "Usage: $0 [quick|health|full]"
exit 1
;;
esac
}
# Main execution
main() {
# Check prerequisites
echo "Checking prerequisites..."
# Check Docker
if ! docker version > /dev/null 2>&1; then
echo -e "${RED}✗ Docker is not installed or not running${NC}"
exit 1
fi
echo -e "${GREEN}✓ Docker is running${NC}"
# Check docker-compose
if ! docker-compose version > /dev/null 2>&1; then
echo -e "${RED}✗ docker-compose is not installed${NC}"
exit 1
fi
echo -e "${GREEN}✓ docker-compose is available${NC}"
# Check .env file
if [ ! -f .env ]; then
echo -e "${YELLOW}⚠ .env file not found, using defaults${NC}"
cp .env.example .env
fi
echo ""
# Run tests
run_tests $TEST_MODE
# Summary
echo -e "\n${GREEN}=============================="
echo -e "✅ Docker tests completed successfully!${NC}"
echo -e "==============================\n"
if [ "$TEST_MODE" = "full" ] && [ "$CLEANUP" = "false" ]; then
echo "Services are still running. You can:"
echo " • View the frontend at http://localhost:5173"
echo " • Access the API at http://localhost:8000"
echo " • Stop services with: docker-compose down"
fi
}
# Run main
main