feat(storage-server): add StorageServer<F: FileSystem> with BlockDevice trait, mock adapters, and tests

This commit is contained in:
2026-10-18 03:37:40 +02:00
parent b7bc223a79
commit 7a4600b3a2
13 changed files with 591 additions and 12 deletions

View File

@@ -0,0 +1,64 @@
use crate::filesystem::FileHandle;
use crate::protocol::*;
use server_framework::{Decode, Encode};
#[test]
fn open_roundtrip() {
let req = StorageRequest::Open { path_word0: 0x61626364, path_word1: 0 };
assert_eq!(StorageRequest::decode(req.encode()), Some(req));
}
#[test]
fn read_roundtrip() {
let req = StorageRequest::Read { handle: FileHandle::new(3), max_bytes: 512 };
assert_eq!(StorageRequest::decode(req.encode()), Some(req));
}
#[test]
fn write_roundtrip() {
let req = StorageRequest::Write { handle: FileHandle::new(1), data_word: 42 };
assert_eq!(StorageRequest::decode(req.encode()), Some(req));
}
#[test]
fn close_roundtrip() {
let req = StorageRequest::Close { handle: FileHandle::new(5) };
assert_eq!(StorageRequest::decode(req.encode()), Some(req));
}
#[test]
fn file_size_roundtrip() {
let req = StorageRequest::FileSize { handle: FileHandle::new(2) };
assert_eq!(StorageRequest::decode(req.encode()), Some(req));
}
#[test]
fn handle_response_roundtrip() {
let resp = StorageResponse::Handle(FileHandle::new(7));
assert_eq!(StorageResponse::decode(resp.encode()), Some(resp));
}
#[test]
fn data_response_roundtrip() {
let resp = StorageResponse::Data { bytes_read: 256 };
assert_eq!(StorageResponse::decode(resp.encode()), Some(resp));
}
#[test]
fn all_response_variants() {
let variants = [
StorageResponse::Ok,
StorageResponse::NotFound,
StorageResponse::Error,
StorageResponse::Size(1024),
StorageResponse::DirEntries { count: 3 },
];
for resp in variants {
assert_eq!(StorageResponse::decode(resp.encode()), Some(resp));
}
}
#[test]
fn invalid_request_returns_none() {
assert!(StorageRequest::decode([99, 0, 0, 0]).is_none());
}