Skip to main content

UnitTestBuilder

Struct UnitTestBuilder 

Source
pub struct UnitTestBuilder { /* private fields */ }
Expand description

A fluent builder for configuring and creating UnitTest instances.

This is the entry point for setting up unit tests. It allows configuring the policy under test, its configuration, and mocking external dependencies like HTTP and gRPC backends.

§Example

let mut tester = UnitTestBuilder::default()
    .with_config(json!({"key": "value"}).to_string())
    .with_backend(TraceBackend::new(UnitHttpResponse::new(200)))
    .with_http_upstream_from_authority("api.example.com", my_backend)
    .with_entrypoint(crate::configure);

Implementations§

Source§

impl UnitTestBuilder

Source

pub fn with_config<S: Into<String>>(self, config: S) -> Self

Sets the policy configuration JSON. Returns self for method chaining.

Source

pub fn with_backend<B: Backend + 'static>(self, backend: B) -> Self

Sets the default HTTP backend used when no specific upstream is matched. Returns self for method chaining.

Source

pub fn with_http_upstream_from_authority<K: AsRef<str>, B: Backend + 'static>( self, authority: K, backend: B, ) -> Self

Registers an HTTP upstream backend by authority (e.g., “api.example.com”).

The authority is automatically converted to the internal upstream service name format. Returns self for method chaining.

Source

pub fn with_http_upstream<K: Into<String>, B: Backend + 'static>( self, upstream: K, backend: B, ) -> Self

Registers an HTTP upstream backend by its full service name. Returns self for method chaining.

Source

pub fn with_grpc_upstream_from_authority<K: AsRef<str>, B: GrpcBackend + 'static>( self, authority: K, backend: B, ) -> Self

Registers a gRPC upstream backend by authority (e.g., “grpc.example.com”).

The authority is automatically converted to the internal upstream service name format. Returns self for method chaining.

Source

pub fn with_grpc_upstream<K: Into<String>, B: GrpcBackend + 'static>( self, upstream: K, backend: B, ) -> Self

Registers a gRPC upstream backend by its full service name. Returns self for method chaining.

Source

pub fn metadata<F: FnOnce(&mut Metadata)>(self, function: F) -> Self

Returns a mutable reference to the metadata that will be used for the test. Modify the values as desired. Modifying the values impact in the service registration process, if you’ll use this method make sure to do it before calling the with_*_upstream_from_authority methods.

Source

pub fn with_identity_management<K: Into<String>, B: Backend + 'static>( self, url: K, backend: B, ) -> Self

Sets the function to be used as the identity management backend. Returns self for method chaining.

Source

pub fn with_entrypoint<C, T, E: Entrypoint<C, T> + Clone + 'static>( self, entrypoint: E, ) -> UnitTest

Finalizes the builder and creates a UnitTest instance with the specified policy entrypoint.

This method consumes the builder and initializes the test environment.

Trait Implementations§

Source§

impl Default for UnitTestBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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<C, T> Extract<T> for C
where T: FromContext<C>,

Source§

type Error = <T as FromContext<C>>::Error

Source§

fn extract(&self) -> Result<T, <C as Extract<T>>::Error>

Source§

fn extract_always(&self) -> T
where Self: Extract<T, Error = Infallible>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.