@@ -203,6 +203,7 @@ mod tests {
203
203
fn test_console_valid_configuration_nested ( ) {
204
204
let args = ConsoleArgs {
205
205
socket_path : String :: from ( "/tmp/vhost.sock" ) . into ( ) ,
206
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
206
207
backend : BackendType :: Nested ,
207
208
tcp_port : String :: from ( "12345" ) ,
208
209
socket_count : 1 ,
@@ -216,6 +217,7 @@ mod tests {
216
217
fn test_console_invalid_configuration_nested_1 ( ) {
217
218
let args = ConsoleArgs {
218
219
socket_path : String :: from ( "/tmp/vhost.sock" ) . into ( ) ,
220
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
219
221
backend : BackendType :: Nested ,
220
222
tcp_port : String :: from ( "12345" ) ,
221
223
socket_count : 0 ,
@@ -232,6 +234,7 @@ mod tests {
232
234
fn test_console_invalid_configuration_nested_2 ( ) {
233
235
let args = ConsoleArgs {
234
236
socket_path : String :: from ( "/tmp/vhost.sock" ) . into ( ) ,
237
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
235
238
backend : BackendType :: Nested ,
236
239
tcp_port : String :: from ( "12345" ) ,
237
240
socket_count : 2 ,
@@ -248,6 +251,7 @@ mod tests {
248
251
fn test_console_valid_configuration_network_1 ( ) {
249
252
let args = ConsoleArgs {
250
253
socket_path : String :: from ( "/tmp/vhost.sock" ) . into ( ) ,
254
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
251
255
backend : BackendType :: Network ,
252
256
tcp_port : String :: from ( "12345" ) ,
253
257
socket_count : 1 ,
@@ -261,6 +265,7 @@ mod tests {
261
265
fn test_console_valid_configuration_network_2 ( ) {
262
266
let args = ConsoleArgs {
263
267
socket_path : String :: from ( "/tmp/vhost.sock" ) . into ( ) ,
268
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
264
269
backend : BackendType :: Network ,
265
270
tcp_port : String :: from ( "12345" ) ,
266
271
socket_count : 2 ,
@@ -291,6 +296,7 @@ mod tests {
291
296
fn test_start_backend_server_success ( ) {
292
297
let args = ConsoleArgs {
293
298
socket_path : String :: from ( "/not_a_dir/vhost.sock" ) . into ( ) ,
299
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
294
300
backend : BackendType :: Network ,
295
301
tcp_port : String :: from ( "12345" ) ,
296
302
socket_count : 1 ,
@@ -304,6 +310,7 @@ mod tests {
304
310
fn test_start_backend_success ( ) {
305
311
let config = VuConsoleConfig {
306
312
socket_path : String :: from ( "/not_a_dir/vhost.sock" ) . into ( ) ,
313
+ vm_sock : String :: from ( "/tmp/vm.sock" ) . into ( ) ,
307
314
backend : BackendType :: Network ,
308
315
tcp_port : String :: from ( "12346" ) ,
309
316
socket_count : 1 ,
@@ -312,4 +319,55 @@ mod tests {
312
319
313
320
assert ! ( start_backend( config) . is_err( ) ) ;
314
321
}
322
+
323
+ #[ test]
324
+ fn test_console_invalid_uds_path ( ) {
325
+ let args = ConsoleArgs {
326
+ socket_path : PathBuf :: from ( "/tmp/vhost.sock" ) ,
327
+ vm_sock : "/non_existing_dir/test.sock" . to_string ( ) ,
328
+ backend : BackendType :: Uds ,
329
+ tcp_port : String :: new ( ) ,
330
+ socket_count : 1 ,
331
+ max_queue_size : 128 ,
332
+ } ;
333
+
334
+ assert_matches ! (
335
+ VuConsoleConfig :: try_from( args) ,
336
+ Err ( Error :: InvalidUdsFile )
337
+ ) ;
338
+ }
339
+
340
+ #[ test]
341
+ fn test_generate_vm_sock_addrs_uds ( ) {
342
+ let config = VuConsoleConfig {
343
+ socket_path : PathBuf :: new ( ) ,
344
+ vm_sock : "/tmp/vm.sock" . to_string ( ) ,
345
+ backend : BackendType :: Uds ,
346
+ tcp_port : String :: new ( ) ,
347
+ socket_count : 3 ,
348
+ max_queue_size : 128 ,
349
+ } ;
350
+
351
+ let addrs = config. generate_vm_sock_addrs ( ) ;
352
+ assert_eq ! ( addrs, vec![
353
+ "/tmp/vm.sock0" ,
354
+ "/tmp/vm.sock1" ,
355
+ "/tmp/vm.sock2"
356
+ ] ) ;
357
+ }
358
+
359
+ #[ test]
360
+ fn test_start_uds_backend_with_invalid_path ( ) {
361
+ let config = VuConsoleConfig {
362
+ socket_path : PathBuf :: from ( "/tmp/vhost.sock" ) ,
363
+ vm_sock : "/invalid/path/uds.sock" . to_string ( ) ,
364
+ backend : BackendType :: Uds ,
365
+ tcp_port : String :: new ( ) ,
366
+ socket_count : 1 ,
367
+ max_queue_size : 128 ,
368
+ } ;
369
+
370
+ let result = start_backend ( config) ;
371
+ assert_matches ! ( result, Err ( Error :: CouldNotInitBackend ( _) ) ) ;
372
+ }
315
373
}
0 commit comments