Skip to content

Commit c469ddf

Browse files
committed
limayaml/defaults_test.go: use slices.Clone() to create expect variable
to avoid input variable were changed on preparing `expect` variable. Signed-off-by: Norio Nomura <[email protected]> limayaml: revert fixing expect Signed-off-by: Norio Nomura <[email protected]>
1 parent 42b9595 commit c469ddf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/limayaml/defaults_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"runtime"
9+
"slices"
910
"testing"
1011

1112
"github.com/google/go-cmp/cmp"
@@ -201,7 +202,7 @@ func TestFillDefault(t *testing.T) {
201202
"MY.Host": "host.lima.internal",
202203
}
203204

204-
expect.Mounts = y.Mounts
205+
expect.Mounts = slices.Clone(y.Mounts)
205206
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
206207
expect.Mounts[0].Writable = ptr.Of(false)
207208
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
@@ -218,20 +219,20 @@ func TestFillDefault(t *testing.T) {
218219

219220
expect.MountInotify = ptr.Of(false)
220221

221-
expect.Provision = y.Provision
222+
expect.Provision = slices.Clone(y.Provision)
222223
expect.Provision[0].Mode = ProvisionModeSystem
223224
expect.Provision[0].Script = "#!/bin/true # Eins"
224225

225-
expect.Probes = y.Probes
226+
expect.Probes = slices.Clone(y.Probes)
226227
expect.Probes[0].Mode = ProbeModeReadiness
227228
expect.Probes[0].Description = "user probe 1/1"
228229
expect.Probes[0].Script = "#!/bin/true # Eins"
229230

230-
expect.Networks = y.Networks
231+
expect.Networks = slices.Clone(y.Networks)
231232
expect.Networks[0].MACAddress = MACAddress(fmt.Sprintf("%s#%d", filePath, 0))
232233
expect.Networks[0].Interface = "lima0"
233234

234-
expect.DNS = y.DNS
235+
expect.DNS = slices.Clone(y.DNS)
235236
expect.PortForwards = []PortForward{
236237
defaultPortForward,
237238
defaultPortForward,
@@ -273,6 +274,7 @@ func TestFillDefault(t *testing.T) {
273274

274275
expect.TimeZone = y.TimeZone
275276
expect.Firmware = y.Firmware
277+
expect.Firmware.Images = slices.Clone(y.Firmware.Images)
276278

277279
expect.Rosetta = Rosetta{
278280
Enabled: ptr.Of(false),
@@ -410,7 +412,9 @@ func TestFillDefault(t *testing.T) {
410412

411413
expect = d
412414
// Also verify that archive arch is filled in
415+
expect.Containerd.Archives = slices.Clone(d.Containerd.Archives)
413416
expect.Containerd.Archives[0].Arch = *d.Arch
417+
expect.Mounts = slices.Clone(d.Mounts)
414418
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
415419
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
416420
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -651,7 +655,7 @@ func TestFillDefault(t *testing.T) {
651655
expect.Networks[0].Lima = o.Networks[1].Lima
652656

653657
// Only highest prio DNS are retained
654-
expect.DNS = o.DNS
658+
expect.DNS = slices.Clone(o.DNS)
655659

656660
// ONE remains from filledDefaults.Env; the rest are set from o
657661
expect.Env["ONE"] = y.Env["ONE"]

0 commit comments

Comments
 (0)