Add test infrastructure with fixtures, helpers, and integration tests
- Add [lib] target to enable integration test imports - Add rcgen and reqwest dev-dependencies for TLS and HTTP test helpers - Create src/config/test_fixtures.rs with test_static_config() and test_dynamic_config() - Create tests/ with integration tests, HTTP test helper (TestUpstream), and TLS test helper (SelfSignedCert) - Add Clone derives to StaticConfig and related structs for test fixture construction - All existing tests continue to pass
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
pub mod dynamic_config;
|
||||
pub mod static_config;
|
||||
pub mod test_fixtures;
|
||||
pub mod validation;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct StaticConfig {
|
||||
pub listeners: Vec<ListenerConfig>,
|
||||
#[serde(default)]
|
||||
@@ -32,7 +32,7 @@ fn default_shutdown_timeout_secs() -> u64 {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct ListenerConfig {
|
||||
pub bind_addr: String,
|
||||
#[serde(default = "default_http_port")]
|
||||
@@ -55,7 +55,7 @@ fn default_https_port() -> u16 {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct TlsConfig {
|
||||
pub mode: String,
|
||||
#[serde(default)]
|
||||
@@ -76,7 +76,7 @@ fn default_acme_directory() -> String {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct LoggingConfig {
|
||||
#[serde(default = "default_log_level")]
|
||||
pub level: String,
|
||||
|
||||
65
src/config/test_fixtures.rs
Normal file
65
src/config/test_fixtures.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use crate::config::dynamic_config::{BodyConfig, DynamicConfig, RateLimitConfig, SiteConfig};
|
||||
use crate::config::static_config::{ListenerConfig, LoggingConfig, StaticConfig, TlsConfig};
|
||||
|
||||
pub fn test_static_config() -> StaticConfig {
|
||||
StaticConfig {
|
||||
listeners: vec![ListenerConfig {
|
||||
bind_addr: "127.0.0.1".to_string(),
|
||||
http_port: 80,
|
||||
https_port: 443,
|
||||
tls: TlsConfig {
|
||||
mode: "manual".to_string(),
|
||||
acme_domains: vec![],
|
||||
acme_cache_dir: String::new(),
|
||||
acme_directory: "production".to_string(),
|
||||
cert_path: "/tmp/test-cert.pem".to_string(),
|
||||
key_path: "/tmp/test-key.pem".to_string(),
|
||||
},
|
||||
sites: vec![],
|
||||
}],
|
||||
allow_wildcard_bind: false,
|
||||
health_check_port: 9900,
|
||||
admin_socket_path: "/tmp/reverse-proxy-test/admin.sock".to_string(),
|
||||
shutdown_timeout_secs: 30,
|
||||
logging: LoggingConfig::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_dynamic_config() -> DynamicConfig {
|
||||
DynamicConfig {
|
||||
sites: vec![SiteConfig {
|
||||
host: "test.local".to_string(),
|
||||
upstream: "127.0.0.1:8080".to_string(),
|
||||
upstream_scheme: "http".to_string(),
|
||||
upstream_connect_timeout_secs: 5,
|
||||
upstream_request_timeout_secs: 60,
|
||||
}],
|
||||
rate_limit: RateLimitConfig {
|
||||
requests_per_second: 10,
|
||||
burst: 20,
|
||||
},
|
||||
body: BodyConfig {
|
||||
limit_bytes: 104857600,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_static_config_fixture_is_valid() {
|
||||
let config = test_static_config();
|
||||
assert!(!config.listeners.is_empty());
|
||||
assert_eq!(config.health_check_port, 9900);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_config_fixture_is_valid() {
|
||||
let config = test_dynamic_config();
|
||||
assert!(!config.sites.is_empty());
|
||||
assert_eq!(config.rate_limit.requests_per_second, 10);
|
||||
assert_eq!(config.body.limit_bytes, 104857600);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user