Skip to content

Commit a570232

Browse files
committed
fix limayaml FillDefault() tests making it independent of vm-types
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 755e537 commit a570232

File tree

1 file changed

+46
-75
lines changed

1 file changed

+46
-75
lines changed

pkg/limayaml/defaults_test.go

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func TestFillDefault(t *testing.T) {
3131
logrus.SetLevel(logrus.DebugLevel)
3232
var d, y, o limatype.LimaYAML
3333

34-
defaultVMType := limatype.QEMU
3534
opts := []cmp.Option{
3635
// Consider nil slices and empty slices to be identical
3736
cmpopts.EquateEmpty(),
@@ -76,7 +75,6 @@ func TestFillDefault(t *testing.T) {
7675

7776
// Builtin default values
7877
builtin := limatype.LimaYAML{
79-
VMType: &defaultVMType,
8078
OS: ptr.Of(limatype.LINUX),
8179
Arch: ptr.Of(arch),
8280
CPUs: ptr.Of(defaultCPUs()),
@@ -105,9 +103,6 @@ func TestFillDefault(t *testing.T) {
105103
},
106104
Video: limatype.Video{
107105
Display: ptr.Of("none"),
108-
VNC: limatype.VNCOptions{
109-
Display: ptr.Of("127.0.0.1:0,to=9"),
110-
},
111106
},
112107
HostResolver: limatype.HostResolver{
113108
Enabled: ptr.Of(true),
@@ -194,31 +189,11 @@ func TestFillDefault(t *testing.T) {
194189
},
195190
},
196191
TimeZone: ptr.Of("Antarctica/Troll"),
197-
Firmware: limatype.Firmware{
198-
LegacyBIOS: ptr.Of(false),
199-
Images: []limatype.FileWithVMType{
200-
{
201-
File: limatype.File{
202-
Location: "https://gitlab.com/kraxel/qemu/-/raw/704f7cad5105246822686f65765ab92045f71a3b/pc-bios/edk2-aarch64-code.fd.bz2",
203-
Arch: limatype.AARCH64,
204-
Digest: "sha256:a5fc228623891297f2d82e22ea56ec57cde93fea5ec01abf543e4ed5cacaf277",
205-
},
206-
VMType: limatype.QEMU,
207-
},
208-
{
209-
File: limatype.File{
210-
Location: "https://github.com/AkihiroSuda/qemu/raw/704f7cad5105246822686f65765ab92045f71a3b/pc-bios/edk2-aarch64-code.fd.bz2",
211-
Arch: limatype.AARCH64,
212-
Digest: "sha256:a5fc228623891297f2d82e22ea56ec57cde93fea5ec01abf543e4ed5cacaf277",
213-
},
214-
VMType: limatype.QEMU,
215-
},
216-
},
217-
},
218192
}
219193

220194
expect := builtin
221-
expect.VMType = ptr.Of(limatype.QEMU) // due to NINEP
195+
// VMType should remain nil when not explicitly set (will be resolved by ValidateVMType later)
196+
expect.VMType = nil
222197
expect.HostResolver.Hosts = map[string]string{
223198
"MY.Host": "host.lima.internal",
224199
}
@@ -312,8 +287,12 @@ func TestFillDefault(t *testing.T) {
312287
}
313288

314289
expect.TimeZone = y.TimeZone
315-
expect.Firmware = y.Firmware
316-
expect.Firmware.Images = slices.Clone(y.Firmware.Images)
290+
// Set firmware expectations to match what FillDefault actually does
291+
// FillDefault uses the builtin default values, which include LegacyBIOS: ptr.Of(false)
292+
expect.Firmware = limatype.Firmware{
293+
LegacyBIOS: ptr.Of(false), // This matches what FillDefault actually sets
294+
Images: nil,
295+
}
317296

318297
expect.Rosetta = limatype.Rosetta{
319298
Enabled: ptr.Of(false),
@@ -335,7 +314,7 @@ func TestFillDefault(t *testing.T) {
335314
// Calling filepath.Abs() to add a drive letter on Windows
336315
varLog, _ := filepath.Abs("/var/log")
337316
d = limatype.LimaYAML{
338-
VMType: ptr.Of("vz"),
317+
// Remove driver-specific VMType from defaults test
339318
OS: ptr.Of("unknown"),
340319
Arch: ptr.Of("unknown"),
341320
CPUs: ptr.Of(7),
@@ -363,23 +342,14 @@ func TestFillDefault(t *testing.T) {
363342
TimeZone: ptr.Of("Zulu"),
364343
Firmware: limatype.Firmware{
365344
LegacyBIOS: ptr.Of(true),
366-
Images: []limatype.FileWithVMType{
367-
{
368-
File: limatype.File{
369-
Location: "/dummy",
370-
Arch: limatype.X8664,
371-
},
372-
},
373-
},
345+
// Remove driver-specific firmware images from defaults
374346
},
375347
Audio: limatype.Audio{
376348
Device: ptr.Of("coreaudio"),
377349
},
378350
Video: limatype.Video{
379351
Display: ptr.Of("cocoa"),
380-
VNC: limatype.VNCOptions{
381-
Display: ptr.Of("none"),
382-
},
352+
// Remove driver-specific VNC configuration
383353
},
384354
HostResolver: limatype.HostResolver{
385355
Enabled: ptr.Of(false),
@@ -458,6 +428,8 @@ func TestFillDefault(t *testing.T) {
458428
}
459429

460430
expect = d
431+
// VMType should remain nil when not explicitly set
432+
expect.VMType = nil
461433
// Also verify that archive arch is filled in
462434
expect.Containerd.Archives = slices.Clone(d.Containerd.Archives)
463435
expect.Containerd.Archives[0].Arch = *d.Arch
@@ -480,7 +452,8 @@ func TestFillDefault(t *testing.T) {
480452
expect.HostResolver.Hosts = map[string]string{
481453
"default": d.HostResolver.Hosts["default"],
482454
}
483-
expect.MountType = ptr.Of(limatype.VIRTIOFS)
455+
// Remove driver-specific mount type from defaults test
456+
expect.MountType = nil
484457
expect.MountInotify = ptr.Of(false)
485458
expect.CACertificates.RemoveDefaults = ptr.Of(true)
486459
expect.CACertificates.Certs = []string{
@@ -504,7 +477,7 @@ func TestFillDefault(t *testing.T) {
504477
FillDefault(&y, &d, &limatype.LimaYAML{}, filePath, false)
505478
assert.DeepEqual(t, &y, &expect, opts...)
506479

507-
dExpect := expect
480+
dExpected := expect
508481

509482
// ------------------------------------------------------------------------------------
510483
// User-provided defaults should not override user-provided config values
@@ -516,29 +489,29 @@ func TestFillDefault(t *testing.T) {
516489

517490
expect = y
518491

519-
expect.Provision = slices.Concat(y.Provision, dExpect.Provision)
520-
expect.Probes = slices.Concat(y.Probes, dExpect.Probes)
521-
expect.PortForwards = slices.Concat(y.PortForwards, dExpect.PortForwards)
522-
expect.CopyToHost = slices.Concat(y.CopyToHost, dExpect.CopyToHost)
523-
expect.Containerd.Archives = slices.Concat(y.Containerd.Archives, dExpect.Containerd.Archives)
492+
expect.Provision = slices.Concat(y.Provision, dExpected.Provision)
493+
expect.Probes = slices.Concat(y.Probes, dExpected.Probes)
494+
expect.PortForwards = slices.Concat(y.PortForwards, dExpected.PortForwards)
495+
expect.CopyToHost = slices.Concat(y.CopyToHost, dExpected.CopyToHost)
496+
expect.Containerd.Archives = slices.Concat(y.Containerd.Archives, dExpected.Containerd.Archives)
524497
expect.Containerd.Archives[2].Arch = *expect.Arch
525-
expect.AdditionalDisks = slices.Concat(y.AdditionalDisks, dExpect.AdditionalDisks)
526-
expect.Firmware.Images = slices.Concat(y.Firmware.Images, dExpect.Firmware.Images)
498+
expect.AdditionalDisks = slices.Concat(y.AdditionalDisks, dExpected.AdditionalDisks)
499+
expect.Firmware.Images = slices.Concat(y.Firmware.Images, dExpected.Firmware.Images)
527500

528501
// Mounts and Networks start with lowest priority first, so higher priority entries can overwrite
529-
expect.Mounts = slices.Concat(dExpect.Mounts, y.Mounts)
530-
expect.Networks = slices.Concat(dExpect.Networks, y.Networks)
502+
expect.Mounts = slices.Concat(dExpected.Mounts, y.Mounts)
503+
expect.Networks = slices.Concat(dExpected.Networks, y.Networks)
531504

532-
expect.HostResolver.Hosts["default"] = dExpect.HostResolver.Hosts["default"]
505+
expect.HostResolver.Hosts["default"] = dExpected.HostResolver.Hosts["default"]
533506

534-
// dExpect.DNS will be ignored, and not appended to y.DNS
507+
// dExpected.DNS will be ignored, and not appended to y.DNS
535508

536-
// "TWO" does not exist in filledDefaults.Env, so is set from dExpect.Env
537-
expect.Env["TWO"] = dExpect.Env["TWO"]
509+
// "TWO" does not exist in filledDefaults.Env, so is set from dExpected.Env
510+
expect.Env["TWO"] = dExpected.Env["TWO"]
538511

539-
expect.Param["TWO"] = dExpect.Param["TWO"]
512+
expect.Param["TWO"] = dExpected.Param["TWO"]
540513

541-
t.Logf("d.vmType=%q, y.vmType=%q, expect.vmType=%q", *d.VMType, *y.VMType, *expect.VMType)
514+
t.Logf("d.vmType=%v, y.vmType=%v, expect.vmType=%v", d.VMType, y.VMType, expect.VMType)
542515

543516
FillDefault(&y, &d, &limatype.LimaYAML{}, filePath, false)
544517
assert.DeepEqual(t, &y, &expect, opts...)
@@ -547,7 +520,7 @@ func TestFillDefault(t *testing.T) {
547520
// User-provided overrides should override user-provided config settings
548521

549522
o = limatype.LimaYAML{
550-
VMType: ptr.Of("qemu"),
523+
// Remove driver-specific VMType from override test
551524
OS: ptr.Of(limatype.LINUX),
552525
Arch: ptr.Of(arch),
553526
CPUs: ptr.Of(12),
@@ -585,9 +558,7 @@ func TestFillDefault(t *testing.T) {
585558
},
586559
Video: limatype.Video{
587560
Display: ptr.Of("cocoa"),
588-
VNC: limatype.VNCOptions{
589-
Display: ptr.Of("none"),
590-
},
561+
// Remove driver-specific VNC configuration
591562
},
592563
HostResolver: limatype.HostResolver{
593564
Enabled: ptr.Of(false),
@@ -685,20 +656,20 @@ func TestFillDefault(t *testing.T) {
685656

686657
expect = o
687658

688-
expect.Provision = slices.Concat(o.Provision, y.Provision, dExpect.Provision)
689-
expect.Probes = slices.Concat(o.Probes, y.Probes, dExpect.Probes)
690-
expect.PortForwards = slices.Concat(o.PortForwards, y.PortForwards, dExpect.PortForwards)
691-
expect.CopyToHost = slices.Concat(o.CopyToHost, y.CopyToHost, dExpect.CopyToHost)
692-
expect.Containerd.Archives = slices.Concat(o.Containerd.Archives, y.Containerd.Archives, dExpect.Containerd.Archives)
659+
expect.Provision = slices.Concat(o.Provision, y.Provision, dExpected.Provision)
660+
expect.Probes = slices.Concat(o.Probes, y.Probes, dExpected.Probes)
661+
expect.PortForwards = slices.Concat(o.PortForwards, y.PortForwards, dExpected.PortForwards)
662+
expect.CopyToHost = slices.Concat(o.CopyToHost, y.CopyToHost, dExpected.CopyToHost)
663+
expect.Containerd.Archives = slices.Concat(o.Containerd.Archives, y.Containerd.Archives, dExpected.Containerd.Archives)
693664
expect.Containerd.Archives[3].Arch = *expect.Arch
694-
expect.AdditionalDisks = slices.Concat(o.AdditionalDisks, y.AdditionalDisks, dExpect.AdditionalDisks)
695-
expect.Firmware.Images = slices.Concat(o.Firmware.Images, y.Firmware.Images, dExpect.Firmware.Images)
665+
expect.AdditionalDisks = slices.Concat(o.AdditionalDisks, y.AdditionalDisks, dExpected.AdditionalDisks)
666+
expect.Firmware.Images = slices.Concat(o.Firmware.Images, y.Firmware.Images, dExpected.Firmware.Images)
696667

697-
expect.HostResolver.Hosts["default"] = dExpect.HostResolver.Hosts["default"]
698-
expect.HostResolver.Hosts["MY.Host"] = dExpect.HostResolver.Hosts["host.lima.internal"]
668+
expect.HostResolver.Hosts["default"] = dExpected.HostResolver.Hosts["default"]
669+
expect.HostResolver.Hosts["MY.Host"] = dExpected.HostResolver.Hosts["host.lima.internal"]
699670

700-
// o.Mounts just makes dExpect.Mounts[0] writable because the Location matches
701-
expect.Mounts = slices.Concat(dExpect.Mounts, y.Mounts)
671+
// o.Mounts just makes dExpected.Mounts[0] writable because the Location matches
672+
expect.Mounts = slices.Concat(dExpected.Mounts, y.Mounts)
702673
expect.Mounts[0].Writable = ptr.Of(true)
703674
expect.Mounts[0].SSHFS.Cache = ptr.Of(false)
704675
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(true)
@@ -711,8 +682,8 @@ func TestFillDefault(t *testing.T) {
711682
expect.MountType = ptr.Of(limatype.NINEP)
712683
expect.MountInotify = ptr.Of(true)
713684

714-
// o.Networks[1] is overriding the dExpect.Networks[0].Lima entry for the "def0" interface
715-
expect.Networks = slices.Concat(dExpect.Networks, y.Networks, []limatype.Network{o.Networks[0]})
685+
// o.Networks[1] is overriding the dExpected.Networks[0].Lima entry for the "def0" interface
686+
expect.Networks = slices.Concat(dExpected.Networks, y.Networks, []limatype.Network{o.Networks[0]})
716687
expect.Networks[0].Lima = o.Networks[1].Lima
717688

718689
// Only highest prio DNS are retained

0 commit comments

Comments
 (0)