pub struct UnitTest { /* private fields */ }Expand description
The main test orchestrator for running PDK policy unit tests.
This struct manages the Proxy-Wasm host stub, handles request lifecycles, and coordinates interactions between the policy under test and mock backends.
Created via UnitTestBuilder.
Implementations§
Source§impl UnitTest
impl UnitTest
Sourcepub fn restart(&mut self)
pub fn restart(&mut self)
Simulate a system restart by cleaning all contexts and keeping the configured upstreams.
Sourcepub fn set_chunk_size(&mut self, chunk_size: usize)
pub fn set_chunk_size(&mut self, chunk_size: usize)
Sets the chunk size for body processing.
Bodies larger than this size will be processed in multiple chunks.
Sourcepub fn add_contract_data<I, N, S, Sla>(
&mut self,
id: I,
name: N,
secret: Option<S>,
sla_id: Option<Sla>,
)
pub fn add_contract_data<I, N, S, Sla>( &mut self, id: I, name: N, secret: Option<S>, sla_id: Option<Sla>, )
Adds contract data for client ID enforcement testing.
This simulates registered API contracts in the Anypoint Platform.
Sourcepub fn remove_contract_data<I>(&mut self, id: I)
pub fn remove_contract_data<I>(&mut self, id: I)
Removes contract data for client ID enforcement testing.
Sourcepub fn add_ldap_data<U, P>(
&mut self,
config: Option<UnitLdapConfig>,
user: U,
pass: P,
)
pub fn add_ldap_data<U, P>( &mut self, config: Option<UnitLdapConfig>, user: U, pass: P, )
Registers a valid LDAP credential pair for use during testing.
If config is Some, the pair is matched only when the policy uses
LDAP connection parameters equal to that config. If config is None,
the pair acts as a wildcard and matches regardless of the LDAP config.
§Arguments
config- Optional LDAP server configuration to scope this credential to.user- The username that should be considered valid.pass- The password that should be considered valid foruser.
Sourcepub fn request_partial(&mut self, request: UnitHttpRequest) -> UnitTestRequest
pub fn request_partial(&mut self, request: UnitHttpRequest) -> UnitTestRequest
Sends a request through the policy and returns a handle to track its progress.
The returned UnitTestRequest can be polled to advance the request
through the policy lifecycle and eventually retrieve the response.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Advances the simulated time by one tick interval.
This triggers on_tick callbacks and processes any pending requests.
Sourcepub fn sleep(&mut self, duration: Duration)
pub fn sleep(&mut self, duration: Duration)
Advances the simulated time by the specified duration.
This will trigger multiple ticks if the duration spans multiple tick intervals.
Sourcepub fn request(&mut self, request: UnitHttpRequest) -> UnitHttpResponse
pub fn request(&mut self, request: UnitHttpRequest) -> UnitHttpResponse
Sends a request and blocks until the full response is received.
This is a convenience method that combines request_partial() with polling
until completion. Use this for simple synchronous test scenarios.