pub struct TestContextBuilder { /* private fields */ }Expand description
Builds a deterministic RequestContext for tests.
Starts from a seeded request id and a pinned arrival time, then layers on the
optional fields a test sets. Construct via TestContextBuilder::new.
use klauthed_testing::context::TestContextBuilder;
let ctx = TestContextBuilder::new()
.seed(42)
.tenant("acme")
.locale("tr-TR")
.correlation_id("trace-1")
.metadata("feature_flag", "beta")
.build();
assert_eq!(ctx.tenant(), Some("acme"));
assert_eq!(ctx.locale(), Some("tr-TR"));
assert_eq!(ctx.correlation_id(), Some("trace-1"));
assert_eq!(ctx.metadata_get("feature_flag"), Some("beta"));Implementations§
Source§impl TestContextBuilder
impl TestContextBuilder
Sourcepub fn seed(self, seed: u64) -> Self
pub fn seed(self, seed: u64) -> Self
Set the seed used to derive the (deterministic) request id.
Sourcepub fn received_at(self, at: Timestamp) -> Self
pub fn received_at(self, at: Timestamp) -> Self
Pin the arrival time (received_at).
Sourcepub fn principal(self, principal: impl Into<String>) -> Self
pub fn principal(self, principal: impl Into<String>) -> Self
Set the authenticated principal / subject.
Sourcepub fn locale(self, locale: impl Into<String>) -> Self
pub fn locale(self, locale: impl Into<String>) -> Self
Set the preferred locale (BCP-47, e.g. en-US).
Sourcepub fn correlation_id(self, id: impl Into<String>) -> Self
pub fn correlation_id(self, id: impl Into<String>) -> Self
Set the inbound correlation / trace id.
Sourcepub fn metadata(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn metadata(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a metadata entry.
Sourcepub fn request_id(&self) -> RequestId
pub fn request_id(&self) -> RequestId
The seeded RequestId this builder will use.
Sourcepub fn build(self) -> RequestContext
pub fn build(self) -> RequestContext
Build the RequestContext.
Trait Implementations§
Source§impl Clone for TestContextBuilder
impl Clone for TestContextBuilder
Source§fn clone(&self) -> TestContextBuilder
fn clone(&self) -> TestContextBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TestContextBuilder
impl Debug for TestContextBuilder
Auto Trait Implementations§
impl Freeze for TestContextBuilder
impl RefUnwindSafe for TestContextBuilder
impl Send for TestContextBuilder
impl Sync for TestContextBuilder
impl Unpin for TestContextBuilder
impl UnsafeUnpin for TestContextBuilder
impl UnwindSafe for TestContextBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more