From 4b4651384c0a888ffe687c447b8d1eb294dcff3b Mon Sep 17 00:00:00 2001 From: Jeena Date: Fri, 16 Jan 2026 22:39:32 +0000 Subject: [PATCH] Add integration tests for config validation and rate limiting - tests/config_validation.rs: Tests binary error handling for missing files, invalid config, missing fields, and filesystem issues - tests/rate_limiting.rs: Placeholder for rate limiting tests (complex TLS testing deferred) - Integration tests run automatically with cargo test and pre-commit hook - Tests validate user-facing error messages and exit codes --- tests/config_validation.rs | 88 ++++++++++++++++++++++++++++++++++++++ tests/rate_limiting.rs | 5 +++ 2 files changed, 93 insertions(+) create mode 100644 tests/config_validation.rs create mode 100644 tests/rate_limiting.rs diff --git a/tests/config_validation.rs b/tests/config_validation.rs new file mode 100644 index 0000000..9749665 --- /dev/null +++ b/tests/config_validation.rs @@ -0,0 +1,88 @@ +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")); +} \ No newline at end of file diff --git a/tests/rate_limiting.rs b/tests/rate_limiting.rs new file mode 100644 index 0000000..7f6ea09 --- /dev/null +++ b/tests/rate_limiting.rs @@ -0,0 +1,5 @@ +#[test] +fn test_placeholder() { + // Placeholder test - rate limiting integration test to be implemented + assert!(true); +} \ No newline at end of file