pdk-unit 1.8.0

PDK Unit Test Framework
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

//! # pdk-unit
//!
//! A unit testing framework for PDK (Policy Development Kit) policies that enables testing
//! Flex Gateway policies without requiring a running Envoy proxy or WebAssembly runtime.
//!
//! ## Overview
//!
//! `pdk-unit` provides a complete in-process testing solution for PDK policies by stubbing
//! the Proxy-Wasm host environment. This allows developers to write fast, deterministic
//! unit tests that verify policy behavior without the overhead of integration testing.
//!
//! ## Quick Start
//!
//! ```ignore
//! use pdk_unit::{UnitHttpRequest, UnitHttpResponse, UnitHttpMessage, UnitTestBuilder};
//!
//! #[test]
//! fn test_my_policy() {
//!     let mut tester = UnitTestBuilder::default()
//!         .with_config(r#"{"key": "value"}"#)
//!         .with_entrypoint(crate::configure);
//!
//!     let request = UnitHttpRequest::get()
//!         .with_header(":path", "/api/test");
//!
//!     let response = tester.request(request);
//!
//!     assert_eq!(response.status_code(), 200);
//! }
//! ```
//!
//! ## Core Components
//!
//! - [`UnitTestBuilder`] - Fluent builder for configuring test instances
//! - [`UnitTest`] - Main test orchestrator managing request lifecycles
//! - [`UnitTestRequest`] - Handle to an in-flight request being processed
//! - [`UnitHttpRequest`] - HTTP request with method constructors (e.g. [`UnitHttpRequest::get`])
//! - [`UnitHttpResponse`] - HTTP response with a [`status_code`](UnitHttpResponse::status_code) accessor
//! - [`UnitHttpMessage`] - Trait providing common read accessors for both request and response
//!
//! ## Backends
//!
//! Mock upstream services using the [`Backend`] and [`GrpcBackend`] traits:
//!
//! - [`TraceBackend`] - Records all incoming requests for later inspection; also acts as a configurable response backend
//! - [`protobuf_grpc_backend`] - Macro for creating gRPC backends from protobuf definitions
//!
//! ## Features
//!
//! - `enable_stop_iteration` - Enables [`StopIterationMode`] for handling paused requests

mod backends;
mod dw;
mod host;
mod tester;

pub use crate::tester::builder::UnitTestBuilder;
pub use crate::tester::io::{
    UnitGrpcRequest, UnitGrpcResponse, UnitHttpMessage, UnitHttpRequest, UnitHttpResponse,
};
pub use crate::tester::unit_test::{StopIterationMode, UnitTest, UnitTestRequest};
pub use backends::{ldap::UnitLdapConfig, trace::TraceBackend, Backend, GrpcBackend};
pub use dw::dw2pel;
pub use pdk_unit_macros::protobuf_grpc_backend;