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
This commit is contained in:
parent
13acdd9bcb
commit
4b4651384c
2 changed files with 93 additions and 0 deletions
88
tests/config_validation.rs
Normal file
88
tests/config_validation.rs
Normal file
|
|
@ -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"));
|
||||||
|
}
|
||||||
5
tests/rate_limiting.rs
Normal file
5
tests/rate_limiting.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#[test]
|
||||||
|
fn test_placeholder() {
|
||||||
|
// Placeholder test - rate limiting integration test to be implemented
|
||||||
|
assert!(true);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue