Integration tests: drive the real --web server end-to-end (2.1)
Unit tests cover parsers/resolvers but not whether the axum handlers, SQLite layer, and config persistence actually wire together. New tests/api.rs spawns the compiled binary in --web mode against a scratch library dir and exercises the real HTTP API the way a browser does — no network / yt-dlp needed (every endpoint here is local state). Coverage: index + /api/library served; ETag conditional GET → 304; settings round-trip (POST → GET reflects → config.toml on disk updated); folder CRUD + the self-parent cycle guard (→ 400); notes upsert/delete; channel-options store + is_empty() clear; backup/db returns a real SQLite file. HTTP via curl (transparently handles the server's gzip + chunked encoding; already a CI dependency) with a graceful skip if curl is absent. Each test gets its own server, port (bind :0 to grab a free one), and tempdir, so they run in parallel and clean up on drop. Added .forgejo/workflows/test.yml so `cargo test` (unit + integration) runs on every push/PR — the release workflow only fired on tags. 105 tests pass (98 unit + 7 integration). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
39850059cb
commit
7906d7d07f
2 changed files with 355 additions and 0 deletions
40
.forgejo/workflows/test.yml
Normal file
40
.forgejo/workflows/test.yml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Build + test on every push / PR. The release workflow only fires on
|
||||
# tags, so this is the everyday safety net: it compiles the binary and
|
||||
# runs the full suite, including the tests/api.rs integration tests that
|
||||
# spawn the real `--web` server and drive its HTTP API.
|
||||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: rust:1.85-bookworm
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install build dependencies
|
||||
# libxcb headers are needed to *link* the eframe/winit GUI even
|
||||
# though the integration tests only run the headless --web server.
|
||||
# curl is what the integration tests use as their HTTP client.
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev \
|
||||
libxkbcommon-dev curl ca-certificates
|
||||
|
||||
- name: Cache cargo registry + build
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: cargo-test-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
|
||||
|
||||
- name: Test (unit + integration)
|
||||
run: cargo test --locked
|
||||
Loading…
Add table
Add a link
Reference in a new issue