use std::process::Command; use tempfile::TempDir; use std::fs; #[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 = TempDir::new().unwrap(); let config_path = temp_dir.path().join("config.toml"); 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\"")); } #[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#" 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(); 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 = TempDir::new().unwrap(); let config_path = temp_dir.path().join("config.toml"); 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")); }