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,45 @@
|
||||
use buffa::Message;
|
||||
use proto::proto::control::TerminalInfos;
|
||||
|
||||
use crate::storage::{decode, load, save};
|
||||
|
||||
#[test]
|
||||
fn corrupt_snapshot_is_preserved_and_uncommitted_temporary_is_ignored() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("terminals.bin");
|
||||
std::fs::write(&path, [0xff]).unwrap();
|
||||
assert!(load(&path).unwrap().infos.is_empty());
|
||||
let backup = std::fs::read_dir(directory.path())
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.path();
|
||||
assert!(
|
||||
backup
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.contains(".corrupt-")
|
||||
);
|
||||
assert_eq!(std::fs::read(backup).unwrap(), [0xff]);
|
||||
std::fs::write(
|
||||
directory.path().join(".registry-snapshot-interrupted"),
|
||||
[0xff],
|
||||
)
|
||||
.unwrap();
|
||||
save(&path, TerminalInfos::default()).unwrap();
|
||||
assert!(load(&path).unwrap().infos.is_empty());
|
||||
assert_eq!(std::fs::read(path).unwrap(), Vec::<u8>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semantic_corruption_is_rejected() {
|
||||
let snapshot = TerminalInfos {
|
||||
infos: [("wrong-id".into(), Default::default())]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(decode(&snapshot.try_encode_to_vec().unwrap()).is_err());
|
||||
}
|
||||
Reference in New Issue
Block a user