Skip to main content

TestHarness

Struct TestHarness 

Source
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: Router

The 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 str

The engine db runs against: "sqlite" or "postgres".

Implementations§

Source§

impl TestHarness

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for TestHarness

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more