-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
231 lines (198 loc) · 5.62 KB
/
test.sh
File metadata and controls
231 lines (198 loc) · 5.62 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# Test runner script for DockerVault
# Runs both backend and frontend tests with coverage reporting
set -e # Exit on any error
echo "🧪 Running DockerVault Test Suite"
echo "================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Check if we're in the right directory
if [ ! -f "docker-compose.yml" ]; then
print_error "Please run this script from the project root directory"
exit 1
fi
# Parse command line arguments
BACKEND_ONLY=false
FRONTEND_ONLY=false
COVERAGE=true
VERBOSE=false
HELP=false
while [[ $# -gt 0 ]]; do
case $1 in
--backend-only)
BACKEND_ONLY=true
shift
;;
--frontend-only)
FRONTEND_ONLY=true
shift
;;
--no-coverage)
COVERAGE=false
shift
;;
--verbose|-v)
VERBOSE=true
shift
;;
--help|-h)
HELP=true
shift
;;
*)
print_error "Unknown option $1"
exit 1
;;
esac
done
if [ "$HELP" = true ]; then
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --backend-only Run only backend tests"
echo " --frontend-only Run only frontend tests"
echo " --no-coverage Skip coverage reporting"
echo " --verbose, -v Show verbose output"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all tests with coverage"
echo " $0 --backend-only # Run only backend tests"
echo " $0 --no-coverage -v # Run all tests without coverage, verbose"
exit 0
fi
# Initialize test results
BACKEND_PASSED=false
FRONTEND_PASSED=false
# Backend Tests
if [ "$FRONTEND_ONLY" = false ]; then
echo ""
echo "🐍 Running Backend Tests (Python)"
echo "--------------------------------"
cd backend
# Check if virtual environment exists
if [ ! -d "venv" ]; then
print_warning "Virtual environment not found, creating one..."
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
else
source venv/bin/activate
fi
# Install test dependencies if not already installed
if ! pip list | grep -q pytest; then
print_status "Installing test dependencies..."
pip install -r requirements-dev.txt
fi
# Run backend tests
print_status "Running pytest..."
if [ "$COVERAGE" = true ]; then
if [ "$VERBOSE" = true ]; then
pytest -v --cov=app --cov-report=term-missing --cov-report=html:htmlcov --cov-fail-under=80
else
pytest --cov=app --cov-report=term-missing --cov-report=html:htmlcov --cov-fail-under=80 --tb=short
fi
else
if [ "$VERBOSE" = true ]; then
pytest -v
else
pytest --tb=short
fi
fi
if [ $? -eq 0 ]; then
BACKEND_PASSED=true
print_status "Backend tests passed!"
if [ "$COVERAGE" = true ]; then
print_status "Coverage report generated in backend/htmlcov/"
fi
else
print_error "Backend tests failed!"
fi
cd ..
fi
# Frontend Tests
if [ "$BACKEND_ONLY" = false ]; then
echo ""
echo "⚛️ Running Frontend Tests (React/TypeScript)"
echo "--------------------------------------------"
cd frontend
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
print_warning "Dependencies not installed, running npm install..."
npm install
fi
# Run frontend tests
print_status "Running vitest..."
if [ "$COVERAGE" = true ]; then
if [ "$VERBOSE" = true ]; then
npm run test:coverage -- --run --reporter=verbose
else
npm run test:coverage -- --run
fi
else
if [ "$VERBOSE" = true ]; then
npm test -- --run --reporter=verbose
else
npm test -- --run
fi
fi
if [ $? -eq 0 ]; then
FRONTEND_PASSED=true
print_status "Frontend tests passed!"
if [ "$COVERAGE" = true ]; then
print_status "Coverage report generated in frontend/coverage/"
fi
else
print_error "Frontend tests failed!"
fi
cd ..
fi
# Test Summary
echo ""
echo "📊 Test Summary"
echo "==============="
if [ "$FRONTEND_ONLY" = false ]; then
if [ "$BACKEND_PASSED" = true ]; then
print_status "Backend: PASSED"
else
print_error "Backend: FAILED"
fi
fi
if [ "$BACKEND_ONLY" = false ]; then
if [ "$FRONTEND_PASSED" = true ]; then
print_status "Frontend: PASSED"
else
print_error "Frontend: FAILED"
fi
fi
# Overall result
if ([ "$FRONTEND_ONLY" = false ] && [ "$BACKEND_PASSED" = false ]) ||
([ "$BACKEND_ONLY" = false ] && [ "$FRONTEND_PASSED" = false ]); then
echo ""
print_error "Some tests failed. Please check the output above."
exit 1
else
echo ""
print_status "All tests passed! 🎉"
if [ "$COVERAGE" = true ]; then
echo ""
echo "📈 Coverage Reports:"
[ "$FRONTEND_ONLY" = false ] && echo " Backend: backend/htmlcov/index.html"
[ "$BACKEND_ONLY" = false ] && echo " Frontend: frontend/coverage/index.html"
fi
exit 0
fi