|
Bogdan Timofte
authored
8 months ago
|
1
|
#!/bin/bash
|
|
|
2
|
|
|
|
3
|
# Media Importer Test Runner
|
|
|
4
|
# Comprehensive testing framework based on Development.md specifications
|
|
|
5
|
|
|
|
6
|
set -e
|
|
|
7
|
|
|
|
8
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
9
|
TEST_DIR="$SCRIPT_DIR/test"
|
|
|
10
|
SOURCE_DIR="$TEST_DIR/source"
|
|
|
11
|
DEST_DIR="$TEST_DIR/destination"
|
|
|
12
|
SAMPLES_DIR="$SCRIPT_DIR/sample" # Fixed: was 'samples' but should be 'sample'
|
|
|
13
|
MEDIA_IMPORTER="$SCRIPT_DIR/media-importer.sh"
|
|
|
14
|
TEST_REPORTS_DIR="$SCRIPT_DIR/test_reports"
|
|
|
15
|
|
|
|
16
|
# Colors for output
|
|
|
17
|
RED='\033[0;31m'
|
|
|
18
|
GREEN='\033[0;32m'
|
|
|
19
|
YELLOW='\033[1;33m'
|
|
|
20
|
BLUE='\033[0;34m'
|
|
|
21
|
NC='\033[0m' # No Color
|
|
|
22
|
|
|
|
23
|
# Function to print colored output
|
|
|
24
|
print_color() {
|
|
|
25
|
local color="$1"
|
|
|
26
|
local message="$2"
|
|
|
27
|
echo -e "${color}${message}${NC}"
|
|
|
28
|
}
|
|
|
29
|
|
|
|
30
|
# Function to create test directories
|
|
|
31
|
create_test_dirs() {
|
|
|
32
|
print_color "$BLUE" "Creating test directories..."
|
|
|
33
|
mkdir -p "$SOURCE_DIR"
|
|
|
34
|
mkdir -p "$DEST_DIR"
|
|
|
35
|
mkdir -p "$TEST_REPORTS_DIR"
|
|
|
36
|
}
|
|
|
37
|
|
|
|
38
|
# Function to clean test directory
|
|
|
39
|
clean_test_dir() {
|
|
|
40
|
print_color "$BLUE" "Cleaning test directory..."
|
|
|
41
|
rm -rf "$TEST_DIR"/*
|
|
|
42
|
}
|
|
|
43
|
|
|
|
44
|
# Function to copy sample files
|
|
|
45
|
copy_sample_files() {
|
|
|
46
|
local source_pattern="$1"
|
|
|
47
|
local target_dir="$2"
|
|
|
48
|
|
|
|
49
|
if [[ -d "$SAMPLES_DIR/$source_pattern" ]]; then
|
|
|
50
|
# Copy all files recursively from source to target directory
|
|
|
51
|
find "$SAMPLES_DIR/$source_pattern" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.tiff" -o -iname "*.tif" -o -iname "*.cr2" -o -iname "*.nef" -o -iname "*.arw" -o -iname "*.dng" -o -iname "*.raw" -o -iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.mts" -o -iname "*.m2ts" -o -iname "*.mkv" -o -iname "*.wmv" -o -iname "*.3gp" -o -iname "*.m4v" \) -exec cp {} "$target_dir/" \; 2>/dev/null || true
|
|
|
52
|
print_color "$GREEN" "Copied $source_pattern files to $target_dir"
|
|
|
53
|
else
|
|
|
54
|
print_color "$YELLOW" "Warning: $SAMPLES_DIR/$source_pattern not found. Path: $SAMPLES_DIR/$source_pattern"
|
|
|
55
|
fi
|
|
|
56
|
}
|
|
|
57
|
|
|
|
58
|
# Function to capture directory state
|
|
|
59
|
capture_state() {
|
|
|
60
|
local dir_path="$1"
|
|
|
61
|
local output_file="$2"
|
|
|
62
|
local label="$3"
|
|
|
63
|
|
|
|
64
|
print_color "$BLUE" "Capturing $label directory state..."
|
|
|
65
|
if [[ -d "$dir_path" ]]; then
|
|
|
66
|
find "$dir_path" -type f | sort > "$output_file"
|
|
|
67
|
else
|
|
|
68
|
echo "# Directory does not exist or is empty" > "$output_file"
|
|
|
69
|
fi
|
|
|
70
|
}
|
|
|
71
|
|
|
|
72
|
# Function to run test command and capture output
|
|
|
73
|
run_test_command() {
|
|
|
74
|
local command="$1"
|
|
|
75
|
local log_file="$2"
|
|
|
76
|
|
|
|
77
|
print_color "$YELLOW" "Executing: $command"
|
|
|
78
|
echo "$command" > "$log_file"
|
|
|
79
|
echo "" >> "$log_file"
|
|
|
80
|
echo "=== SCRIPT OUTPUT ===" >> "$log_file"
|
|
|
81
|
|
|
|
82
|
# Run command and capture both stdout and stderr
|
|
|
83
|
if eval "$command" >> "$log_file" 2>&1; then
|
|
|
84
|
echo "" >> "$log_file"
|
|
|
85
|
echo "=== COMMAND COMPLETED SUCCESSFULLY ===" >> "$log_file"
|
|
|
86
|
return 0
|
|
|
87
|
else
|
|
|
88
|
echo "" >> "$log_file"
|
|
|
89
|
echo "=== COMMAND FAILED ===" >> "$log_file"
|
|
|
90
|
return 1
|
|
|
91
|
fi
|
|
|
92
|
}
|
|
|
93
|
|
|
|
94
|
# Function to generate test report
|
|
|
95
|
generate_test_report() {
|
|
|
96
|
local test_name="$1"
|
|
|
97
|
local scenario="$2"
|
|
|
98
|
local objective="$3"
|
|
|
99
|
local files_used="$4"
|
|
|
100
|
local command="$5"
|
|
|
101
|
local result_status="$6"
|
|
|
102
|
|
|
|
103
|
# Determine success/failure prefix
|
|
|
104
|
local status_prefix
|
|
|
105
|
if [[ $result_status -eq 0 ]]; then
|
|
|
106
|
status_prefix="s"
|
|
|
107
|
else
|
|
|
108
|
status_prefix="f"
|
|
|
109
|
fi
|
|
|
110
|
|
|
|
111
|
# Format date as YYYYMMDD
|
|
|
112
|
local date_stamp=$(date '+%Y%m%d')
|
|
|
113
|
|
|
|
114
|
# Create filename with new format: [s|f]_date_restul_numelei
|
|
|
115
|
local report_file="$TEST_REPORTS_DIR/${status_prefix}_${date_stamp}_${test_name}.md"
|
|
|
116
|
|
|
|
117
|
print_color "$BLUE" "Generating test report: $report_file"
|
|
|
118
|
|
|
|
119
|
cat > "$report_file" << EOF
|
|
|
120
|
# Test Report: $test_name
|
|
|
121
|
|
|
|
122
|
## Test Information
|
|
|
123
|
- **Date**: $(date)
|
|
|
124
|
- **Scenario**: $scenario
|
|
|
125
|
- **Objective**: $objective
|
|
|
126
|
- **Files Used**: $files_used
|
|
|
127
|
|
|
|
128
|
## Pre-Test State
|
|
|
129
|
### Source Directory Structure
|
|
|
130
|
\`\`\`
|
|
|
131
|
$(cat "$TEST_DIR/source_before.txt" 2>/dev/null || echo "# No pre-test source state captured")
|
|
|
132
|
\`\`\`
|
|
|
133
|
|
|
|
134
|
### Destination Directory Structure
|
|
|
135
|
\`\`\`
|
|
|
136
|
$(cat "$TEST_DIR/dest_before.txt" 2>/dev/null || echo "# No pre-test destination state captured")
|
|
|
137
|
\`\`\`
|
|
|
138
|
|
|
|
139
|
## Test Execution
|
|
|
140
|
### Command Used
|
|
|
141
|
\`\`\`bash
|
|
|
142
|
$command
|
|
|
143
|
\`\`\`
|
|
|
144
|
|
|
|
145
|
### Script Output
|
|
|
146
|
\`\`\`
|
|
|
147
|
$(cat "$TEST_DIR/import_log.txt" 2>/dev/null || echo "# No script output captured")
|
|
|
148
|
\`\`\`
|
|
|
149
|
|
|
|
150
|
## Post-Test State
|
|
|
151
|
### Source Directory Structure
|
|
|
152
|
\`\`\`
|
|
|
153
|
$(cat "$TEST_DIR/source_after.txt" 2>/dev/null || echo "# No post-test source state captured")
|
|
|
154
|
\`\`\`
|
|
|
155
|
|
|
|
156
|
### Destination Directory Structure
|
|
|
157
|
\`\`\`
|
|
|
158
|
$(cat "$TEST_DIR/dest_after.txt" 2>/dev/null || echo "# No post-test destination state captured")
|
|
|
159
|
\`\`\`
|
|
|
160
|
|
|
|
161
|
## Analysis and Verification
|
|
|
162
|
### Expected Results
|
|
|
163
|
- Files should be processed according to the test scenario
|
|
|
164
|
- No data loss should occur
|
|
|
165
|
- Proper error handling for edge cases
|
|
|
166
|
|
|
|
167
|
### Actual Results
|
|
|
168
|
- Test execution completed with status: $result_status
|
|
|
169
|
|
|
|
170
|
### Issues Found
|
|
|
171
|
- [ ] No issues detected
|
|
|
172
|
- [ ] Issues found (see notes below)
|
|
|
173
|
|
|
|
174
|
### Protections Verified
|
|
|
175
|
- [ ] Destination exclusion working
|
|
|
176
|
- [ ] Move confirmation functional
|
|
|
177
|
- [ ] No data loss detected
|
|
|
178
|
- [ ] UTC conversion correct (for QuickTime files)
|
|
|
179
|
- [ ] Unimportable files handling (if applicable)
|
|
|
180
|
|
|
|
181
|
## Conclusion
|
|
|
182
|
### Test Result
|
|
|
183
|
- [ ] PASSED
|
|
|
184
|
- [ ] FAILED
|
|
|
185
|
- [ ] PARTIAL (with notes)
|
|
|
186
|
|
|
|
187
|
### Notes
|
|
|
188
|
Test completed as per Development.md specifications.
|
|
|
189
|
|
|
|
190
|
### Files Generated
|
|
|
191
|
- \`test/source_before.txt\` - Pre-test source structure
|
|
|
192
|
- \`test/dest_before.txt\` - Pre-test destination structure
|
|
|
193
|
- \`test/source_after.txt\` - Post-test source structure
|
|
|
194
|
- \`test/dest_after.txt\` - Post-test destination structure
|
|
|
195
|
- \`test/import_log.txt\` - Full script execution log
|
|
|
196
|
- \`test/test_report.md\` - This report
|
|
|
197
|
EOF
|
|
|
198
|
|
|
|
199
|
print_color "$GREEN" "Test report generated: $report_file"
|
|
|
200
|
|
|
|
201
|
# Clean up old reports, keeping only the last 10
|
|
|
202
|
cleanup_old_reports
|
|
|
203
|
}
|
|
|
204
|
|
|
|
205
|
# Function to clean up old test reports, keeping only the last 10
|
|
|
206
|
cleanup_old_reports() {
|
|
|
207
|
if [[ -d "$TEST_REPORTS_DIR" ]]; then
|
|
|
208
|
# Count total reports
|
|
|
209
|
local total_reports=$(find "$TEST_REPORTS_DIR" -name "*.md" | wc -l)
|
|
|
210
|
|
|
|
211
|
if [[ $total_reports -gt 10 ]]; then
|
|
|
212
|
print_color "$BLUE" "Cleaning up old test reports (keeping last 10)..."
|
|
|
213
|
|
|
|
214
|
# Find and remove oldest reports, keeping the 10 most recent
|
|
|
215
|
find "$TEST_REPORTS_DIR" -name "*.md" -type f -printf '%T@ %p\n' | \
|
|
|
216
|
sort -n | \
|
|
|
217
|
head -n -$((10)) | \
|
|
|
218
|
cut -d' ' -f2- | \
|
|
|
219
|
xargs -r rm
|
|
|
220
|
|
|
|
221
|
local remaining=$(find "$TEST_REPORTS_DIR" -name "*.md" | wc -l)
|
|
|
222
|
print_color "$GREEN" "Kept $remaining most recent test reports"
|
|
|
223
|
fi
|
|
|
224
|
fi
|
|
|
225
|
}
|
|
|
226
|
|
|
|
227
|
# Test Case 0: Basic Functionality Test
|
|
|
228
|
run_basic_functionality_test() {
|
|
|
229
|
print_color "$GREEN" "=== Running Test 0: Basic Functionality Test ==="
|
|
|
230
|
|
|
|
231
|
clean_test_dir
|
|
|
232
|
create_test_dirs
|
|
|
233
|
|
|
|
234
|
# Setup test files
|
|
|
235
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
236
|
|
|
|
237
|
# Capture pre-test state
|
|
|
238
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
239
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
240
|
|
|
|
241
|
# Run test
|
|
|
242
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
243
|
local result=0
|
|
|
244
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
245
|
|
|
|
246
|
# Capture post-test state
|
|
|
247
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
248
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
249
|
|
|
|
250
|
# Generate report
|
|
|
251
|
generate_test_report \
|
|
|
252
|
"Basic_Functionality" \
|
|
|
253
|
"Processing files with valid EXIF data" \
|
|
|
254
|
"Verify correct sorting and organization of media files" \
|
|
|
255
|
"Sample media files with EXIF data from samples/media/sortable/" \
|
|
|
256
|
"$command" \
|
|
|
257
|
"$result"
|
|
|
258
|
}
|
|
|
259
|
|
|
|
260
|
# Test Case 1: Unimportable Files Test
|
|
|
261
|
run_unimportable_files_test() {
|
|
|
262
|
print_color "$GREEN" "=== Running Test 1: Unimportable Files Test ==="
|
|
|
263
|
|
|
|
264
|
clean_test_dir
|
|
|
265
|
create_test_dirs
|
|
|
266
|
|
|
|
267
|
# Setup test files - mix of sortable and unimportable
|
|
|
268
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
269
|
copy_sample_files "media/unimportable" "$SOURCE_DIR"
|
|
|
270
|
|
|
|
271
|
# Capture pre-test state
|
|
|
272
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
273
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
274
|
|
|
|
275
|
# Run test (without --collect-unimportable flag)
|
|
|
276
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
277
|
local result=0
|
|
|
278
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
279
|
|
|
|
280
|
# Capture post-test state
|
|
|
281
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
282
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
283
|
|
|
|
284
|
# Generate report
|
|
|
285
|
generate_test_report \
|
|
|
286
|
"Unimportable_Files_Handling" \
|
|
|
287
|
"Testing files without EXIF data in root and subfolders" \
|
|
|
288
|
"Verify proper handling of unimportable files without collection flag" \
|
|
|
289
|
"Mixed sortable and unimportable files from samples/media/" \
|
|
|
290
|
"$command" \
|
|
|
291
|
"$result"
|
|
|
292
|
}
|
|
|
293
|
|
|
|
294
|
# Test Case 2: Mixed Content Test
|
|
|
295
|
run_mixed_content_test() {
|
|
|
296
|
print_color "$GREEN" "=== Running Test 2: Mixed Content Test ==="
|
|
|
297
|
|
|
|
298
|
clean_test_dir
|
|
|
299
|
create_test_dirs
|
|
|
300
|
|
|
|
301
|
# Setup separate folders for sortable vs unimportable
|
|
|
302
|
mkdir -p "$SOURCE_DIR/sortable" "$SOURCE_DIR/unimportable"
|
|
|
303
|
copy_sample_files "media/sortable" "$SOURCE_DIR/sortable"
|
|
|
304
|
copy_sample_files "media/unimportable" "$SOURCE_DIR/unimportable"
|
|
|
305
|
|
|
|
306
|
# Capture pre-test state
|
|
|
307
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
308
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
309
|
|
|
|
310
|
# Run test
|
|
|
311
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
312
|
local result=0
|
|
|
313
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
314
|
|
|
|
315
|
# Capture post-test state
|
|
|
316
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
317
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
318
|
|
|
|
319
|
# Generate report
|
|
|
320
|
generate_test_report \
|
|
|
321
|
"Mixed_Content" \
|
|
|
322
|
"Processing sortable and unimportable files in separate folders" \
|
|
|
323
|
"Verify cleanup behavior for folders with different file types" \
|
|
|
324
|
"Separate folders: sortable/ and unimportable/ with respective file types" \
|
|
|
325
|
"$command" \
|
|
|
326
|
"$result"
|
|
|
327
|
}
|
|
|
328
|
|
|
|
329
|
# Test Case 3: Safety Protections Test
|
|
|
330
|
run_safety_protections_test() {
|
|
|
331
|
print_color "$GREEN" "=== Running Test 3: Safety Protections Test ==="
|
|
|
332
|
|
|
|
333
|
clean_test_dir
|
|
|
334
|
create_test_dirs
|
|
|
335
|
|
|
|
336
|
# Setup test files
|
|
|
337
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
338
|
|
|
|
339
|
# Create a file in destination to test exclusion
|
|
|
340
|
echo "test file" > "$DEST_DIR/test.txt"
|
|
|
341
|
|
|
|
342
|
# Capture pre-test state
|
|
|
343
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
344
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
345
|
|
|
|
346
|
# Run test
|
|
|
347
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
348
|
local result=0
|
|
|
349
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
350
|
|
|
|
351
|
# Capture post-test state
|
|
|
352
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
353
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
354
|
|
|
|
355
|
# Generate report
|
|
|
356
|
generate_test_report \
|
|
|
357
|
"Safety_Protections" \
|
|
|
358
|
"Testing destination exclusion and move confirmation" \
|
|
|
359
|
"Verify data integrity protections prevent data loss" \
|
|
|
360
|
"Sample files with pre-existing destination content" \
|
|
|
361
|
"$command" \
|
|
|
362
|
"$result"
|
|
|
363
|
}
|
|
|
364
|
|
|
|
365
|
# Test Case 4: UTC Conversion Test
|
|
|
366
|
run_utc_conversion_test() {
|
|
|
367
|
print_color "$GREEN" "=== Running Test 4: UTC Conversion Test ==="
|
|
|
368
|
|
|
|
369
|
clean_test_dir
|
|
|
370
|
create_test_dirs
|
|
|
371
|
|
|
|
372
|
# Setup test files (assuming QuickTime files are available)
|
|
|
373
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
374
|
|
|
|
375
|
# Capture pre-test state
|
|
|
376
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
377
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
378
|
|
|
|
379
|
# Run test
|
|
|
380
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
381
|
local result=0
|
|
|
382
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
383
|
|
|
|
384
|
# Capture post-test state
|
|
|
385
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
386
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
387
|
|
|
|
388
|
# Generate report
|
|
|
389
|
generate_test_report \
|
|
|
390
|
"UTC_Conversion" \
|
|
|
391
|
"Testing UTC timestamp conversion for QuickTime files" \
|
|
|
392
|
"Verify correct UTC to local time conversion" \
|
|
|
393
|
"QuickTime/Apple media files with UTC timestamps" \
|
|
|
394
|
"$command" \
|
|
|
395
|
"$result"
|
|
|
396
|
}
|
|
|
397
|
|
|
|
398
|
# Test Case 5: Subdirectory Processing Test
|
|
|
399
|
run_subdirectory_processing_test() {
|
|
|
400
|
print_color "$GREEN" "=== Running Test 5: Subdirectory Processing Test ==="
|
|
|
401
|
|
|
|
402
|
clean_test_dir
|
|
|
403
|
create_test_dirs
|
|
|
404
|
|
|
|
405
|
# Create nested directory structure
|
|
|
406
|
mkdir -p "$SOURCE_DIR/level1/level2"
|
|
|
407
|
copy_sample_files "media/sortable" "$SOURCE_DIR/level1/level2"
|
|
|
408
|
|
|
|
409
|
# Capture pre-test state
|
|
|
410
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
411
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
412
|
|
|
|
413
|
# Run test
|
|
|
414
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" -v"
|
|
|
415
|
local result=0
|
|
|
416
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
417
|
|
|
|
418
|
# Capture post-test state
|
|
|
419
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
420
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
421
|
|
|
|
422
|
# Generate report
|
|
|
423
|
generate_test_report \
|
|
|
424
|
"Subdirectory_Processing" \
|
|
|
425
|
"Testing processing of files in nested subdirectories" \
|
|
|
426
|
"Verify recursive file discovery and processing" \
|
|
|
427
|
"Files in nested directory structure (level1/level2/)" \
|
|
|
428
|
"$command" \
|
|
|
429
|
"$result"
|
|
|
430
|
}
|
|
|
431
|
|
|
|
432
|
# Test Case 6: Keep Empty Directories Test
|
|
|
433
|
run_keep_empty_dirs_test() {
|
|
|
434
|
print_color "$GREEN" "=== Running Test 6: Keep Empty Directories Test ==="
|
|
|
435
|
|
|
|
436
|
clean_test_dir
|
|
|
437
|
create_test_dirs
|
|
|
438
|
|
|
|
439
|
# Create directory structure with some empty dirs
|
|
|
440
|
mkdir -p "$SOURCE_DIR/sortable" "$SOURCE_DIR/empty1" "$SOURCE_DIR/empty2"
|
|
|
441
|
copy_sample_files "media/sortable" "$SOURCE_DIR/sortable"
|
|
|
442
|
|
|
|
443
|
# Capture pre-test state
|
|
|
444
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
445
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_before.txt" "destination"
|
|
|
446
|
|
|
|
447
|
# Run test with --keep-empty-dirs
|
|
|
448
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$DEST_DIR\" --keep-empty-dirs -v"
|
|
|
449
|
local result=0
|
|
|
450
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
451
|
|
|
|
452
|
# Capture post-test state
|
|
|
453
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
454
|
capture_state "$DEST_DIR" "$TEST_DIR/dest_after.txt" "destination"
|
|
|
455
|
|
|
|
456
|
# Generate report
|
|
|
457
|
generate_test_report \
|
|
|
458
|
"Keep_Empty_Directories" \
|
|
|
459
|
"Testing --keep-empty-dirs functionality" \
|
|
|
460
|
"Verify empty directory preservation when flag is used" \
|
|
|
461
|
"Directory structure with sortable files and empty directories" \
|
|
|
462
|
"$command" \
|
|
|
463
|
"$result"
|
|
|
464
|
}
|
|
|
465
|
|
|
|
466
|
# Test Case 7: Source Only Test
|
|
|
467
|
run_source_only_test() {
|
|
|
468
|
print_color "$GREEN" "=== Running Test 7: Source Only Test ==="
|
|
|
469
|
|
|
|
470
|
clean_test_dir
|
|
|
471
|
create_test_dirs
|
|
|
472
|
|
|
|
473
|
# Setup test files
|
|
|
474
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
475
|
|
|
|
476
|
# Capture pre-test state
|
|
|
477
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
478
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_before.txt" "auto-destination"
|
|
|
479
|
|
|
|
480
|
# Run test with only source parameter
|
|
|
481
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -v"
|
|
|
482
|
local result=0
|
|
|
483
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
484
|
|
|
|
485
|
# Capture post-test state
|
|
|
486
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
487
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_after.txt" "auto-destination"
|
|
|
488
|
|
|
|
489
|
# Generate report
|
|
|
490
|
generate_test_report \
|
|
|
491
|
"Source_Only_Test" \
|
|
|
492
|
"Testing processing with only source parameter" \
|
|
|
493
|
"Verify automatic creation of sorted subdirectory" \
|
|
|
494
|
"Sample media files, no explicit destination specified" \
|
|
|
495
|
"$command" \
|
|
|
496
|
"$result"
|
|
|
497
|
}
|
|
|
498
|
|
|
Bogdan Timofte
authored
3 weeks ago
|
499
|
# Test Case 8: Destination Inside Source Test
|
|
|
500
|
run_destination_inside_source_test() {
|
|
|
501
|
print_color "$GREEN" "=== Running Test 8: Destination Inside Source Test ==="
|
|
|
502
|
|
|
|
503
|
clean_test_dir
|
|
|
504
|
create_test_dirs
|
|
|
505
|
|
|
|
506
|
# Setup test files
|
|
|
507
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
508
|
|
|
|
509
|
# Capture pre-test state
|
|
|
510
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
511
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_before.txt" "destination-inside-source"
|
|
|
512
|
|
|
|
513
|
# Run test with destination explicitly inside source
|
|
|
514
|
local command="\"$MEDIA_IMPORTER\" -s \"$SOURCE_DIR\" -d \"$SOURCE_DIR/sorted\" -v"
|
|
|
515
|
local result=0
|
|
|
516
|
run_test_command "$command" "$TEST_DIR/import_log.txt" || result=$?
|
|
|
517
|
|
|
|
518
|
# Guard 1: no files should remain outside sorted for sortable-only dataset
|
|
|
519
|
local outside_count
|
|
|
520
|
outside_count=$(find "$SOURCE_DIR" -type f ! -path "$SOURCE_DIR/sorted/*" | wc -l | tr -d ' ')
|
|
|
521
|
if [[ "$outside_count" != "0" ]]; then
|
|
|
522
|
echo "Destination exclusion check failed: found $outside_count file(s) outside sorted" >> "$TEST_DIR/import_log.txt"
|
|
|
523
|
result=1
|
|
|
524
|
fi
|
|
|
525
|
|
|
|
526
|
# Guard 2: destination exclusion should prevent sorted/sorted recursion
|
|
|
527
|
local recursive_sorted_count
|
|
|
528
|
recursive_sorted_count=$(find "$SOURCE_DIR/sorted" -type d -path "*/sorted/sorted*" 2>/dev/null | wc -l | tr -d ' ')
|
|
|
529
|
if [[ "$recursive_sorted_count" != "0" ]]; then
|
|
|
530
|
echo "Destination recursion check failed: found nested sorted/sorted directories" >> "$TEST_DIR/import_log.txt"
|
|
|
531
|
result=1
|
|
|
532
|
fi
|
|
|
533
|
|
|
|
534
|
# Capture post-test state
|
|
|
535
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
536
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_after.txt" "destination-inside-source"
|
|
|
537
|
|
|
|
538
|
# Generate report
|
|
|
539
|
generate_test_report \
|
|
|
540
|
"Destination_Inside_Source" \
|
|
|
541
|
"Testing explicit destination inside source directory" \
|
|
|
542
|
"Verify destination exclusion and no sorted/sorted recursion" \
|
|
|
543
|
"Sortable sample media with destination set to source/sorted" \
|
|
|
544
|
"$command" \
|
|
|
545
|
"$result"
|
|
|
546
|
}
|
|
|
547
|
|
|
|
548
|
# Test Case 9: Verify Mode Test
|
|
|
549
|
run_verify_mode_test() {
|
|
|
550
|
print_color "$GREEN" "=== Running Test 9: Verify Mode Test ==="
|
|
|
551
|
|
|
|
552
|
clean_test_dir
|
|
|
553
|
create_test_dirs
|
|
|
554
|
|
|
|
555
|
# Setup test files
|
|
|
556
|
copy_sample_files "media/sortable" "$SOURCE_DIR"
|
|
|
557
|
|
|
|
558
|
# Capture pre-test state
|
|
|
559
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_before.txt" "source"
|
|
|
560
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_before.txt" "auto-destination"
|
|
|
561
|
|
|
|
562
|
local log_file="$TEST_DIR/import_log.txt"
|
|
|
563
|
local result=0
|
|
|
564
|
: > "$log_file"
|
|
|
565
|
|
|
|
566
|
local command_default="cd \"$SOURCE_DIR\" && \"$MEDIA_IMPORTER\" --dry-run"
|
|
|
567
|
local command_strict="cd \"$SOURCE_DIR\" && \"$MEDIA_IMPORTER\" --dry-run --verify-mode strict"
|
|
|
568
|
local command="$command_default && $command_strict"
|
|
|
569
|
|
|
|
570
|
echo "$command_default" >> "$log_file"
|
|
|
571
|
echo "" >> "$log_file"
|
|
|
572
|
echo "=== DEFAULT VERIFY MODE OUTPUT ===" >> "$log_file"
|
|
|
573
|
if eval "$command_default" >> "$log_file" 2>&1; then
|
|
|
574
|
if ! grep -q "Verify mode:[[:space:]]*size" "$log_file"; then
|
|
|
575
|
echo "Expected default verify mode 'size' not found in output" >> "$log_file"
|
|
|
576
|
result=1
|
|
|
577
|
fi
|
|
|
578
|
else
|
|
|
579
|
result=1
|
|
|
580
|
fi
|
|
|
581
|
|
|
|
582
|
echo "" >> "$log_file"
|
|
|
583
|
echo "$command_strict" >> "$log_file"
|
|
|
584
|
echo "" >> "$log_file"
|
|
|
585
|
echo "=== STRICT VERIFY MODE OUTPUT ===" >> "$log_file"
|
|
|
586
|
if eval "$command_strict" >> "$log_file" 2>&1; then
|
|
|
587
|
if ! grep -q "Verify mode:[[:space:]]*strict" "$log_file"; then
|
|
|
588
|
echo "Expected strict verify mode not found in output" >> "$log_file"
|
|
|
589
|
result=1
|
|
|
590
|
fi
|
|
|
591
|
else
|
|
|
592
|
result=1
|
|
|
593
|
fi
|
|
|
594
|
|
|
|
595
|
if [[ $result -eq 0 ]]; then
|
|
|
596
|
echo "" >> "$log_file"
|
|
|
597
|
echo "=== COMMAND COMPLETED SUCCESSFULLY ===" >> "$log_file"
|
|
|
598
|
else
|
|
|
599
|
echo "" >> "$log_file"
|
|
|
600
|
echo "=== COMMAND FAILED ===" >> "$log_file"
|
|
|
601
|
fi
|
|
|
602
|
|
|
|
603
|
# Capture post-test state
|
|
|
604
|
capture_state "$SOURCE_DIR" "$TEST_DIR/source_after.txt" "source"
|
|
|
605
|
capture_state "$SOURCE_DIR/sorted" "$TEST_DIR/dest_after.txt" "auto-destination"
|
|
|
606
|
|
|
|
607
|
# Generate report
|
|
|
608
|
generate_test_report \
|
|
|
609
|
"Verify_Mode" \
|
|
|
610
|
"Testing verify-mode defaults and strict override" \
|
|
|
611
|
"Verify default mode is size and strict mode is accepted" \
|
|
|
612
|
"Sample sortable media in source-only dry-run mode" \
|
|
|
613
|
"$command" \
|
|
|
614
|
"$result"
|
|
|
615
|
}
|
|
|
616
|
|
|
Bogdan Timofte
authored
8 months ago
|
617
|
# Function to show menu
|
|
|
618
|
show_menu() {
|
|
|
619
|
echo ""
|
|
|
620
|
print_color "$GREEN" "Media Importer Test Runner"
|
|
|
621
|
echo "=========================="
|
|
|
622
|
echo ""
|
|
|
623
|
echo "Available Tests:"
|
|
|
624
|
echo "0. Basic Functionality Test"
|
|
|
625
|
echo "1. Unimportable Files Test"
|
|
|
626
|
echo "2. Mixed Content Test"
|
|
|
627
|
echo "3. Safety Protections Test"
|
|
|
628
|
echo "4. UTC Conversion Test"
|
|
|
629
|
echo "5. Subdirectory Processing Test"
|
|
|
630
|
echo "6. Keep Empty Directories Test"
|
|
|
631
|
echo "7. Source Only Test"
|
|
Bogdan Timofte
authored
3 weeks ago
|
632
|
echo "8. Destination Inside Source Test"
|
|
|
633
|
echo "9. Verify Mode Test"
|
|
|
634
|
echo "10. Run All Tests"
|
|
Bogdan Timofte
authored
8 months ago
|
635
|
echo "q. Quit"
|
|
|
636
|
echo ""
|
|
Bogdan Timofte
authored
3 weeks ago
|
637
|
echo -n "Select test to run (0-10, q to quit): "
|
|
Bogdan Timofte
authored
8 months ago
|
638
|
}
|
|
|
639
|
|
|
|
640
|
# Function to run all tests
|
|
|
641
|
run_all_tests() {
|
|
|
642
|
print_color "$GREEN" "Running all tests sequentially..."
|
|
|
643
|
|
|
|
644
|
run_basic_functionality_test
|
|
|
645
|
echo ""
|
|
|
646
|
run_unimportable_files_test
|
|
|
647
|
echo ""
|
|
|
648
|
run_mixed_content_test
|
|
|
649
|
echo ""
|
|
|
650
|
run_safety_protections_test
|
|
|
651
|
echo ""
|
|
|
652
|
run_utc_conversion_test
|
|
|
653
|
echo ""
|
|
|
654
|
run_subdirectory_processing_test
|
|
|
655
|
echo ""
|
|
|
656
|
run_keep_empty_dirs_test
|
|
|
657
|
echo ""
|
|
|
658
|
run_source_only_test
|
|
Bogdan Timofte
authored
3 weeks ago
|
659
|
echo ""
|
|
|
660
|
run_destination_inside_source_test
|
|
|
661
|
echo ""
|
|
|
662
|
run_verify_mode_test
|
|
Bogdan Timofte
authored
8 months ago
|
663
|
|
|
|
664
|
print_color "$GREEN" "All tests completed!"
|
|
|
665
|
}
|
|
|
666
|
|
|
|
667
|
# Main menu loop
|
|
|
668
|
main() {
|
|
|
669
|
while true; do
|
|
|
670
|
show_menu
|
|
|
671
|
read -r choice
|
|
|
672
|
|
|
|
673
|
case $choice in
|
|
|
674
|
0)
|
|
|
675
|
run_basic_functionality_test
|
|
|
676
|
;;
|
|
|
677
|
1)
|
|
|
678
|
run_unimportable_files_test
|
|
|
679
|
;;
|
|
|
680
|
2)
|
|
|
681
|
run_mixed_content_test
|
|
|
682
|
;;
|
|
|
683
|
3)
|
|
|
684
|
run_safety_protections_test
|
|
|
685
|
;;
|
|
|
686
|
4)
|
|
|
687
|
run_utc_conversion_test
|
|
|
688
|
;;
|
|
|
689
|
5)
|
|
|
690
|
run_subdirectory_processing_test
|
|
|
691
|
;;
|
|
|
692
|
6)
|
|
|
693
|
run_keep_empty_dirs_test
|
|
|
694
|
;;
|
|
|
695
|
7)
|
|
|
696
|
run_source_only_test
|
|
|
697
|
;;
|
|
|
698
|
8)
|
|
Bogdan Timofte
authored
3 weeks ago
|
699
|
run_destination_inside_source_test
|
|
|
700
|
;;
|
|
|
701
|
9)
|
|
|
702
|
run_verify_mode_test
|
|
|
703
|
;;
|
|
|
704
|
10)
|
|
Bogdan Timofte
authored
8 months ago
|
705
|
run_all_tests
|
|
|
706
|
;;
|
|
|
707
|
q|Q)
|
|
|
708
|
print_color "$GREEN" "Exiting test runner."
|
|
|
709
|
exit 0
|
|
|
710
|
;;
|
|
|
711
|
*)
|
|
Bogdan Timofte
authored
3 weeks ago
|
712
|
print_color "$RED" "Invalid choice. Please select 0-10 or q to quit."
|
|
Bogdan Timofte
authored
8 months ago
|
713
|
;;
|
|
|
714
|
esac
|
|
|
715
|
|
|
|
716
|
echo ""
|
|
|
717
|
echo -n "Press Enter to continue..."
|
|
|
718
|
read -r
|
|
|
719
|
done
|
|
|
720
|
}
|
|
|
721
|
|
|
|
722
|
# Check if script exists
|
|
|
723
|
if [[ ! -f "$MEDIA_IMPORTER" ]]; then
|
|
|
724
|
print_color "$RED" "Error: $MEDIA_IMPORTER not found!"
|
|
|
725
|
exit 1
|
|
|
726
|
fi
|
|
|
727
|
|
|
|
728
|
# Check if samples directory exists
|
|
|
729
|
if [[ ! -d "$SAMPLES_DIR" ]]; then
|
|
|
730
|
print_color "$YELLOW" "Warning: $SAMPLES_DIR not found. Some tests may not work properly."
|
|
|
731
|
fi
|
|
|
732
|
|
|
|
733
|
# Run main menu if no arguments provided
|
|
|
734
|
if [[ $# -eq 0 ]]; then
|
|
|
735
|
main
|
|
|
736
|
else
|
|
|
737
|
# Handle command line arguments
|
|
|
738
|
case "$1" in
|
|
|
739
|
"basic"|"0")
|
|
|
740
|
run_basic_functionality_test
|
|
|
741
|
;;
|
|
|
742
|
"unimportable"|"1")
|
|
|
743
|
run_unimportable_files_test
|
|
|
744
|
;;
|
|
|
745
|
"mixed"|"2")
|
|
|
746
|
run_mixed_content_test
|
|
|
747
|
;;
|
|
|
748
|
"safety"|"3")
|
|
|
749
|
run_safety_protections_test
|
|
|
750
|
;;
|
|
|
751
|
"utc"|"4")
|
|
|
752
|
run_utc_conversion_test
|
|
|
753
|
;;
|
|
|
754
|
"subdir"|"5")
|
|
|
755
|
run_subdirectory_processing_test
|
|
|
756
|
;;
|
|
|
757
|
"keep-empty"|"6")
|
|
|
758
|
run_keep_empty_dirs_test
|
|
|
759
|
;;
|
|
|
760
|
"source-only"|"7")
|
|
|
761
|
run_source_only_test
|
|
|
762
|
;;
|
|
Bogdan Timofte
authored
3 weeks ago
|
763
|
"dest-in-source"|"8")
|
|
|
764
|
run_destination_inside_source_test
|
|
|
765
|
;;
|
|
|
766
|
"verify-mode"|"9")
|
|
|
767
|
run_verify_mode_test
|
|
|
768
|
;;
|
|
|
769
|
"all"|"10")
|
|
Bogdan Timofte
authored
8 months ago
|
770
|
run_all_tests
|
|
|
771
|
;;
|
|
|
772
|
"clean")
|
|
|
773
|
clean_test_dir
|
|
|
774
|
;;
|
|
|
775
|
"setup")
|
|
|
776
|
create_test_dirs
|
|
|
777
|
;;
|
|
|
778
|
*)
|
|
|
779
|
print_color "$RED" "Unknown test: $1"
|
|
Bogdan Timofte
authored
3 weeks ago
|
780
|
echo "Usage: $0 [basic|unimportable|mixed|safety|utc|subdir|keep-empty|source-only|dest-in-source|verify-mode|all|clean|setup] or [0-10]"
|
|
Bogdan Timofte
authored
8 months ago
|
781
|
exit 1
|
|
|
782
|
;;
|
|
|
783
|
esac
|
|
|
784
|
fi
|