Add terminal service implementation and integration tests
- Introduced terminal.h header file defining the terminal service API. - Implemented integration tests for terminal service registration and health checks. - Added unit tests for FFI layer, health checks, and terminal service functionality. - Created a mock center for testing terminal registration and deregistration. - Ensured proper error handling and response validation in tests.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::Config;
|
||||
|
||||
#[test]
|
||||
fn defaults_file_and_environment_precedence() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join(".env");
|
||||
let config = Config::from_file(&path, HashMap::new()).unwrap();
|
||||
assert_eq!(config.port, 50051);
|
||||
assert_eq!(config.health_interval, Duration::from_secs(10));
|
||||
std::fs::write(&path, "REGISTRY_PORT=1234\nREGISTRY_HOST=localhost\n").unwrap();
|
||||
let config = Config::from_file(
|
||||
&path,
|
||||
HashMap::from([("REGISTRY_PORT".into(), "4321".into())]),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(config.port, 4321);
|
||||
assert_eq!(config.host, "localhost");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_configuration_fails() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join(".env");
|
||||
for (key, value) in [
|
||||
("REGISTRY_PORT", "0"),
|
||||
("REGISTRY_PORT", "65536"),
|
||||
("REGISTRY_HEALTH_INTERVAL_SECS", "0"),
|
||||
("REGISTRY_HEALTH_TIMEOUT_SECS", "abc"),
|
||||
("REGISTRY_HOST", " "),
|
||||
("REGISTRY_DATA_PATH", ""),
|
||||
] {
|
||||
assert!(Config::from_file(&path, HashMap::from([(key.into(), value.into())])).is_err());
|
||||
}
|
||||
std::fs::write(&path, "REGISTRY_PORT='unterminated").unwrap();
|
||||
assert!(Config::from_file(&path, HashMap::new()).is_err());
|
||||
}
|
||||
Reference in New Issue
Block a user