- Create shared tests/common.rs with TestEnvironment setup - Simplify gemini_test_client.py to single-request client - Refactor config validation tests to use common setup - Add test_valid_config_startup for complete server validation - Fix clippy warning in main.rs - Remove unused code and consolidate test infrastructure
117 lines
No EOL
3.8 KiB
Rust
117 lines
No EOL
3.8 KiB
Rust
mod common;
|
|
|
|
use std::process::Command;
|
|
|
|
#[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 env = common::setup_test_environment();
|
|
let config_content = format!(r#"
|
|
root = "{}"
|
|
cert = "{}"
|
|
key = "{}"
|
|
bind_host = "127.0.0.1"
|
|
"#, env.content_path.display(), env.cert_path.display(), env.key_path.display());
|
|
std::fs::write(&env.config_path, config_content).unwrap();
|
|
|
|
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
|
|
.arg("--config")
|
|
.arg(&env.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("Add: hostname = \"your.domain.com\""));
|
|
}
|
|
|
|
#[test]
|
|
fn test_nonexistent_root_directory() {
|
|
let env = common::setup_test_environment();
|
|
let config_content = format!(r#"
|
|
root = "/definitely/does/not/exist"
|
|
cert = "{}"
|
|
key = "{}"
|
|
hostname = "example.com"
|
|
bind_host = "127.0.0.1"
|
|
"#, env.cert_path.display(), env.key_path.display());
|
|
std::fs::write(&env.config_path, config_content).unwrap();
|
|
|
|
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
|
|
.arg("--config")
|
|
.arg(&env.config_path)
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
|
assert!(stderr.contains("Error: Root directory '/definitely/does/not/exist' does not exist"));
|
|
assert!(stderr.contains("Create the directory and add your Gemini files (.gmi, .txt, images)"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_missing_certificate_file() {
|
|
let env = common::setup_test_environment();
|
|
let config_content = format!(r#"
|
|
root = "{}"
|
|
cert = "/nonexistent/cert.pem"
|
|
key = "{}"
|
|
hostname = "example.com"
|
|
bind_host = "127.0.0.1"
|
|
"#, env.content_path.display(), env.key_path.display());
|
|
std::fs::write(&env.config_path, config_content).unwrap();
|
|
|
|
let output = Command::new(env!("CARGO_BIN_EXE_pollux"))
|
|
.arg("--config")
|
|
.arg(&env.config_path)
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
|
assert!(stderr.contains("Error: Certificate file '/nonexistent/cert.pem' does not exist"));
|
|
assert!(stderr.contains("Generate or obtain TLS certificates for your domain"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_valid_config_startup() {
|
|
let env = common::setup_test_environment();
|
|
let config_content = format!(r#"
|
|
root = "{}"
|
|
cert = "{}"
|
|
key = "{}"
|
|
hostname = "localhost"
|
|
bind_host = "127.0.0.1"
|
|
port = {}
|
|
"#, env.content_path.display(), env.cert_path.display(), env.key_path.display(), env.port);
|
|
std::fs::write(&env.config_path, config_content).unwrap();
|
|
|
|
let mut server_process = Command::new(env!("CARGO_BIN_EXE_pollux"))
|
|
.arg("--config")
|
|
.arg(&env.config_path)
|
|
.spawn()
|
|
.unwrap();
|
|
|
|
// Wait for server to start
|
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
|
|
|
// Check server is still running (didn't exit with error)
|
|
assert!(server_process.try_wait().unwrap().is_none(), "Server should still be running with valid config");
|
|
|
|
// Kill server
|
|
server_process.kill().unwrap();
|
|
} |