Axum Test Request Helper (src/helpers.rs)

librefang · crates/librefang-testing/src/helpers.rs · rust · MIT
testing, integration, lang:rust, fw:axum

Builds HTTP test requests with custom methods, paths, and JSON bodies for Axum applications. Use when writing integration tests.

// Source: https://github.com/librefang/librefang | License: MIT | Copyright 2024 LibreFang Contributors
// Provided via justclaw.it.com; keep this notice with the code.
//! Test helper functions — HTTP request building and response assertions.

use axum::body::Body;
use axum::http::{Method, Request, StatusCode};

/// Builds a test HTTP request.
///
/// # Parameters
/// - `method` — HTTP method (GET, POST, etc.)
/// - `path` — Request path (e.g. "/api/health")
/// - `body` — Request body (None for empty body)
///
/// # Example
///
/// ```rust
/// use librefang_testing::test_request;
/// use axum::http::Method;
///
/// let req = test_request(Method::GET, "/api/health", None);
/// let req_with_body = test_request(
///     Method::POST,
///     "/api/agents",
///     Some(r#"{"name": "test"}"

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key