quivr/.run_tests.sh
Stan Girard 380cf82706
feat: quivr core 0.1 (#2970)
# Description


# Testing backend 

## Docker setup
1. Copy `.env.example` to `.env`. Some env variables were added :
EMBEDDING_DIM
2. Apply supabase migratrions : 
```sh
supabase stop
supabase db reset
supabase start
```
3. Start backend containers
```
make dev
```
## Local setup 
You can also run backend without docker.
1. Install [`rye`](https://rye.astral.sh/guide/installation/). Choose
the managed python version and set the version to 3.11
2. Run the following: 
```
cd quivr/backend
rye sync
```
3. Source `.venv` virtual env : `source .venv/bin/activate`
4. Run the backend, make sure you are running redis and supabase
API: 
```
LOG_LEVEL=debug uvicorn quivr_api.main:app --log-level debug --reload --host 0.0.0.0 --port 5050 --workers 1
```
Worker: 
```
LOG_LEVEL=debug celery -A quivr_worker.celery_worker worker -l info -E --concurrency 1
```
Notifier: 
```
LOG_LEVEL=debug python worker/quivr_worker/celery_monitor.py
```

---------

Co-authored-by: chloedia <chloedaems0@gmail.com>
Co-authored-by: aminediro <aminedirhoussi1@gmail.com>
Co-authored-by: Antoine Dewez <44063631+Zewed@users.noreply.github.com>
Co-authored-by: Chloé Daems <73901882+chloedia@users.noreply.github.com>
Co-authored-by: Zewed <dewez.antoine2@gmail.com>
2024-09-02 10:20:53 +02:00

106 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -e
## TESTS SUITES
test_suites=(
"Backend Core:cd backend/core && tox -p auto"
"Worker:cd backend && pytest worker"
"API:cd backend && pytest api"
)
# Check if gum is installed
if ! command -v gum &>/dev/null; then
echo "gum is not installed. Please install it with 'brew install gum'."
exit 1
fi
root_dir=$(pwd)
# Function to check if Tika server is running
check_tika_server() {
if nc -z localhost 9998 >/dev/null 2>&1; then
return 0
else
gum style --foreground 196 "Error: Tika server is not running on port 9998."
gum style --foreground 226 "Please start the Tika server before running the tests."
gum style --foreground 226 "Run 'docker run -d -p 9998:9998 apache/tika' to start the Tika server."
return 1
fi
}
# select test suites to run, either all or one of the following
get_test_suites_to_run() {
gum style --bold "Select test suites to run:"
options=("All" "${test_suites[@]%%:*}")
selected=$(gum choose "${options[@]}")
if [[ "$selected" == "All" ]]; then
gum style --bold "Running all test suites"
else
# Find the matching test suite
for suite in "${test_suites[@]}"; do
if [[ "${suite%%:*}" == "$selected" ]]; then
test_suites=("$suite")
break
fi
done
fi
}
# Function to run a single test suite
run_test_suite() {
local suite_name=$1
local command=$2
local exit_code
gum style --border normal --border-foreground 99 --padding "1 2" --bold "$suite_name Tests"
eval "$command"
exit_code=$?
cd "$root_dir"
if [ $exit_code -eq 0 ]; then
gum style --foreground 46 "$suite_name Tests: PASSED"
else
gum style --foreground 196 "$suite_name Tests: FAILED"
fi
return $exit_code
}
run_tests() {
get_test_suites_to_run
# gum spin --spinner dot --title "Running tests..." -- sleep 1
local all_passed=true
local results=()
for suite in "${test_suites[@]}"; do
IFS=':' read -r suite_name suite_command <<< "$suite"
if ! run_test_suite "$suite_name" "$suite_command"; then
all_passed=false
fi
results+=("$suite_name:$?")
done
# Print summary of test results
gum style --border double --border-foreground 99 --padding "1 2" --bold "Test Summary"
for result in "${results[@]}"; do
IFS=':' read -r suite_name exit_code <<< "$result"
if [ "$exit_code" -eq 0 ]; then
gum style --foreground 46 "$suite_name: PASSED"
else
gum style --foreground 196 "$suite_name: FAILED"
fi
done
# Return overall exit code
$all_passed
}
# Main execution
if check_tika_server; then
run_tests
exit $?
else
exit 1
fi