Files
nym/common/http-api-client-macro/tests/macro_tests.rs
T
durch 4f08161315 fix: Address critical issues in client configuration registry implementation
- Fixed HeaderMapInit parsing bug that would cause compilation errors
- Added comprehensive documentation with usage examples and DSL reference
- Improved error handling with better error messages for invalid headers
- Added test coverage for both macro and registry functionality
- Added debug inspection capabilities for registered configurations
- Fixed module name conflicts in tests by using separate modules

All tests now passing:
- 7 macro tests validating DSL parsing and code generation
- 4 registry tests verifying configuration collection and application
2025-09-05 20:58:27 +02:00

65 lines
1.7 KiB
Rust

use nym_http_api_client_macro::{client_cfg, client_defaults};
use std::time::Duration;
#[test]
fn test_client_cfg_basic() {
// Test that the macro compiles with basic configuration
let _config = client_cfg!(timeout = Duration::from_secs(30), gzip = true);
}
#[test]
fn test_client_cfg_with_headers() {
// Test that the macro compiles with default headers
let _config = client_cfg!(
timeout = Duration::from_secs(30),
default_headers {
"User-Agent" => "TestApp/1.0",
"Accept" => "application/json"
}
);
}
#[test]
fn test_client_cfg_with_method_calls() {
// Test that the macro compiles with method calls
let _config = client_cfg!(
pool_max_idle_per_host = 32,
tcp_nodelay = true,
danger_accept_invalid_certs = true
);
}
#[test]
fn test_client_defaults_with_priority() {
// Test that client_defaults macro compiles with priority
client_defaults!(
priority = -100;
gzip = true,
deflate = true
);
}
#[test]
fn test_client_defaults_without_priority() {
// Test that client_defaults macro compiles without priority (defaults to 0)
client_defaults!(brotli = true, zstd = true);
}
#[test]
fn test_empty_client_cfg() {
// Test that empty configuration compiles
let _config = client_cfg!();
}
// Integration test to verify the closure actually works
#[test]
fn test_client_cfg_closure_application() {
let config = client_cfg!(gzip = true);
// Apply the configuration to a new builder
let builder = reqwest::ClientBuilder::new();
let _configured_builder = config(builder);
// Note: We can't easily test the internal state of the builder,
// but we verify it compiles and runs without panic
}