Skip to content

Commit 621ee4c

Browse files
committed
limayaml/defaults_test.go: keep expect as dExpect
Because `d` is no longer modified to expected values, it needs to keep `dExpect` to creating `expect` variable later. Signed-off-by: Norio Nomura <[email protected]>
1 parent 7392863 commit 621ee4c

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

pkg/limayaml/defaults_test.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ func TestFillDefault(t *testing.T) {
451451
FillDefault(&y, &d, &LimaYAML{}, filePath)
452452
assert.DeepEqual(t, &y, &expect, opts...)
453453

454+
dExpect := expect
455+
454456
// ------------------------------------------------------------------------------------
455457
// User-provided defaults should not override user-provided config values
456458

@@ -460,26 +462,27 @@ func TestFillDefault(t *testing.T) {
460462

461463
expect = y
462464

463-
expect.Provision = append(append([]Provision{}, y.Provision...), d.Provision...)
464-
expect.Probes = append(append([]Probe{}, y.Probes...), d.Probes...)
465-
expect.PortForwards = append(append([]PortForward{}, y.PortForwards...), d.PortForwards...)
466-
expect.CopyToHost = append(append([]CopyToHost{}, y.CopyToHost...), d.CopyToHost...)
467-
expect.Containerd.Archives = append(append([]File{}, y.Containerd.Archives...), d.Containerd.Archives...)
468-
expect.AdditionalDisks = append(append([]Disk{}, y.AdditionalDisks...), d.AdditionalDisks...)
469-
expect.Firmware.Images = append(append([]FileWithVMType{}, y.Firmware.Images...), d.Firmware.Images...)
465+
expect.Provision = append(append([]Provision{}, y.Provision...), dExpect.Provision...)
466+
expect.Probes = append(append([]Probe{}, y.Probes...), dExpect.Probes...)
467+
expect.PortForwards = append(append([]PortForward{}, y.PortForwards...), dExpect.PortForwards...)
468+
expect.CopyToHost = append(append([]CopyToHost{}, y.CopyToHost...), dExpect.CopyToHost...)
469+
expect.Containerd.Archives = append(append([]File{}, y.Containerd.Archives...), dExpect.Containerd.Archives...)
470+
expect.Containerd.Archives[2].Arch = *expect.Arch
471+
expect.AdditionalDisks = append(append([]Disk{}, y.AdditionalDisks...), dExpect.AdditionalDisks...)
472+
expect.Firmware.Images = append(append([]FileWithVMType{}, y.Firmware.Images...), dExpect.Firmware.Images...)
470473

471474
// Mounts and Networks start with lowest priority first, so higher priority entries can overwrite
472-
expect.Mounts = append(append([]Mount{}, d.Mounts...), y.Mounts...)
473-
expect.Networks = append(append([]Network{}, d.Networks...), y.Networks...)
475+
expect.Mounts = append(append([]Mount{}, dExpect.Mounts...), y.Mounts...)
476+
expect.Networks = append(append([]Network{}, dExpect.Networks...), y.Networks...)
474477

475-
expect.HostResolver.Hosts["default"] = d.HostResolver.Hosts["default"]
478+
expect.HostResolver.Hosts["default"] = dExpect.HostResolver.Hosts["default"]
476479

477-
// d.DNS will be ignored, and not appended to y.DNS
480+
// dExpect.DNS will be ignored, and not appended to y.DNS
478481

479-
// "TWO" does not exist in filledDefaults.Env, so is set from d.Env
480-
expect.Env["TWO"] = d.Env["TWO"]
482+
// "TWO" does not exist in filledDefaults.Env, so is set from dExpect.Env
483+
expect.Env["TWO"] = dExpect.Env["TWO"]
481484

482-
expect.Param["TWO"] = d.Param["TWO"]
485+
expect.Param["TWO"] = dExpect.Param["TWO"]
483486

484487
t.Logf("d.vmType=%q, y.vmType=%q, expect.vmType=%q", *d.VMType, *y.VMType, *expect.VMType)
485488

@@ -625,19 +628,20 @@ func TestFillDefault(t *testing.T) {
625628

626629
expect = o
627630

628-
expect.Provision = append(append(o.Provision, y.Provision...), d.Provision...)
629-
expect.Probes = append(append(o.Probes, y.Probes...), d.Probes...)
630-
expect.PortForwards = append(append(o.PortForwards, y.PortForwards...), d.PortForwards...)
631-
expect.CopyToHost = append(append(o.CopyToHost, y.CopyToHost...), d.CopyToHost...)
632-
expect.Containerd.Archives = append(append(o.Containerd.Archives, y.Containerd.Archives...), d.Containerd.Archives...)
633-
expect.AdditionalDisks = append(append(o.AdditionalDisks, y.AdditionalDisks...), d.AdditionalDisks...)
634-
expect.Firmware.Images = append(append(o.Firmware.Images, y.Firmware.Images...), d.Firmware.Images...)
631+
expect.Provision = append(append(o.Provision, y.Provision...), dExpect.Provision...)
632+
expect.Probes = append(append(o.Probes, y.Probes...), dExpect.Probes...)
633+
expect.PortForwards = append(append(o.PortForwards, y.PortForwards...), dExpect.PortForwards...)
634+
expect.CopyToHost = append(append(o.CopyToHost, y.CopyToHost...), dExpect.CopyToHost...)
635+
expect.Containerd.Archives = append(append(o.Containerd.Archives, y.Containerd.Archives...), dExpect.Containerd.Archives...)
636+
expect.Containerd.Archives[3].Arch = *expect.Arch
637+
expect.AdditionalDisks = append(append(o.AdditionalDisks, y.AdditionalDisks...), dExpect.AdditionalDisks...)
638+
expect.Firmware.Images = append(append(o.Firmware.Images, y.Firmware.Images...), dExpect.Firmware.Images...)
635639

636-
expect.HostResolver.Hosts["default"] = d.HostResolver.Hosts["default"]
637-
expect.HostResolver.Hosts["MY.Host"] = d.HostResolver.Hosts["host.lima.internal"]
640+
expect.HostResolver.Hosts["default"] = dExpect.HostResolver.Hosts["default"]
641+
expect.HostResolver.Hosts["MY.Host"] = dExpect.HostResolver.Hosts["host.lima.internal"]
638642

639-
// o.Mounts just makes d.Mounts[0] writable because the Location matches
640-
expect.Mounts = append(append([]Mount{}, d.Mounts...), y.Mounts...)
643+
// o.Mounts just makes dExpect.Mounts[0] writable because the Location matches
644+
expect.Mounts = append(append([]Mount{}, dExpect.Mounts...), y.Mounts...)
641645
expect.Mounts[0].Writable = ptr.Of(true)
642646
expect.Mounts[0].SSHFS.Cache = ptr.Of(false)
643647
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(true)
@@ -650,8 +654,8 @@ func TestFillDefault(t *testing.T) {
650654
expect.MountType = ptr.Of(NINEP)
651655
expect.MountInotify = ptr.Of(true)
652656

653-
// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface
654-
expect.Networks = append(append(d.Networks, y.Networks...), o.Networks[0])
657+
// o.Networks[1] is overriding the dExpect.Networks[0].Lima entry for the "def0" interface
658+
expect.Networks = append(append(dExpect.Networks, y.Networks...), o.Networks[0])
655659
expect.Networks[0].Lima = o.Networks[1].Lima
656660

657661
// Only highest prio DNS are retained

0 commit comments

Comments
 (0)