From e25aba1e2634336840c4fd10c4be6dfc8b0922c4 Mon Sep 17 00:00:00 2001 From: Yusuke Kadowaki Date: Sun, 21 Jan 2024 20:01:11 +0900 Subject: [PATCH] Fix deeepsource errors (#2299) * Fix references to loop variable from within nested function * Skip necessary lock erroneously passed by valu * Refactor discovererClient function signature * format * skip copylocks --- .../v1/client/discoverer/discover_test.go | 20 +++++++++++++++---- pkg/gateway/lb/usecase/vald.go | 2 +- pkg/gateway/lb/usecase/vald_test.go | 10 +++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/internal/client/v1/client/discoverer/discover_test.go b/internal/client/v1/client/discoverer/discover_test.go index fb4b403227..345d68eb3f 100644 --- a/internal/client/v1/client/discoverer/discover_test.go +++ b/internal/client/v1/client/discoverer/discover_test.go @@ -66,7 +66,9 @@ func Test_client_GetReadClient(t *testing.T) { client: &mockClient, readClient: &mockReadClient, readReplicaReplicas: 1, - roundRobin: counter, + //nolint: govet,copylocks + //skipcq: VET-V0008 + roundRobin: counter, }, want: &mockReadClient, } @@ -80,7 +82,9 @@ func Test_client_GetReadClient(t *testing.T) { client: &mockClient, readClient: &mockReadClient, readReplicaReplicas: 1, - roundRobin: counter, + //nolint: govet,copylocks + //skipcq: VET-V0008 + roundRobin: counter, }, want: &mockClient, } @@ -94,20 +98,28 @@ func Test_client_GetReadClient(t *testing.T) { client: &mockClient, readClient: &mockReadClient, readReplicaReplicas: 3, - roundRobin: counter, + //nolint: govet,copylocks + //skipcq: VET-V0008 + roundRobin: counter, }, want: &mockClient, } }(), } + //nolint: govet,copylocks + //skipcq: VET-V0008 for _, tc := range tests { + //nolint: govet,copylocks + //skipcq: VET-V0008 test := tc t.Run(test.name, func(t *testing.T) { c := &client{ client: test.fields.client, readClient: test.fields.readClient, readReplicaReplicas: test.fields.readReplicaReplicas, - roundRobin: test.fields.roundRobin, + //nolint: govet,copylocks + //skipcq: VET-V0008 + roundRobin: test.fields.roundRobin, } got := c.GetReadClient() if !reflect.DeepEqual(got, test.want) { diff --git a/pkg/gateway/lb/usecase/vald.go b/pkg/gateway/lb/usecase/vald.go index b8dc5e3948..b348b66639 100644 --- a/pkg/gateway/lb/usecase/vald.go +++ b/pkg/gateway/lb/usecase/vald.go @@ -46,7 +46,7 @@ type run struct { gateway service.Gateway } -func discovererClient(cfg *config.Data, dopts []grpc.Option, aopts []grpc.Option, eg errgroup.Group) (discoverer.Client, error) { +func discovererClient(cfg *config.Data, dopts, aopts []grpc.Option, eg errgroup.Group) (discoverer.Client, error) { var discovererOpts []discoverer.Option discovererOpts = append(discovererOpts, discoverer.WithAutoConnect(true), diff --git a/pkg/gateway/lb/usecase/vald_test.go b/pkg/gateway/lb/usecase/vald_test.go index c6e32773f0..f8a60a09d5 100644 --- a/pkg/gateway/lb/usecase/vald_test.go +++ b/pkg/gateway/lb/usecase/vald_test.go @@ -23,10 +23,9 @@ import ( "github.com/stretchr/testify/require" "github.com/vdaas/vald/internal/client/v1/client/discoverer" iconfig "github.com/vdaas/vald/internal/config" + "github.com/vdaas/vald/internal/net/grpc" "github.com/vdaas/vald/internal/sync/errgroup" "github.com/vdaas/vald/pkg/gateway/lb/config" - - "github.com/vdaas/vald/internal/net/grpc" ) func Test_discovererClient(t *testing.T) { @@ -100,10 +99,11 @@ func Test_discovererClient(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + test := tt + t.Run(test.name, func(t *testing.T) { t.Parallel() - client, err := discovererClient(tt.cfg, tt.dopts, tt.aopts, errgroup.Get()) - tt.assert(t, client, err) + client, err := discovererClient(test.cfg, test.dopts, test.aopts, errgroup.Get()) + test.assert(t, client, err) }) } }