tanu-core

Crates.iotanu-core
lib.rstanu-core
version0.10.0
created_at2025-01-30 13:50:03.321896+00
updated_at2025-09-18 02:47:22.235434+00
descriptionThe core component of tanu-rs
homepagehttps://github.com/tanu-rs/tanu
repositoryhttps://github.com/tanu-rs/tanu
max_upload_size
id1536402
size173,768
(yukinarit)

documentation

README

tanu-core

Crates.io Documentation License

The core component of the tanu WebAPI testing framework for Rust.

Overview

tanu-core provides the foundational components for building high-performance, async-friendly WebAPI tests in Rust. It contains the essential building blocks that power the tanu testing framework:

  • HTTP Client: Async HTTP client built on reqwest with ergonomic API
  • Assertion System: Type-safe assertion macros for test validation
  • Configuration Management: Flexible configuration system supporting multiple projects
  • Test Runner: Async test execution engine with concurrency support
  • Error Handling: Clean error propagation using eyre

Key Features

HTTP Client

  • Built on reqwest with async/await support
  • Automatic JSON serialization/deserialization
  • Cookie support (with cookies feature)
  • Multipart form data support (with multipart feature)
  • Gzip, deflate, brotli, and zstd compression support

Assertion System

The assertion system provides ergonomic macros for test validation:

use tanu_core::{check, check_eq, check_ne, check_str_eq};

// Basic assertions
check!(response.status().is_success(), "Expected successful response");
check_eq!(200, response.status().as_u16());
check_ne!(404, response.status().as_u16());
check_str_eq!("application/json", response.headers()["content-type"]);

Configuration Management

Supports flexible configuration via tanu.toml files:

[[projects]]
name = "api-tests"
test_ignore = ["slow_test"]

[projects.retry]
count = 3
factor = 2.0
jitter = true
delays = ["1s", "2s", "5s"]

Test Discovery

Compile-time test discovery using procedural macros:

#[tanu::test]
async fn test_api_endpoint() -> eyre::Result<()> {
    // Test implementation
    Ok(())
}

#[tanu::test(1)]
#[tanu::test(2)]
#[tanu::test(3)]
async fn parameterized_test(param: u32) -> eyre::Result<()> {
    // Test with parameter
    Ok(())
}

Usage

Add tanu-core to your Cargo.toml:

[dependencies]
tanu-core = "0.10.0"

Basic HTTP Test Example

use tanu_core::{check, check_eq, http::Client};

#[tanu::test]
async fn test_get_request() -> eyre::Result<()> {
    let client = Client::new();
    
    let response = client
        .get("https://httpbin.org/get")
        .header("user-agent", "tanu-test")
        .send()
        .await?;
    
    check!(response.status().is_success());
    check_eq!(200, response.status().as_u16());
    
    let json: serde_json::Value = response.json().await?;
    check_eq!("tanu-test", json["headers"]["User-Agent"].as_str().unwrap());
    
    Ok(())
}

Features

  • json - Enables JSON support for HTTP requests (via reqwest)
  • multipart - Enables multipart form data support
  • cookies - Enables cookie jar support for maintaining session state

Architecture

tanu-core is designed with modularity and extensibility in mind:

  • http - HTTP client functionality and request/response handling
  • assertion - Test assertion macros and validation utilities
  • config - Configuration parsing and management
  • runner - Test execution engine with async support
  • error - Error types and handling utilities

Integration

tanu-core is typically used through the main tanu crate, but can be used directly for custom testing scenarios or integration into other tools.

For complete examples and documentation, see the main tanu repository.

Commit count: 123

cargo fmt