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
This commit is contained in:
Jeena 2026-01-16 23:26:26 +00:00
parent ad84bf187d
commit 3e490d85ef
2 changed files with 103 additions and 91 deletions

View file

@ -1,6 +1,5 @@
use std::process::Command;
use tempfile::TempDir;
use std::fs;
use std::env;
#[test]
fn test_missing_config_file() {
@ -18,9 +17,10 @@ fn test_missing_config_file() {
#[test]
fn test_missing_hostname() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
fs::write(&config_path, r#"
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"
@ -29,7 +29,7 @@ fn test_missing_hostname() {
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg(config_path)
.arg(&config_path)
.output()
.unwrap();
@ -37,13 +37,17 @@ fn test_missing_hostname() {
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 = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
fs::write(&config_path, r#"
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"
@ -57,6 +61,9 @@ fn test_nonexistent_root_directory() {
.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"));
@ -65,9 +72,10 @@ fn test_nonexistent_root_directory() {
#[test]
fn test_missing_certificate_file() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
fs::write(&config_path, r#"
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"
@ -77,7 +85,7 @@ fn test_missing_certificate_file() {
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
.arg("--config")
.arg(config_path)
.arg(&config_path)
.output()
.unwrap();
@ -85,4 +93,7 @@ fn test_missing_certificate_file() {
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);
}