pub struct TestHarness {Show 13 fields
pub router: Router,
pub harness: Harness,
pub mailer: FakeMailer,
pub captcha: FakeCaptcha,
pub rate_limiter: FakeRateLimiter,
pub clock: FixedClock,
pub kv: MemoryKeyValue,
pub http: FakeHttpClient,
pub defer: FakeDefer,
pub signer: Arc<HmacSigner>,
pub db: Arc<dyn Database>,
pub modules: Vec<Arc<dyn Module>>,
pub dialect: &'static str,
}Expand description
A harness with every port faked and a migrated database, migrations
applied per module on creation. The same database handle is wired
into the router and exposed for assertions — SQLite in memory by
default (TestHarness::new), or a throwaway Postgres 16 database
for the parity suite (TestHarness::with_database, issue #20).
Fields§
§router: RouterThe assembled router: hand it to crate::request.
harness: Harness§mailer: FakeMailer§captcha: FakeCaptcha§rate_limiter: FakeRateLimiter§clock: FixedClock§kv: MemoryKeyValue§http: FakeHttpClient§defer: FakeDefer§signer: Arc<HmacSigner>§db: Arc<dyn Database>The migrated database backing the Database port (shared with
the router — assertions see module writes). On Postgres every
call is marshalled onto the kit’s own runtime, so any executor
can drive it.
modules: Vec<Arc<dyn Module>>The modules passed in (for conformance access).
dialect: &'static strThe engine db runs against: "sqlite" or "postgres".
Implementations§
Source§impl TestHarness
impl TestHarness
Sourcepub fn new(modules: Vec<Box<dyn Module>>) -> Self
pub fn new(modules: Vec<Box<dyn Module>>) -> Self
Builds the harness (venture test-venture.test), applies every
module’s sqlite migrations to a fresh in-memory database, and
assembles the router.
§Panics
Panics when the harness cannot build (invalid module set) or a migration fails — exactly what a module test should surface.
Sourcepub fn with_ports(
modules: Vec<Box<dyn Module>>,
patch: impl FnOnce(&mut Ports),
) -> Self
pub fn with_ports( modules: Vec<Box<dyn Module>>, patch: impl FnOnce(&mut Ports), ) -> Self
TestHarness::new with a patch over the default ports: swap in a
token-checking FakeCaptcha, a scripted FakeRateLimiter, or a
MapConfig carrying ADMIN_TOKEN, after the standard fakes (and
the migrated database) are in place.
§Panics
Panics when the harness cannot build or a migration fails.
Sourcepub fn with_database(modules: Vec<Box<dyn Module>>, dialect: Dialect) -> Self
pub fn with_database(modules: Vec<Box<dyn Module>>, dialect: Dialect) -> Self
TestHarness::new over the chosen Dialect (issue #20):
Dialect::Sqlite is the in-memory default; Dialect::Postgres { url } creates a throwaway Postgres 16 database on that server,
applies every module’s migrations (the postgres set when
shipped, else the portable-linted sqlite set) and drops the
database when the harness drops. Requires building
cratefield-testing with the postgres feature.
§Panics
Panics when the harness cannot build, a migration fails, the
Postgres server is unreachable, or the postgres feature is off
and the Postgres dialect was requested anyway.
Sourcepub fn with_database_and_ports(
modules: Vec<Box<dyn Module>>,
dialect: Dialect,
patch: impl FnOnce(&mut Ports),
) -> Self
pub fn with_database_and_ports( modules: Vec<Box<dyn Module>>, dialect: Dialect, patch: impl FnOnce(&mut Ports), ) -> Self
TestHarness::with_database with a patch over the default
ports (the parity counterpart of TestHarness::with_ports).
§Panics
Panics for the same reasons as TestHarness::with_database.
Sourcepub fn all_dialects(
make_modules: impl Fn() -> Vec<Box<dyn Module>>,
) -> Vec<Self>
pub fn all_dialects( make_modules: impl Fn() -> Vec<Box<dyn Module>>, ) -> Vec<Self>
One harness per dialect available in the environment — the parity
loop (issue #20): for kit in TestHarness::all_dialects(make) { … } runs one test definition against SQLite and Postgres. The
factory runs once per dialect so every kit gets fresh module
instances: a module may carry per-build state (email-signup
parks its ModuleContext for the waitlist.confirmed handler),
and a shared instance would keep the first dialect’s context
alive in the next dialect’s router.
§Panics
Panics like TestHarness::with_database for any dialect built.
Sourcepub fn all_dialects_with_ports(
make_modules: impl Fn() -> Vec<Box<dyn Module>>,
patch: impl Fn(&mut Ports) + Clone,
) -> Vec<Self>
pub fn all_dialects_with_ports( make_modules: impl Fn() -> Vec<Box<dyn Module>>, patch: impl Fn(&mut Ports) + Clone, ) -> Vec<Self>
TestHarness::all_dialects with a port patch applied to every
kit. The patch runs once per dialect, so it must be a Fn over
cloneable captures (Arc handles), not a one-shot mover.
§Panics
Panics like TestHarness::with_database for any dialect built.
Sourcepub fn with_builder(
modules: Vec<Box<dyn Module>>,
configure: impl FnOnce(HarnessBuilder) -> HarnessBuilder,
patch: impl FnOnce(&mut Ports),
) -> Self
pub fn with_builder( modules: Vec<Box<dyn Module>>, configure: impl FnOnce(HarnessBuilder) -> HarnessBuilder, patch: impl FnOnce(&mut Ports), ) -> Self
TestHarness::with_ports with a hook over the HarnessBuilder
before it builds: mount a UI renderer (.ui(..)), add a template
override, anything the venture would do in harness.rs.
§Panics
Panics when the harness cannot build or a migration fails.