@@ -27,6 +27,7 @@ const (
2727 testQemuVCPUsKey = "urunc_config.monitors.qemu.default_vcpus"
2828 testQemuBinaryKey = "urunc_config.monitors.qemu.binary_path"
2929 testQemuDataKey = "urunc_config.monitors.qemu.data_path"
30+ testQemuVhostKey = "urunc_config.monitors.qemu.vhost"
3031 testHvtMemoryKey = "urunc_config.monitors.hvt.default_memory_mb"
3132 testVirtiofsdPathKey = "urunc_config.extra_binaries.virtiofsd.path"
3233 testVirtiofsdOptsKey = "urunc_config.extra_binaries.virtiofsd.options"
@@ -56,6 +57,7 @@ func TestUruncConfigFromMap(t *testing.T) {
5657 testQemuVCPUsKey : "2" ,
5758 testQemuBinaryKey : testQemuBinaryPath ,
5859 testQemuDataKey : testQemuDataPath ,
60+ testQemuVhostKey : "true" ,
5961 }
6062
6163 config := UruncConfigFromMap (cfgMap )
@@ -67,6 +69,7 @@ func TestUruncConfigFromMap(t *testing.T) {
6769 assert .Equal (t , uint (2 ), qemuConfig .DefaultVCPUs )
6870 assert .Equal (t , testQemuBinaryPath , qemuConfig .BinaryPath )
6971 assert .Equal (t , testQemuDataPath , qemuConfig .DataPath )
72+ assert .True (t , qemuConfig .Vhost )
7073 })
7174
7275 t .Run ("multiple monitors" , func (t * testing.T ) {
@@ -323,6 +326,34 @@ func TestUruncConfigFromMap(t *testing.T) {
323326 assert .Equal (t , testVirtiofsdDefOpts , vfsConfig .Options )
324327 })
325328
329+ t .Run ("vhost false is parsed correctly" , func (t * testing.T ) {
330+ t .Parallel ()
331+ cfgMap := map [string ]string {
332+ testQemuMemoryKey : "512" ,
333+ testQemuVhostKey : "false" ,
334+ }
335+
336+ config := UruncConfigFromMap (cfgMap )
337+
338+ assert .NotNil (t , config )
339+ qemuConfig := config .Monitors ["qemu" ]
340+ assert .False (t , qemuConfig .Vhost )
341+ })
342+
343+ t .Run ("invalid vhost value defaults to false" , func (t * testing.T ) {
344+ t .Parallel ()
345+ cfgMap := map [string ]string {
346+ testQemuMemoryKey : "512" ,
347+ testQemuVhostKey : "invalid" ,
348+ }
349+
350+ config := UruncConfigFromMap (cfgMap )
351+
352+ assert .NotNil (t , config )
353+ qemuConfig := config .Monitors ["qemu" ]
354+ assert .False (t , qemuConfig .Vhost , "invalid vhost value should default to false" )
355+ })
356+
326357}
327358
328359func TestUruncConfigMap (t * testing.T ) {
@@ -415,6 +446,24 @@ func TestUruncConfigMap(t *testing.T) {
415446 assert .NotNil (t , cfgMap )
416447 assert .Empty (t , cfgMap )
417448 })
449+
450+ t .Run ("vhost true is serialized correctly" , func (t * testing.T ) {
451+ t .Parallel ()
452+ config := & UruncConfig {
453+ Monitors : map [string ]types.MonitorConfig {
454+ "qemu" : {
455+ DefaultMemoryMB : 512 ,
456+ DefaultVCPUs : 2 ,
457+ Vhost : true ,
458+ },
459+ },
460+ ExtraBins : map [string ]types.ExtraBinConfig {},
461+ }
462+
463+ cfgMap := config .Map ()
464+
465+ assert .Equal (t , "true" , cfgMap [testQemuVhostKey ])
466+ })
418467}
419468
420469func TestDefaultConfigs (t * testing.T ) {
@@ -449,6 +498,7 @@ func TestDefaultConfigs(t *testing.T) {
449498 assert .Equal (t , uint (256 ), hvConfig .DefaultMemoryMB )
450499 assert .Equal (t , uint (1 ), hvConfig .DefaultVCPUs )
451500 assert .Equal (t , "" , hvConfig .BinaryPath )
501+ assert .False (t , hvConfig .Vhost , "vhost should be false by default" )
452502 }
453503 })
454504
0 commit comments