Skip to content

Commit

Permalink
Fix deeepsource errors (#2299)
Browse files Browse the repository at this point in the history
* Fix references to loop variable from within nested function

* Skip necessary lock erroneously passed by valu

* Refactor discovererClient function signature

* format

* skip copylocks
  • Loading branch information
ykadowak committed Jan 21, 2024
1 parent ea6a157 commit e25aba1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
20 changes: 16 additions & 4 deletions internal/client/v1/client/discoverer/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/lb/usecase/vald.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions pkg/gateway/lb/usecase/vald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit e25aba1

Please sign in to comment.