From 2b4d8a09ff2abded7b017b0a0d938d3982ff36c8 Mon Sep 17 00:00:00 2001 From: xinhangzhou <123058040+xinhangzhou@users.noreply.github.com> Date: Tue, 25 Mar 2025 03:23:10 +0800 Subject: [PATCH] refactor: use maps.Copy for cleaner map handling (#15090) Signed-off-by: xinhangzhou --- beacon-chain/rpc/endpoints_test.go | 9 ++++++++- beacon-chain/rpc/service_test.go | 12 ------------ changelog/xinhangzhou_use_maps.Copy.md | 3 +++ 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 changelog/xinhangzhou_use_maps.Copy.md diff --git a/beacon-chain/rpc/endpoints_test.go b/beacon-chain/rpc/endpoints_test.go index 80bcc23259..22ce9490f2 100644 --- a/beacon-chain/rpc/endpoints_test.go +++ b/beacon-chain/rpc/endpoints_test.go @@ -150,7 +150,14 @@ func Test_endpoints(t *testing.T) { actualRoutes[e.template] = e.methods } } - expectedRoutes := combineMaps(beaconRoutes, builderRoutes, configRoutes, debugRoutes, eventsRoutes, nodeRoutes, validatorRoutes, rewardsRoutes, lightClientRoutes, blobRoutes, prysmValidatorRoutes, prysmNodeRoutes, prysmBeaconRoutes) + expectedRoutes := make(map[string][]string) + for _, m := range []map[string][]string{ + beaconRoutes, builderRoutes, configRoutes, debugRoutes, eventsRoutes, + nodeRoutes, validatorRoutes, rewardsRoutes, lightClientRoutes, blobRoutes, + prysmValidatorRoutes, prysmNodeRoutes, prysmBeaconRoutes, + } { + maps.Copy(expectedRoutes, m) + } assert.Equal(t, true, maps.EqualFunc(expectedRoutes, actualRoutes, func(actualMethods []string, expectedMethods []string) bool { return slices.Equal(expectedMethods, actualMethods) diff --git a/beacon-chain/rpc/service_test.go b/beacon-chain/rpc/service_test.go index 4cd599c419..b7b4d61784 100644 --- a/beacon-chain/rpc/service_test.go +++ b/beacon-chain/rpc/service_test.go @@ -23,18 +23,6 @@ func init() { logrus.SetOutput(io.Discard) } -func combineMaps(maps ...map[string][]string) map[string][]string { - combinedMap := make(map[string][]string) - - for _, m := range maps { - for k, v := range m { - combinedMap[k] = v - } - } - - return combinedMap -} - func TestLifecycle_OK(t *testing.T) { hook := logTest.NewGlobal() chainService := &mock.ChainService{ diff --git a/changelog/xinhangzhou_use_maps.Copy.md b/changelog/xinhangzhou_use_maps.Copy.md new file mode 100644 index 0000000000..f5820903f9 --- /dev/null +++ b/changelog/xinhangzhou_use_maps.Copy.md @@ -0,0 +1,3 @@ +### Ignored + +- Use maps.Copy for cleaner map handling \ No newline at end of file