@@ -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,51 @@ 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 ! ( VuConsoleConfig :: try_from( args) , Err ( Error :: InvalidUdsFile ) ) ;
335
+ }
336
+
337
+ #[ test]
338
+ fn test_generate_vm_sock_addrs_uds ( ) {
339
+ let config = VuConsoleConfig {
340
+ socket_path : PathBuf :: new ( ) ,
341
+ vm_sock : "/tmp/vm.sock" . to_string ( ) ,
342
+ backend : BackendType :: Uds ,
343
+ tcp_port : String :: new ( ) ,
344
+ socket_count : 3 ,
345
+ max_queue_size : 128 ,
346
+ } ;
347
+
348
+ let addrs = config. generate_vm_sock_addrs ( ) ;
349
+ assert_eq ! (
350
+ addrs,
351
+ vec![ "/tmp/vm.sock0" , "/tmp/vm.sock1" , "/tmp/vm.sock2" ]
352
+ ) ;
353
+ }
354
+
355
+ #[ test]
356
+ fn test_start_uds_backend_with_invalid_path ( ) {
357
+ let config = VuConsoleConfig {
358
+ socket_path : PathBuf :: from ( "/tmp/vhost.sock" ) ,
359
+ vm_sock : "/invalid/path/uds.sock" . to_string ( ) ,
360
+ backend : BackendType :: Uds ,
361
+ tcp_port : String :: new ( ) ,
362
+ socket_count : 1 ,
363
+ max_queue_size : 128 ,
364
+ } ;
365
+
366
+ let result = start_backend ( config) ;
367
+ assert_matches ! ( result, Err ( Error :: CouldNotInitBackend ( _) ) ) ;
368
+ }
315
369
}
0 commit comments