Unify integration test environment and add valid config validation
- 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
This commit is contained in:
parent
3e490d85ef
commit
01bcda10d0
5 changed files with 219 additions and 295 deletions
59
tests/common.rs
Normal file
59
tests/common.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use tempfile::TempDir;
|
||||
|
||||
pub struct TestEnvironment {
|
||||
pub temp_dir: TempDir,
|
||||
pub config_path: PathBuf,
|
||||
pub cert_path: PathBuf,
|
||||
pub key_path: PathBuf,
|
||||
pub content_path: PathBuf,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
pub fn setup_test_environment() -> TestEnvironment {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let cert_path = temp_dir.path().join("cert.pem");
|
||||
let key_path = temp_dir.path().join("key.pem");
|
||||
let content_path = temp_dir.path().join("content");
|
||||
|
||||
// Create content directory and file
|
||||
std::fs::create_dir(&content_path).unwrap();
|
||||
std::fs::write(content_path.join("test.gmi"), "# Test Gemini content\n").unwrap();
|
||||
|
||||
// Generate test certificates
|
||||
generate_test_certificates(temp_dir.path());
|
||||
|
||||
// Use a unique port based on process ID to avoid conflicts
|
||||
let port = 1967 + (std::process::id() % 1000) as u16;
|
||||
|
||||
TestEnvironment {
|
||||
temp_dir,
|
||||
config_path,
|
||||
cert_path,
|
||||
key_path,
|
||||
content_path,
|
||||
port,
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_test_certificates(temp_dir: &Path) {
|
||||
use std::process::Command;
|
||||
|
||||
let cert_path = temp_dir.join("cert.pem");
|
||||
let key_path = temp_dir.join("key.pem");
|
||||
|
||||
let status = Command::new("openssl")
|
||||
.args(&[
|
||||
"req", "-x509", "-newkey", "rsa:2048",
|
||||
"-keyout", &key_path.to_string_lossy(),
|
||||
"-out", &cert_path.to_string_lossy(),
|
||||
"-days", "1",
|
||||
"-nodes",
|
||||
"-subj", "/CN=localhost"
|
||||
])
|
||||
.status()
|
||||
.unwrap();
|
||||
|
||||
assert!(status.success(), "Failed to generate test certificates");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue