Skip to content

v0.2.4

Latest

Choose a tag to compare

@goddtriffin goddtriffin released this 27 Sep 20:29
3d21b3e

Lets a consuming project test the real router without binding a socket:
drive it with tower::ServiceExt::oneshot and get exactly what production
serves — pages, the 404, the well-known documents, the cache policy, tracing and
the body limit. Previously run was the only thing that assembled the router,
so every handler typed on the library's state was testable only over a real
port.

Testing

  • WebServer::into_router(shutdown) returns the finished Router: everything
    run does before binding. run and into_router share one assembly path, so
    the router a test drives cannot drift from the one that ships.
  • Boot validation still runs. Ok means run would have started; a site
    whose asset build never ran fails here exactly as it would in a deploy. There
    is no lenient test mode.
  • It does not require S: AppShutdown, and it never runs the drain window or
    on_shutdown. shutdown.trigger() reaches only handlers listening on
    state.shutdown().
  • A server without frontend boots from any root, so a single handler can be
    tested against a real WebServerState with no fixtures:
    WebServer::with_state(..).merge(routes).into_router(Shutdown::manual()).

Configuration

  • WebServer::root_dir(path) sets where html/, static/ and
    cache-buster.json are read from, at boot and per request. It defaults to the
    working directory, so existing servers are unaffected. cargo test runs from
    the crate's own directory rather than the built site; point root_dir at the
    build output — e.g. concat!(env!("CARGO_MANIFEST_DIR"), "/../bin") from a
    workspace member. It is per server, so parallel tests can use different trees.
  • The build-time asset pipeline still runs in the working directory.

Template

  • template-web-server is now a library plus a binary, and its tests drive the
    built site through into_router. The README's Testing with into_router
    section describes the pattern.
  • make assets builds bin/; make dev and make test both depend on it.

No public signature changed; upgrading needs no edits.

Full Changelog: v0.2.3...v0.2.4