feat: implement comprehensive test optimization
- Add gotestsum for real-time test progress visibility - Parallelize 174 tests across 14 files for faster execution - Add -short mode support skipping 21 heavy integration tests - Create testutil/db.go helper for future transaction rollbacks - Fix data race in notification_service_test.go - Fix 4 CrowdSec LAPI test failures with permissive validator Performance improvements: - Tests now run in parallel (174 tests with t.Parallel()) - Quick feedback loop via -short mode - Zero race conditions detected - Coverage maintained at 87.7% Closes test optimization initiative
This commit is contained in:
34
.github/skills/test-backend-unit-scripts/run.sh
vendored
34
.github/skills/test-backend-unit-scripts/run.sh
vendored
@@ -36,12 +36,30 @@ cd "${PROJECT_ROOT}/backend"
|
||||
# Execute tests
|
||||
log_step "EXECUTION" "Running backend unit tests"
|
||||
|
||||
# Run go test with all passed arguments
|
||||
if go test "$@" ./...; then
|
||||
log_success "Backend unit tests passed"
|
||||
exit 0
|
||||
else
|
||||
exit_code=$?
|
||||
log_error "Backend unit tests failed (exit code: ${exit_code})"
|
||||
exit "${exit_code}"
|
||||
# Check if short mode is enabled
|
||||
SHORT_FLAG=""
|
||||
if [[ "${CHARON_TEST_SHORT:-false}" == "true" ]]; then
|
||||
SHORT_FLAG="-short"
|
||||
log_info "Running in short mode (skipping integration and heavy network tests)"
|
||||
fi
|
||||
|
||||
# Run tests with gotestsum if available, otherwise fall back to go test
|
||||
if command -v gotestsum &> /dev/null; then
|
||||
if gotestsum --format pkgname -- $SHORT_FLAG "$@" ./...; then
|
||||
log_success "Backend unit tests passed"
|
||||
exit 0
|
||||
else
|
||||
exit_code=$?
|
||||
log_error "Backend unit tests failed (exit code: ${exit_code})"
|
||||
exit "${exit_code}"
|
||||
fi
|
||||
else
|
||||
if go test $SHORT_FLAG "$@" ./...; then
|
||||
log_success "Backend unit tests passed"
|
||||
exit 0
|
||||
else
|
||||
exit_code=$?
|
||||
log_error "Backend unit tests failed (exit code: ${exit_code})"
|
||||
exit "${exit_code}"
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user