Skip to main content

UnitTest

Struct UnitTest 

Source
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

Source

pub fn restart(&mut self)

Simulate a system restart by cleaning all contexts and keeping the configured upstreams.

Source

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.

Source

pub fn add_contract_data<I, N, S, Sla>( &mut self, id: I, name: N, secret: Option<S>, sla_id: Option<Sla>, )
where I: Into<String>, N: Into<String>, S: Into<String>, Sla: Into<String>,

Adds contract data for client ID enforcement testing.

This simulates registered API contracts in the Anypoint Platform.

Source

pub fn remove_contract_data<I>(&mut self, id: I)
where I: Into<String>,

Removes contract data for client ID enforcement testing.

Source

pub fn add_ldap_data<U, P>( &mut self, config: Option<UnitLdapConfig>, user: U, pass: P, )
where U: Into<String>, P: Into<String>,

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 for user.
Source

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.

Source

pub fn tick(&mut self)

Advances the simulated time by one tick interval.

This triggers on_tick callbacks and processes any pending requests.

Source

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.

Source

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.

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.