- 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.
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
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());
|
|
}
|