120 lines
3.0 KiB
YAML
120 lines
3.0 KiB
YAML
name: Integration Tests
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
- main
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
DATABASE_URL: postgres://postgres:postgres@localhost:5432/readur_test
|
|
|
|
jobs:
|
|
integration-tests:
|
|
runs-on: ubuntu-latest
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: readur_test
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install system dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
tesseract-ocr \
|
|
tesseract-ocr-eng \
|
|
libtesseract-dev \
|
|
libleptonica-dev \
|
|
pkg-config \
|
|
libclang-dev \
|
|
clang
|
|
|
|
- name: Setup Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
- name: Cache cargo registry
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
target
|
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-
|
|
|
|
- name: Build readur binary
|
|
run: cargo build --release
|
|
|
|
- name: Start readur server
|
|
run: |
|
|
./target/release/readur &
|
|
echo $! > readur.pid
|
|
env:
|
|
DATABASE_URL: ${{ env.DATABASE_URL }}
|
|
JWT_SECRET: test-secret-key
|
|
PORT: 8000
|
|
UPLOAD_PATH: ./uploads
|
|
WATCH_PATH: ./watch
|
|
|
|
- name: Wait for server to be ready
|
|
run: |
|
|
for i in {1..30}; do
|
|
if curl -f http://localhost:8000/api/health > /dev/null 2>&1; then
|
|
echo "Readur server is ready"
|
|
break
|
|
fi
|
|
echo "Waiting for readur server... ($i/30)"
|
|
sleep 2
|
|
done
|
|
|
|
- name: Wait for PostgreSQL to be ready
|
|
run: |
|
|
until pg_isready -h localhost -p 5432 -U postgres; do
|
|
echo "Waiting for PostgreSQL..."
|
|
sleep 1
|
|
done
|
|
echo "PostgreSQL is ready!"
|
|
|
|
- name: Verify database connection
|
|
run: |
|
|
echo "Testing database connection..."
|
|
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d readur_test -c "SELECT version();"
|
|
echo "Database connection successful!"
|
|
|
|
- name: Run integration tests
|
|
run: |
|
|
cargo test --test '*' -- --test-threads=1
|
|
env:
|
|
DATABASE_URL: ${{ env.DATABASE_URL }}
|
|
TEST_DATABASE_URL: ${{ env.DATABASE_URL }}
|
|
RUST_LOG: debug
|
|
RUST_BACKTRACE: 1
|
|
|
|
- name: Stop readur server
|
|
if: always()
|
|
run: |
|
|
if [ -f readur.pid ]; then
|
|
kill $(cat readur.pid) || true
|
|
rm readur.pid
|
|
fi |