rhttp/tests/integration_tests.rs

55 lines
1.6 KiB
Rust

use reqwest::Client;
use rhttpd::{config::ServerConfig, server::ProxyServer};
use std::collections::HashMap;
#[tokio::test]
async fn test_static_file_serving() {
// Create test configuration
let mut sites = HashMap::new();
sites.insert(
"test.com".to_string(),
rhttpd::config::SiteConfig {
hostname: "test.com".to_string(),
routes: vec![rhttpd::config::RouteRule::Static {
path_pattern: "/*".to_string(),
root: std::path::PathBuf::from("./public"),
index: Some(vec!["index.html".to_string()]),
directory_listing: Some(false),
}],
tls: None,
},
);
let config = ServerConfig {
port: 8081,
sites,
js_config: None,
};
let server = ProxyServer::new(config);
// Start server in background
let server_handle = tokio::spawn(async move {
// Note: This will run forever in a real test, so we'd need to implement graceful shutdown
// For now, just create the server to verify it compiles
});
// Give server time to start
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// Test would go here...
server_handle.abort();
}
#[tokio::test]
async fn test_config_loading() {
// Test loading a valid TOML config
let config_result = ServerConfig::from_file("config.toml");
assert!(config_result.is_ok());
let config = config_result.unwrap();
assert_eq!(config.port, 8080);
assert!(config.sites.contains_key("example.com"));
}