pollux/tests/config_validation.rs
Jeena 3e490d85ef Implement integration tests using system temp directory
- Move tests to use std::env::temp_dir() instead of ./tmp
- Generate test certificates on-demand with openssl
- Create isolated test environments with automatic cleanup
- Add comprehensive config validation integration tests
- Temporarily simplify rate limiting test (complex TLS testing deferred)
- Tests now work out-of-the-box for fresh repository clones
- Run tests sequentially to avoid stderr mixing in parallel execution
2026-01-16 23:26:26 +00:00

99 lines
No EOL
3.1 KiB
Rust

use std::process::Command;
use std::env;
#[test]
fn test_missing_config_file() {
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg("nonexistent.toml")
.output()
.unwrap();
assert!(!output.status.success());
let stderr = String::from_utf8(output.stderr).unwrap();
assert!(stderr.contains("Config file 'nonexistent.toml' not found"));
assert!(stderr.contains("Create the config file with required fields"));
}
#[test]
fn test_missing_hostname() {
let temp_dir = env::temp_dir().join(format!("pollux_test_config_{}", std::process::id()));
std::fs::create_dir_all(&temp_dir).unwrap();
let config_path = temp_dir.join("config.toml");
std::fs::write(&config_path, r#"
root = "/tmp"
cert = "cert.pem"
key = "key.pem"
bind_host = "0.0.0.0"
"#).unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg(&config_path)
.output()
.unwrap();
assert!(!output.status.success());
let stderr = String::from_utf8(output.stderr).unwrap();
assert!(stderr.contains("'hostname' field is required"));
assert!(stderr.contains("hostname = \"your.domain.com\""));
// Cleanup
let _ = std::fs::remove_dir_all(&temp_dir);
}
#[test]
fn test_nonexistent_root_directory() {
let temp_dir = env::temp_dir().join(format!("pollux_test_config_{}", std::process::id()));
std::fs::create_dir_all(&temp_dir).unwrap();
let config_path = temp_dir.join("config.toml");
std::fs::write(&config_path, r#"
root = "/definitely/does/not/exist"
cert = "cert.pem"
key = "key.pem"
hostname = "example.com"
bind_host = "0.0.0.0"
"#).unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg(config_path)
.output()
.unwrap();
// Cleanup
let _ = std::fs::remove_dir_all(&temp_dir);
assert!(!output.status.success());
let stderr = String::from_utf8(output.stderr).unwrap();
assert!(stderr.contains("Root directory '/definitely/does/not/exist' does not exist"));
assert!(stderr.contains("Create the directory and add your Gemini files"));
}
#[test]
fn test_missing_certificate_file() {
let temp_dir = env::temp_dir().join(format!("pollux_test_config_{}", std::process::id()));
std::fs::create_dir_all(&temp_dir).unwrap();
let config_path = temp_dir.join("config.toml");
std::fs::write(&config_path, r#"
root = "/tmp"
cert = "/nonexistent/cert.pem"
key = "key.pem"
hostname = "example.com"
bind_host = "0.0.0.0"
"#).unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg(&config_path)
.output()
.unwrap();
assert!(!output.status.success());
let stderr = String::from_utf8(output.stderr).unwrap();
assert!(stderr.contains("Certificate file '/nonexistent/cert.pem' does not exist"));
assert!(stderr.contains("Generate or obtain TLS certificates"));
// Cleanup
let _ = std::fs::remove_dir_all(&temp_dir);
}