6
6
"os"
7
7
"path/filepath"
8
8
"runtime"
9
+ "slices"
9
10
"testing"
10
11
11
12
"github.com/google/go-cmp/cmp"
@@ -201,7 +202,7 @@ func TestFillDefault(t *testing.T) {
201
202
"MY.Host" : "host.lima.internal" ,
202
203
}
203
204
204
- expect .Mounts = y .Mounts
205
+ expect .Mounts = slices . Clone ( y .Mounts )
205
206
expect .Mounts [0 ].MountPoint = expect .Mounts [0 ].Location
206
207
expect .Mounts [0 ].Writable = ptr .Of (false )
207
208
expect .Mounts [0 ].SSHFS .Cache = ptr .Of (true )
@@ -211,27 +212,27 @@ func TestFillDefault(t *testing.T) {
211
212
expect .Mounts [0 ].NineP .ProtocolVersion = ptr .Of (Default9pProtocolVersion )
212
213
expect .Mounts [0 ].NineP .Msize = ptr .Of (Default9pMsize )
213
214
expect .Mounts [0 ].NineP .Cache = ptr .Of (Default9pCacheForRO )
214
- expect .Mounts [0 ].Virtiofs .QueueSize = ptr . Of ( DefaultVirtiofsQueueSize )
215
+ expect .Mounts [0 ].Virtiofs .QueueSize = nil
215
216
// Only missing Mounts field is Writable, and the default value is also the null value: false
216
217
217
218
expect .MountType = ptr .Of (NINEP )
218
219
219
220
expect .MountInotify = ptr .Of (false )
220
221
221
- expect .Provision = y .Provision
222
+ expect .Provision = slices . Clone ( y .Provision )
222
223
expect .Provision [0 ].Mode = ProvisionModeSystem
223
224
expect .Provision [0 ].Script = "#!/bin/true # Eins"
224
225
225
- expect .Probes = y .Probes
226
+ expect .Probes = slices . Clone ( y .Probes )
226
227
expect .Probes [0 ].Mode = ProbeModeReadiness
227
228
expect .Probes [0 ].Description = "user probe 1/1"
228
- expect .Probes [0 ].Script = "#!/bin/true # Eins"
229
+ expect .Probes [0 ].Script = "#!/bin/false # Eins"
229
230
230
- expect .Networks = y .Networks
231
+ expect .Networks = slices . Clone ( y .Networks )
231
232
expect .Networks [0 ].MACAddress = MACAddress (fmt .Sprintf ("%s#%d" , filePath , 0 ))
232
233
expect .Networks [0 ].Interface = "lima0"
233
234
234
- expect .DNS = y .DNS
235
+ expect .DNS = slices . Clone ( y .DNS )
235
236
expect .PortForwards = []PortForward {
236
237
defaultPortForward ,
237
238
defaultPortForward ,
@@ -273,6 +274,7 @@ func TestFillDefault(t *testing.T) {
273
274
274
275
expect .TimeZone = y .TimeZone
275
276
expect .Firmware = y .Firmware
277
+ expect .Firmware .Images = slices .Clone (y .Firmware .Images )
276
278
277
279
expect .Rosetta = Rosetta {
278
280
Enabled : ptr .Of (false ),
@@ -410,7 +412,9 @@ func TestFillDefault(t *testing.T) {
410
412
411
413
expect = d
412
414
// Also verify that archive arch is filled in
415
+ expect .Containerd .Archives = slices .Clone (d .Containerd .Archives )
413
416
expect .Containerd .Archives [0 ].Arch = * d .Arch
417
+ expect .Mounts = slices .Clone (d .Mounts )
414
418
expect .Mounts [0 ].MountPoint = expect .Mounts [0 ].Location
415
419
expect .Mounts [0 ].SSHFS .Cache = ptr .Of (true )
416
420
expect .Mounts [0 ].SSHFS .FollowSymlinks = ptr .Of (false )
@@ -419,7 +423,7 @@ func TestFillDefault(t *testing.T) {
419
423
expect .Mounts [0 ].NineP .ProtocolVersion = ptr .Of (Default9pProtocolVersion )
420
424
expect .Mounts [0 ].NineP .Msize = ptr .Of (Default9pMsize )
421
425
expect .Mounts [0 ].NineP .Cache = ptr .Of (Default9pCacheForRO )
422
- expect .Mounts [0 ].Virtiofs .QueueSize = ptr . Of ( DefaultVirtiofsQueueSize )
426
+ expect .Mounts [0 ].Virtiofs .QueueSize = nil
423
427
expect .HostResolver .Hosts = map [string ]string {
424
428
"default" : d .HostResolver .Hosts ["default" ],
425
429
}
@@ -447,6 +451,8 @@ func TestFillDefault(t *testing.T) {
447
451
FillDefault (& y , & d , & LimaYAML {}, filePath )
448
452
assert .DeepEqual (t , & y , & expect , opts ... )
449
453
454
+ dExpect := expect
455
+
450
456
// ------------------------------------------------------------------------------------
451
457
// User-provided defaults should not override user-provided config values
452
458
@@ -456,26 +462,27 @@ func TestFillDefault(t *testing.T) {
456
462
457
463
expect = y
458
464
459
- expect .Provision = append (append ([]Provision {}, y .Provision ... ), d .Provision ... )
460
- expect .Probes = append (append ([]Probe {}, y .Probes ... ), d .Probes ... )
461
- expect .PortForwards = append (append ([]PortForward {}, y .PortForwards ... ), d .PortForwards ... )
462
- expect .CopyToHost = append (append ([]CopyToHost {}, y .CopyToHost ... ), d .CopyToHost ... )
463
- expect .Containerd .Archives = append (append ([]File {}, y .Containerd .Archives ... ), d .Containerd .Archives ... )
464
- expect .AdditionalDisks = append (append ([]Disk {}, y .AdditionalDisks ... ), d .AdditionalDisks ... )
465
- 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 ... )
466
473
467
474
// Mounts and Networks start with lowest priority first, so higher priority entries can overwrite
468
- expect .Mounts = append (append ([]Mount {}, d .Mounts ... ), y .Mounts ... )
469
- 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 ... )
470
477
471
- expect .HostResolver .Hosts ["default" ] = d .HostResolver .Hosts ["default" ]
478
+ expect .HostResolver .Hosts ["default" ] = dExpect .HostResolver .Hosts ["default" ]
472
479
473
- // d .DNS will be ignored, and not appended to y.DNS
480
+ // dExpect .DNS will be ignored, and not appended to y.DNS
474
481
475
- // "TWO" does not exist in filledDefaults.Env, so is set from d .Env
476
- 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" ]
477
484
478
- expect .Param ["TWO" ] = d .Param ["TWO" ]
485
+ expect .Param ["TWO" ] = dExpect .Param ["TWO" ]
479
486
480
487
t .Logf ("d.vmType=%q, y.vmType=%q, expect.vmType=%q" , * d .VMType , * y .VMType , * expect .VMType )
481
488
@@ -621,19 +628,20 @@ func TestFillDefault(t *testing.T) {
621
628
622
629
expect = o
623
630
624
- expect .Provision = append (append (o .Provision , y .Provision ... ), d .Provision ... )
625
- expect .Probes = append (append (o .Probes , y .Probes ... ), d .Probes ... )
626
- expect .PortForwards = append (append (o .PortForwards , y .PortForwards ... ), d .PortForwards ... )
627
- expect .CopyToHost = append (append (o .CopyToHost , y .CopyToHost ... ), d .CopyToHost ... )
628
- expect .Containerd .Archives = append (append (o .Containerd .Archives , y .Containerd .Archives ... ), d .Containerd .Archives ... )
629
- expect .AdditionalDisks = append (append (o .AdditionalDisks , y .AdditionalDisks ... ), d .AdditionalDisks ... )
630
- 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 ... )
631
639
632
- expect .HostResolver .Hosts ["default" ] = d .HostResolver .Hosts ["default" ]
633
- 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" ]
634
642
635
- // o.Mounts just makes d .Mounts[0] writable because the Location matches
636
- 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 ... )
637
645
expect .Mounts [0 ].Writable = ptr .Of (true )
638
646
expect .Mounts [0 ].SSHFS .Cache = ptr .Of (false )
639
647
expect .Mounts [0 ].SSHFS .FollowSymlinks = ptr .Of (true )
@@ -646,12 +654,12 @@ func TestFillDefault(t *testing.T) {
646
654
expect .MountType = ptr .Of (NINEP )
647
655
expect .MountInotify = ptr .Of (true )
648
656
649
- // o.Networks[1] is overriding the d .Networks[0].Lima entry for the "def0" interface
650
- 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 ])
651
659
expect .Networks [0 ].Lima = o .Networks [1 ].Lima
652
660
653
661
// Only highest prio DNS are retained
654
- expect .DNS = o .DNS
662
+ expect .DNS = slices . Clone ( o .DNS )
655
663
656
664
// ONE remains from filledDefaults.Env; the rest are set from o
657
665
expect .Env ["ONE" ] = y .Env ["ONE" ]
0 commit comments