Skip to content

Commit 784263c

Browse files
author
Hang SU
committed
test(console): add UDS configuration validation tests
- Verify UDS path parent directory existence check - Test UDS address generation logic with multiple sockets - Add error handling test for invalid UDS backend initialization Signed-off-by: Hang SU <[email protected]>
1 parent e3b6b54 commit 784263c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

vhost-device-console/src/backend.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,51 @@ mod tests {
331331

332332
assert!(start_backend(config).is_err());
333333
}
334+
335+
#[test]
336+
fn test_console_invalid_uds_path() {
337+
let args = ConsoleArgs {
338+
socket_path: PathBuf::from("/tmp/vhost.sock"),
339+
uds_path: Some("/non_existing_dir/test.sock".to_string().into()),
340+
backend: BackendType::Uds,
341+
tcp_port: String::new(),
342+
socket_count: 1,
343+
max_queue_size: 128,
344+
};
345+
346+
assert_matches!(VuConsoleConfig::try_from(args), Err(Error::InvalidUdsFile));
347+
}
348+
349+
#[test]
350+
fn test_generate_vm_sock_addrs_uds() {
351+
let config = VuConsoleConfig {
352+
socket_path: PathBuf::new(),
353+
uds_path: "/tmp/vm.sock".to_string().into(),
354+
backend: BackendType::Uds,
355+
tcp_port: String::new(),
356+
socket_count: 3,
357+
max_queue_size: 128,
358+
};
359+
360+
let addrs = config.generate_vm_socks();
361+
assert_eq!(
362+
addrs,
363+
vec!["/tmp/vm.sock0", "/tmp/vm.sock1", "/tmp/vm.sock2"]
364+
);
365+
}
366+
367+
#[test]
368+
fn test_start_uds_backend_with_invalid_path() {
369+
let config = VuConsoleConfig {
370+
socket_path: PathBuf::from("/tmp/vhost.sock"),
371+
uds_path: "/invalid/path/uds.sock".to_string().into(),
372+
backend: BackendType::Uds,
373+
tcp_port: String::new(),
374+
socket_count: 1,
375+
max_queue_size: 128,
376+
};
377+
378+
let result = start_backend(config);
379+
assert!(result.is_err());
380+
}
334381
}

0 commit comments

Comments
 (0)