Skip to content

Commit eacc7b8

Browse files
committed
fix: issue from golangci-lint about formatted, maps.Copy and embedded field
Signed-off-by: Shouren Yang <yangshouren@gmail.com>
1 parent 272a9c9 commit eacc7b8

4 files changed

Lines changed: 9 additions & 14 deletions

File tree

pkg/device/devices.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"errors"
2222
"fmt"
23+
"maps"
2324
"slices"
2425
"strconv"
2526
"strings"
@@ -215,9 +216,7 @@ func (d *DeviceUsage) DeepCopy() *DeviceUsage {
215216

216217
if d.CustomInfo != nil {
217218
dup.CustomInfo = make(map[string]any, len(d.CustomInfo))
218-
for k, v := range d.CustomInfo {
219-
dup.CustomInfo[k] = v
220-
}
219+
maps.Copy(dup.CustomInfo, d.CustomInfo)
221220
}
222221

223222
return dup

pkg/device/devices_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,6 @@ func TestCheckUUID(t *testing.T) {
11911191
}
11921192
}
11931193

1194-
11951194
func TestDeviceUsageDeepCopy(t *testing.T) {
11961195
tests := []struct {
11971196
name string
@@ -1228,9 +1227,9 @@ func TestDeviceUsageDeepCopy(t *testing.T) {
12281227
{Name: "1g.5gb", Core: 1, Memory: 5, InUse: false},
12291228
},
12301229
},
1231-
Numa: 0,
1232-
Type: "NVIDIA",
1233-
Health: true,
1230+
Numa: 0,
1231+
Type: "NVIDIA",
1232+
Health: true,
12341233
PodInfos: []*PodInfo{
12351234
{
12361235
Pod: &corev1.Pod{

pkg/device/pod_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ func TestUpdatePod(t *testing.T) {
377377
}
378378
}
379379

380-
381380
func TestPodInfoDeepCopy(t *testing.T) {
382381
tests := []struct {
383382
name string
@@ -430,14 +429,14 @@ func TestPodInfoDeepCopy(t *testing.T) {
430429
assert.Equal(t, tt.original.CtrIDs, copy.CtrIDs)
431430
assert.Equal(t, tt.original.Devices, copy.Devices)
432431
if tt.original.Pod != nil {
433-
assert.Equal(t, tt.original.Pod.Name, copy.Pod.Name)
432+
assert.Equal(t, tt.original.Name, copy.Name)
434433
}
435434

436435
// 2. Mutating the copy must not affect the original.
437436
if copy.Pod != nil {
438-
originalPodName := tt.original.Pod.Name
437+
originalPodName := tt.original.Name
439438
copy.Pod.Name = "mutated-pod"
440-
assert.Equal(t, tt.original.Pod.Name, originalPodName)
439+
assert.Equal(t, tt.original.Name, originalPodName)
441440
}
442441
originalNodeID := tt.original.NodeID
443442
copy.NodeID = "mutated-node"

pkg/device/pods.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ func (c ContainerDevice) DeepCopy() ContainerDevice {
211211
}
212212
if c.CustomInfo != nil {
213213
dup.CustomInfo = make(map[string]any, len(c.CustomInfo))
214-
for k, v := range c.CustomInfo {
215-
dup.CustomInfo[k] = v
216-
}
214+
maps.Copy(dup.CustomInfo, c.CustomInfo)
217215
}
218216
return dup
219217
}

0 commit comments

Comments
 (0)