-
-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·460 lines (393 loc) · 15.2 KB
/
run_tests.sh
File metadata and controls
executable file
·460 lines (393 loc) · 15.2 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#!/bin/bash
# Calibre-Web Automated - Interactive Test Runner
# Copyright (C) 2024-2025 Calibre-Web Automated contributors
# SPDX-License-Identifier: GPL-3.0-or-later
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Activate venv if it exists
if [ -d ".venv" ]; then
source .venv/bin/activate
fi
# Test configuration
# Default to 8085 to avoid conflicts with production CWA on 8083
TEST_PORT="${CWA_TEST_PORT:-8085}"
# Determine pytest command (python3 -m pytest works in more environments)
if command -v pytest &> /dev/null; then
PYTEST="pytest"
else
PYTEST="python3 -m pytest"
fi
# Check dependencies
check_dependencies() {
local missing_deps=0
# Check Docker
if ! command -v docker &> /dev/null; then
print_warning "Docker not found - integration tests will fail"
missing_deps=1
elif ! docker info &> /dev/null; then
print_warning "Docker daemon not running - integration tests will fail"
missing_deps=1
fi
# Check Python venv
if [ ! -d ".venv" ]; then
print_warning "Virtual environment not found"
echo " Run: python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt"
missing_deps=1
fi
# Check pytest
if ! command -v pytest &> /dev/null && ! python3 -c "import pytest" &> /dev/null; then
print_warning "pytest not installed"
echo " Run: pip install pytest pytest-timeout pytest-flask pytest-mock faker testcontainers"
missing_deps=1
fi
if [ $missing_deps -eq 1 ]; then
echo ""
read -p "Continue anyway? [y/N]: " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
}
# Print header
print_header() {
clear
echo -e "${BOLD}${CYAN}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Calibre-Web Automated - Test Suite Runner ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo "Setup Guide:"
echo "https://github.com/crocodilestick/Calibre-Web-Automated/wiki/Testing-Quick-Setup"
echo -e "${NC}"
}
# Print section header
print_section() {
echo -e "\n${BOLD}${BLUE}▶ $1${NC}"
}
# Print success message
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
# Print error message
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Print warning message
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
# Print info message
print_info() {
echo -e "${CYAN}ℹ${NC} $1"
}
# Check if running inside Docker
check_environment() {
if [ -f /.dockerenv ]; then
ENVIRONMENT="docker"
print_info "Running inside Docker container (Dev Container detected)"
DEFAULT_MODE="dind"
else
ENVIRONMENT="host"
print_info "Running on host machine"
DEFAULT_MODE="bind"
fi
}
# Show main menu
show_menu() {
print_header
check_environment
check_dependencies
echo ""
echo -e "${BOLD}Select Test Mode:${NC}"
echo ""
echo -e " ${BOLD}1)${NC} Integration Tests (Bind Mount Mode)"
echo " └─ Standard mode - uses temporary directories"
echo " └─ Best for: Local development, CI/CD"
echo ""
echo -e " ${BOLD}2)${NC} Integration Tests (Docker Volume Mode)"
echo " └─ DinD compatible - uses Docker volumes"
echo " └─ Best for: Dev containers, Docker-in-Docker"
echo ""
echo -e " ${BOLD}3)${NC} Docker Startup Tests"
echo " └─ Tests container initialization and health"
echo ""
echo -e " ${BOLD}4)${NC} All Tests (Full Suite)"
echo " └─ Run everything available"
echo ""
echo -e " ${BOLD}5)${NC} Quick Test (Single Integration Test)"
echo " └─ Fast verification - runs one test"
echo ""
echo -e " ${BOLD}6)${NC} Custom Test Selection"
echo " └─ Choose specific test file or pattern"
echo ""
echo -e " ${BOLD}7)${NC} Show Test Info & Status"
echo ""
echo -e " ${BOLD}q)${NC} Quit"
echo ""
echo -ne "${BOLD}Enter your choice [1-7, q]:${NC} "
}
# Run integration tests in bind mount mode
run_integration_bind() {
print_header
print_section "Running Integration Tests (Bind Mount Mode)"
echo ""
print_info "Starting test container with bind mounts..."
print_info "This will take ~3-4 minutes"
echo ""
# Check if pytest is available
if ! command -v pytest &> /dev/null; then
print_error "pytest not found! Installing..."
pip install -q pytest pytest-timeout pytest-flask pytest-mock faker
fi
# Run tests
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
if pytest tests/integration/test_ingest_pipeline.py -v --tb=short; then
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_success "All integration tests passed!"
else
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_error "Some tests failed. Check output above."
fi
echo ""
read -p "Press Enter to continue..."
}
# Run integration tests in Docker volume mode
run_integration_dind() {
print_header
print_section "Running Integration Tests (Docker Volume Mode)"
echo ""
print_info "Starting test container with Docker volumes..."
print_info "This will take ~3-4 minutes"
print_warning "Note: One test (cwa_db_tracks_import) will be skipped"
echo ""
# Check if pytest is available
if ! command -v pytest &> /dev/null; then
print_error "pytest not found! Installing..."
pip install -q pytest pytest-timeout pytest-flask pytest-mock faker
fi
# Run tests with volume mode enabled
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
if USE_DOCKER_VOLUMES=true pytest tests/integration/test_ingest_pipeline.py -v --tb=short; then
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_success "All runnable tests passed! (19/20, 1 skipped)"
else
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_error "Some tests failed. Check output above."
fi
echo ""
read -p "Press Enter to continue..."
}
# Run Docker startup tests
run_docker_tests() {
print_header
print_section "Running Docker Startup Tests"
echo ""
print_info "Testing container initialization..."
echo ""
if [ ! -f tests/docker/test_container_startup.py ]; then
print_error "Docker tests not found at tests/docker/test_container_startup.py"
echo ""
read -p "Press Enter to continue..."
return
fi
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
if pytest tests/docker/ -v --tb=short; then
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_success "Docker tests passed!"
else
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
print_error "Some Docker tests failed."
fi
echo ""
read -p "Press Enter to continue..."
}
# Run all tests
run_all_tests() {
print_header
print_section "Running Full Test Suite"
echo ""
print_info "This will run all available tests"
print_warning "Estimated time: 5-7 minutes"
echo ""
echo -ne "Continue? [y/N]: "
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
return
fi
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
# Determine mode based on environment
if [ "$DEFAULT_MODE" = "dind" ]; then
print_info "Using Docker Volume mode (DinD environment detected)"
USE_DOCKER_VOLUMES=true $PYTEST tests/ -v --tb=short || true
else
print_info "Using Bind Mount mode"
$PYTEST tests/ -v --tb=short || true
fi
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
read -p "Press Enter to continue..."
}
# Run quick test
run_quick_test() {
print_header
print_section "Quick Test - Single Integration Test"
echo ""
print_info "Running: test_ingest_epub_already_target_format"
print_info "This verifies basic ingest functionality (~30 seconds)"
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
if [ "$DEFAULT_MODE" = "dind" ]; then
USE_DOCKER_VOLUMES=true $PYTEST tests/integration/test_ingest_pipeline.py::TestBookIngestInContainer::test_ingest_epub_already_target_format -v
else
$PYTEST tests/integration/test_ingest_pipeline.py::TestBookIngestInContainer::test_ingest_epub_already_target_format -v
fi
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
read -p "Press Enter to continue..."
}
# Custom test selection
run_custom_test() {
print_header
print_section "Custom Test Selection"
echo ""
echo "Available test files:"
echo " 1) tests/integration/test_ingest_pipeline.py (20 tests)"
echo " 2) tests/docker/test_container_startup.py (9 tests)"
echo ""
echo "Or enter a custom pytest pattern (e.g., tests/integration/ -k metadata)"
echo ""
echo -ne "Enter choice [1-2 or custom pattern]: "
read -r choice
case $choice in
1)
TEST_PATH="tests/integration/test_ingest_pipeline.py"
;;
2)
TEST_PATH="tests/docker/test_container_startup.py"
;;
*)
TEST_PATH="$choice"
;;
esac
echo ""
print_info "Running: $TEST_PATH"
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
if [ "$DEFAULT_MODE" = "dind" ]; then
USE_DOCKER_VOLUMES=true $PYTEST $TEST_PATH -v
else
$PYTEST $TEST_PATH -v
fi
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
read -p "Press Enter to continue..."
}
# Show test information
show_info() {
print_header
print_section "Test Suite Information"
echo ""
print_info "Test Environment: $ENVIRONMENT"
print_info "Default Mode: $DEFAULT_MODE"
echo ""
echo -e "${BOLD}Available Tests:${NC}"
echo ""
# Count tests
echo "📊 Integration Tests:"
$PYTEST tests/integration/ --collect-only -q 2>/dev/null | tail -1 || echo " (pytest needed to count)"
echo ""
if [ -d tests/docker ]; then
echo "🐳 Docker Tests:"
$PYTEST tests/docker/ --collect-only -q 2>/dev/null | tail -1 || echo " (pytest needed to count)"
echo ""
fi
echo -e "${BOLD}Test Modes:${NC}"
echo ""
echo -e "• ${BOLD}Bind Mount Mode${NC} (Default on host)"
echo " └─ Uses temporary directories"
echo " └─ 20/20 integration tests pass"
echo " └─ Faster cleanup"
echo ""
echo -e "• ${BOLD}Docker Volume Mode${NC} (Default in dev containers)"
echo " └─ Uses Docker volumes via docker cp"
echo " └─ 19/20 integration tests pass (1 skipped)"
echo " └─ Required for Docker-in-Docker"
echo ""
echo -e "${BOLD}Documentation:${NC}"
echo " • tests/DOCKER_VOLUMES.md - Volume mode details"
echo " • HYBRID_DOCKER_IMPLEMENTATION.md - Implementation notes"
echo " • DIND_MODE_COMPLETE.md - Completion summary"
echo ""
read -p "Press Enter to continue..."
}
# Main loop
main() {
# Check for required dependencies
if ! command -v docker &> /dev/null; then
print_header
print_error "Docker is required but not found!"
echo ""
echo "Please install Docker and try again."
exit 1
fi
while true; do
show_menu
read -r choice
case $choice in
1)
run_integration_bind
;;
2)
run_integration_dind
;;
3)
run_docker_tests
;;
4)
run_all_tests
;;
5)
run_quick_test
;;
6)
run_custom_test
;;
7)
show_info
;;
q|Q)
print_header
print_success "Goodbye!"
echo ""
exit 0
;;
*)
print_header
print_error "Invalid choice. Please try again."
sleep 2
;;
esac
done
}
# Run main function
main