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
impl UnitTestBuilder
Sourcepub fn with_config<S: Into<String>>(self, config: S) -> Self
pub fn with_config<S: Into<String>>(self, config: S) -> Self
Sets the policy configuration JSON. Returns self for method chaining.
Sourcepub fn with_backend<B: Backend + 'static>(self, backend: B) -> Self
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.
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.
Sourcepub fn with_http_upstream<K: Into<String>, B: Backend + 'static>(
self,
upstream: K,
backend: B,
) -> Self
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.
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.
Sourcepub fn with_grpc_upstream<K: Into<String>, B: GrpcBackend + 'static>(
self,
upstream: K,
backend: B,
) -> Self
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.
Sourcepub fn metadata<F: FnOnce(&mut Metadata)>(self, function: F) -> Self
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.
Sourcepub fn with_identity_management<K: Into<String>, B: Backend + 'static>(
self,
url: K,
backend: B,
) -> Self
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.
Sourcepub fn with_entrypoint<C, T, E: Entrypoint<C, T> + Clone + 'static>(
self,
entrypoint: E,
) -> UnitTest
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.