Skip to content

Commit 760a8cf

Browse files
committed
refactor: use maps.Copy for merging maps in tests
Replace manual for-range loops that copied map entries with `maps.Copy` in test files. Added the "maps" import to as needed to simplify map merging and improve readability. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent 7689688 commit 760a8cf

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

builder/vmware/iso/builder_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package iso
66

77
import (
88
"fmt"
9+
"maps"
910
"os"
1011
"path/filepath"
1112
"reflect"
@@ -595,9 +596,7 @@ func TestBuilderPrepare_ToolsMode(t *testing.T) {
595596
for _, tc := range testCases {
596597
t.Run(tc.name, func(t *testing.T) {
597598
config := testConfig()
598-
for k, v := range tc.config {
599-
config[k] = v
600-
}
599+
maps.Copy(config, tc.config)
601600

602601
var b Builder
603602
_, warns, err := b.Prepare(config)

builder/vmware/iso/step_create_vmx_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13+
"maps"
1314
"os"
1415
"os/exec"
1516
"path/filepath"
@@ -85,9 +86,7 @@ func RenderConfig(builderConfig map[string]interface{}, provisionerConfig map[st
8586
},
8687
}
8788
// apply special builder overrides
88-
for k, v := range builderConfig {
89-
t["builders"][0][k] = v
90-
}
89+
maps.Copy(t["builders"][0], builderConfig)
9190
// Apply special provisioner overrides
9291
for k, v := range provisionerConfig {
9392
t["provisioners"][0][k] = v

0 commit comments

Comments
 (0)