Skip to content

Commit e658cf4

Browse files
authored
refactor: use maps.Copy for cleaner map handling (#4119)
Signed-off-by: jishudashu <979260390@qq.com>
1 parent 0980edf commit e658cf4

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

tests/antithesis/compose.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package antithesis
66
import (
77
"errors"
88
"fmt"
9+
"maps"
910
"os"
1011
"path/filepath"
1112

@@ -179,9 +180,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
179180
}
180181

181182
// Apply configuration appropriate to a test network
182-
for k, v := range tmpnet.DefaultTmpnetFlags() {
183-
env[k] = v
184-
}
183+
maps.Copy(env, tmpnet.DefaultTmpnetFlags())
185184

186185
serviceName := getServiceName(i)
187186

tests/fixture/tmpnet/monitor_processes.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"io/fs"
12+
"maps"
1213
"net/http"
1314
"os"
1415
"os/exec"
@@ -316,9 +317,7 @@ func WritePrometheusSDConfig(name string, sdConfig SDConfig, withGitHubLabels bo
316317
}
317318

318319
func applyGitHubLabels(sdConfig SDConfig) SDConfig {
319-
for label, value := range GetGitHubLabels() {
320-
sdConfig.Labels[label] = value
321-
}
320+
maps.Copy(sdConfig.Labels, GetGitHubLabels())
322321
return sdConfig
323322
}
324323

tests/fixture/tmpnet/network.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/json"
1212
"errors"
1313
"fmt"
14+
"maps"
1415
"net/netip"
1516
"os"
1617
"os/exec"
@@ -926,9 +927,7 @@ func (n *Network) GetMonitoringLabels() map[string]string {
926927
"is_ephemeral_node": "false",
927928
"network_owner": n.Owner,
928929
}
929-
for label, value := range GetGitHubLabels() {
930-
labels[label] = value
931-
}
930+
maps.Copy(labels, GetGitHubLabels())
932931
return labels
933932
}
934933

tests/reexecute/c/vm_reexecute_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"flag"
1111
"fmt"
12+
"maps"
1213
"os"
1314
"path/filepath"
1415
"strings"
@@ -91,9 +92,7 @@ func TestMain(m *testing.M) {
9192
fmt.Fprintf(os.Stderr, "failed to parse labels: %v\n", err)
9293
os.Exit(1)
9394
}
94-
for customLabel, customValue := range customLabels {
95-
labels[customLabel] = customValue
96-
}
95+
maps.Copy(labels, customLabels)
9796

9897
m.Run()
9998
}

vms/platformvm/client.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package platformvm
55

66
import (
77
"context"
8+
"maps"
89
"time"
910

1011
"github.com/ava-labs/avalanchego/api"
@@ -654,11 +655,7 @@ func GetOwners(
654655
}
655656

656657
owners := make(map[ids.ID]fx.Owner, len(subnetOwners)+len(deactivationOwners))
657-
for id, owner := range subnetOwners {
658-
owners[id] = owner
659-
}
660-
for id, owner := range deactivationOwners {
661-
owners[id] = owner
662-
}
658+
maps.Copy(owners, subnetOwners)
659+
maps.Copy(owners, deactivationOwners)
663660
return owners, nil
664661
}

0 commit comments

Comments
 (0)