-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-local-docker.sh
More file actions
executable file
Β·201 lines (164 loc) Β· 5.67 KB
/
test-local-docker.sh
File metadata and controls
executable file
Β·201 lines (164 loc) Β· 5.67 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
#!/bin/bash
# π³ Docker-based Local Testing (matches CI/CD environment)
# This script runs tests in the same environment as GitHub Actions
set -e
echo "π³ Docker-Based Local Testing - Matches CI/CD Environment"
echo "=========================================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
print_error "Docker is not running. Please start Docker Desktop."
exit 1
fi
print_status "Creating CI/CD-like test environment with Docker..."
# Create a Docker network for services
print_status "Creating test network..."
docker network create flexfit-test-network 2>/dev/null || true
# 1. Test Java Services (Ubuntu + Java 21)
print_status "π§ͺ Testing Java Services (Ubuntu + Java 21)..."
docker run --rm \
--network flexfit-test-network \
-v "$(pwd)":/workspace \
-w /workspace \
openjdk:21-jdk-slim \
bash -c "
echo 'π¦ Installing dependencies...'
apt-get update -qq && apt-get install -y -qq curl wget
echo 'β Java Unit Tests - User Service'
cd server/user-service
chmod +x mvnw
./mvnw clean test -q -Dspring.profiles.active=test
echo 'β Java Unit Tests - Workout Plan Service'
cd ../workout-plan-service
chmod +x mvnw
./mvnw clean test -q -Dspring.profiles.active=test
echo 'β Java Unit Tests - API Gateway'
cd ../api-gateway
chmod +x mvnw
./mvnw clean test -q
echo 'β Java Unit Tests - Service Registry'
cd ../service-registry
chmod +x mvnw
./mvnw clean test -q
echo 'β
All Java tests completed'
"
if [ $? -eq 0 ]; then
print_success "Java Unit Tests PASSED"
else
print_error "Java Unit Tests FAILED"
exit 1
fi
# 2. Test Python Services (Python 3.9)
print_status "π Testing Python Services (Python 3.9)..."
docker run --rm \
--network flexfit-test-network \
-v "$(pwd)":/workspace \
-w /workspace/genai \
python:3.9-slim \
bash -c "
echo 'π¦ Installing Python dependencies...'
pip install -q pytest requests fastapi uvicorn httpx
pip install -q -r requirements.txt
echo 'π§ͺ Python Unit Tests - GenAI Cloud Worker'
if [ -f test_workout_worker.py ]; then
python -m pytest test_workout_worker.py -v --tb=short
else
echo 'No GenAI cloud tests found'
fi
echo 'π§ͺ Python Unit Tests - GenAI Local Worker'
if [ -f test_workout_worker_local.py ]; then
python -m pytest test_workout_worker_local.py -v --tb=short
else
echo 'No GenAI local tests found'
fi
echo 'β
Python tests completed'
"
if [ $? -eq 0 ]; then
print_success "Python Unit Tests PASSED"
else
print_warning "Python Unit Tests had issues (checking...)"
fi
# 3. Test Client (Node.js 20)
print_status "π Testing Client (Node.js 20)..."
docker run --rm \
--network flexfit-test-network \
-v "$(pwd)":/workspace \
-w /workspace/client \
node:20-slim \
bash -c "
echo 'π¦ Installing Node.js dependencies...'
npm install -q --no-progress
echo 'π§ͺ Client Unit Tests'
# Install test framework if missing
if ! npm list jest >/dev/null 2>&1; then
echo 'Installing Jest test framework...'
npm install -q --no-progress --save-dev jest
fi
# Run tests with proper test framework
if [ -f tests/core-workflows.test.js ]; then
echo 'Running core workflows tests...'
npx jest tests/core-workflows.test.js || node tests/core-workflows.test.js
fi
if [ -f tests/ai-preference-integration.test.js ]; then
echo 'Running AI preference tests...'
npx jest tests/ai-preference-integration.test.js || node tests/ai-preference-integration.test.js
fi
echo 'β
Client tests completed'
"
if [ $? -eq 0 ]; then
print_success "Client Unit Tests PASSED"
else
print_warning "Client Unit Tests had issues (checking...)"
fi
# 4. Integration Test Environment Setup
print_status "π Testing Integration Test Setup..."
docker run --rm \
--network flexfit-test-network \
-v "$(pwd)":/workspace \
-w /workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
docker:latest \
sh -c "
echo 'π³ Checking Docker Compose setup...'
if [ -f docker-compose.yml ]; then
echo 'Docker Compose file exists β
'
else
echo 'Docker Compose file missing β'
fi
if [ -f run-integration-tests.sh ]; then
echo 'Integration test script exists β
'
else
echo 'Integration test script missing β'
fi
"
# Cleanup
print_status "π§Ή Cleaning up test environment..."
docker network rm flexfit-test-network 2>/dev/null || true
echo ""
print_success "π Docker-based local testing completed!"
echo ""
print_status "π‘ This environment matches GitHub Actions CI/CD exactly:"
echo " - Ubuntu Linux containers"
echo " - Java 21 (same as CI/CD)"
echo " - Python 3.9 (same as CI/CD)"
echo " - Node.js 20 (same as CI/CD)"
echo ""
print_status "If tests pass here, they should pass on CI/CD! π"