Skip to main content

Crate volter_testing

Crate volter_testing 

Source
Expand description

In-process test client for Volter applications.

TestClient wraps a Router and drives it directly in memory — no real TCP socket is bound, so tests are fast and don’t fight over ports in CI.

§Quick start

use volter_testing::TestClient;
use volter_router::{Router, get};

async fn handler() -> &'static str { "ok" }

let client = TestClient::new(Router::new().route("/", get(handler)));

let response = client.get("/").send().await;
assert_eq!(response.status(), 200);

let body = response.text().await.unwrap();
assert_eq!(body, "ok");

§JSON round-trip

use serde::{Serialize, Deserialize};
use volter_testing::TestClient;
use volter_router::{Router, post};
use volter_extract::Json;

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Payload { name: String }

async fn echo(Json(p): Json<Payload>) -> Json<Payload> { Json(p) }

let client = TestClient::new(Router::new().route("/echo", post(echo)));

let response = client
    .post("/echo")
    .json(&Payload { name: "ferris".into() })
    .send()
    .await;

let body: Payload = response.json().await.unwrap();
assert_eq!(body, Payload { name: "ferris".into() });

See ARCHITECTURE.md → “Testing architecture” for the full design.

Structs§

TestClient
An in-process test client for Volter applications.
TestRequestBuilder
A request builder produced by TestClient.
TestResponse
The response returned by TestRequestBuilder::send.

Enums§

BodyError
Errors that can occur when consuming a test response body.