Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Sep 24, 2024
1 parent e52ab47 commit e6f975f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ issues:
- path: '(.+)test\.go'
linters:
- govet # Test code field alignment for sake of space is not a concern
- path: 'token_manager_test.go'
linters:
- goconst # Test code is allowed to have constants
- path: 'connection_provider_test.go'
linters:
- goconst # Test cod
# - path: dir/sample\.go
# linters:
# - lll # Test code is allowed to have long lines
Expand Down
20 changes: 12 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const (
indexWaitDuration = time.Millisecond * 100
)
const (
failedToInsertRecord = "failed to insert record"
failedToGetRecord = "failed to get record"
failedToDeleteRecord = "failed to delete record"
failedToCheckRecordExists = "failed to check if record exists"
failedToCheckIsIndexed = "failed to check if record is indexed"
failedToInsertRecord = "failed to insert record"
failedToGetRecord = "failed to get record"
failedToDeleteRecord = "failed to delete record"
failedToCheckRecordExists = "failed to check if record exists"
failedToCheckIsIndexed = "failed to check if record is indexed"
failedToWaitForIndexCompletion = "failed to wait for index completion"
)

type connProvider interface {
Expand Down Expand Up @@ -91,6 +92,7 @@ func NewClient(
if err != nil {
grpcToken.Close()
logger.Error("failed to create connection provider", slog.Any("error", err))

return nil, NewAVSErrorFromGrpc("failed to connect to server", err)
}

Expand Down Expand Up @@ -651,11 +653,11 @@ func (c *Client) WaitForIndexCompletion(
waitInterval time.Duration,
) error {
logger := c.logger.With(slog.String("namespace", namespace), slog.String("indexName", indexName))
logger.DebugContext(ctx, "waiting for index completion")
logger.DebugContext(ctx, failedToWaitForIndexCompletion)

conn, err := c.connectionProvider.GetRandomConn()
if err != nil {
msg := "failed to wait for index completion"
msg := failedToWaitForIndexCompletion
logger.Error(msg, slog.Any("error", err))

return NewAVSError(msg, err)
Expand All @@ -672,7 +674,7 @@ func (c *Client) WaitForIndexCompletion(
for {
indexStatus, err := conn.indexClient.GetStatus(ctx, indexStatusReq)
if err != nil {
msg := "failed to wait for index completion"
msg := failedToWaitForIndexCompletion
logger.ErrorContext(ctx, msg, slog.Any("error", err))

return NewAVSError(msg, err)
Expand Down Expand Up @@ -702,7 +704,9 @@ func (c *Client) WaitForIndexCompletion(
case <-timer.C:
case <-ctx.Done():
msg := "failed to wait for index completion"

logger.ErrorContext(ctx, "waiting for index completion canceled")

return NewAVSError(msg, ctx.Err())
}
}
Expand Down
2 changes: 2 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package avs

import (
Expand Down
4 changes: 3 additions & 1 deletion connection_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (cp *connectionProvider) connectToSeeds(ctx context.Context) error {
authErr = err
tokenLock.Unlock()
conn.close()

return
}

Expand All @@ -390,6 +391,7 @@ func (cp *connectionProvider) connectToSeeds(ctx context.Context) error {
if err != nil {
logger.WarnContext(ctx, "failed to connect to seed", slog.Any("error", err))
grpcConn.Close()

return
}

Expand Down Expand Up @@ -475,8 +477,8 @@ func (cp *connectionProvider) getTendConns() []*connection {
// getUpdatedEndpoints retrieves the updated server endpoints from the Aerospike cluster.
func (cp *connectionProvider) getUpdatedEndpoints(ctx context.Context) map[uint64]*protos.ServerEndpointList {
type idAndEndpoints struct {
id uint64
endpoints map[uint64]*protos.ServerEndpointList
id uint64
}

conns := cp.getTendConns()
Expand Down
39 changes: 26 additions & 13 deletions connection_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ func TestNewConnectionProvider_FailSeedsNil(t *testing.T) {
seeds := HostPortSlice{}
listenerName := "listener"
isLoadBalancer := false
tlsConfig := &tls.Config{}
var logger *slog.Logger
var token tokenManager
tlsConfig := &tls.Config{} //nolint:gosec // tests

var (
logger *slog.Logger
token tokenManager
)

cp, err := newConnectionProvider(context.Background(), seeds, &listenerName, isLoadBalancer, token, tlsConfig, logger)
defer cp.Close()
if err == nil {
defer cp.Close()
}

assert.Nil(t, cp)
assert.Equal(t, err, errors.New("seeds cannot be nil or empty"))
Expand All @@ -44,8 +49,10 @@ func TestNewConnectionProvider_FailNoTLS(t *testing.T) {
listenerName := "listener"
isLoadBalancer := false

var tlsConfig *tls.Config
var logger *slog.Logger
var (
tlsConfig *tls.Config
logger *slog.Logger
)

token := NewMocktokenManager(ctrl)

Check failure on line 57 in connection_provider_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: NewMocktokenManager

Expand All @@ -55,7 +62,9 @@ func TestNewConnectionProvider_FailNoTLS(t *testing.T) {
Return(true)

cp, err := newConnectionProvider(context.Background(), seeds, &listenerName, isLoadBalancer, token, tlsConfig, logger)
defer cp.Close()
if err == nil {
defer cp.Close()
}

assert.Nil(t, cp)
assert.Equal(t, err, errors.New("tlsConfig is required when username/password authentication"))
Expand All @@ -77,12 +86,16 @@ func TestNewConnectionProvider_FailConnectToSeedConns(t *testing.T) {
listenerName := "listener"
isLoadBalancer := false

var tlsConfig *tls.Config
var logger *slog.Logger
var token tokenManager
var (
tlsConfig *tls.Config
logger *slog.Logger
token tokenManager
)

cp, err := newConnectionProvider(ctx, seeds, &listenerName, isLoadBalancer, token, tlsConfig, logger)
defer cp.Close()
if err == nil {
defer cp.Close()
}

assert.Nil(t, cp)
assert.Equal(t, "failed to connect to seeds: context deadline exceeded", err.Error())
Expand Down Expand Up @@ -361,7 +374,7 @@ func TestUpdateClusterConns_NewClusterIDWithDIFFERENTNodeIDs(t *testing.T) {
logger: slog.Default(),
nodeConns: make(map[uint64]*connectionAndEndpoints),
seedConns: []*connection{},
tlsConfig: &tls.Config{},
tlsConfig: &tls.Config{}, //nolint:gosec // tests
seeds: HostPortSlice{},
nodeConnsLock: &sync.RWMutex{},
tendInterval: time.Second * 1,
Expand Down Expand Up @@ -610,7 +623,7 @@ func TestUpdateClusterConns_NewClusterIDWithSAMENodeIDs(t *testing.T) {
cp := &connectionProvider{
logger: slog.Default(),
seedConns: []*connection{},
tlsConfig: &tls.Config{},
tlsConfig: &tls.Config{}, //nolint:gosec // tests
seeds: HostPortSlice{},
nodeConnsLock: &sync.RWMutex{},
tendInterval: time.Second * 1,
Expand Down
4 changes: 2 additions & 2 deletions protos/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ func TestConvertToFields(t *testing.T) {
sort.Slice(result, sortFunc(result))
sort.Slice(tc.expected, sortFunc(result))

for i, _ := range tc.expected {
for i := range tc.expected {
assert.EqualExportedValues(t, tc.expected[i], result[i])
}

Expand Down Expand Up @@ -1152,7 +1152,7 @@ func TestConvertFromFields(t *testing.T) {

type unknownVectorType struct{}

func (*unknownVectorType) isVector_Data() {}
func (*unknownVectorType) isVector_Data() {} //nolint:revive,stylecheck // Grpc generated

func TestConvertFromVector(t *testing.T) {
testCases := []struct {
Expand Down
10 changes: 5 additions & 5 deletions token_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRefreshToken_Success(t *testing.T) {
authClient: mockAuthServiceClient,
}

b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDAsImlhdCI6MTcyNzExMDc1NH0.GD01CEWxW6-7lHcyeetM95WKdUlwY85m5lFqzcTCtzs"
b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDAsImlhdCI6MTcyNzExMDc1NH0.GD01CEWxW6-7lHcyeetM95WKdUlwY85m5lFqzcTCtzs" //nolint:gosec,lll // tests

// Set up expectations for AuthServiceClient.Authenticate()
mockAuthServiceClient.
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestRefreshToken_FailedInvalidJson(t *testing.T) {
authClient: mockAuthServiceClient,
}

b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDAsImlhdCI6MTcyNzExMD.GD01CEWxW6-7lHcyeetM95WKdUlwY85m5lFqzcTCtzs"
b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDAsImlhdCI6MTcyNzExMD.GD01CEWxW6-7lHcyeetM95WKdUlwY85m5lFqzcTCtzs" //nolint:gosec,lll // tests

// Set up expectations for AuthServiceClient.Authenticate()
mockAuthServiceClient.
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestRefreshToken_FailedFindExp(t *testing.T) {
authClient: mockAuthServiceClient,
}

b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3MjcxMTA3NTR9.50IZcLoS7mQPzQsKvJZyXNUukvT5FdiqN2tynNIjHuk"
b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3MjcxMTA3NTR9.50IZcLoS7mQPzQsKvJZyXNUukvT5FdiqN2tynNIjHuk" //nolint:gosec,lll // tests

// Set up expectations for AuthServiceClient.Authenticate()
mockAuthServiceClient.
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestRefreshToken_FailedFindIat(t *testing.T) {
authClient: mockAuthServiceClient,
}

b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDB9.f5DtjF1sYLH6fz0ThcFKxwngIXkVMLnhJtIrjLi_1p0"
b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjMwMDAwMDAwMDB9.f5DtjF1sYLH6fz0ThcFKxwngIXkVMLnhJtIrjLi_1p0" //nolint:gosec,lll // tests

// Set up expectations for AuthServiceClient.Authenticate()
mockAuthServiceClient.
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestRefreshToken_FailedTtlLessThan0(t *testing.T) {
authClient: mockAuthServiceClient,
}

b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjE3MjcxMTA3NTMsImlhdCI6MTcyNzExMDc1NH0.YdH5twU6-LGLtgvD2sktiw1j40MRUe_r4oPN565z4Ok"
b64token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjE3MjcxMTA3NTMsImlhdCI6MTcyNzExMDc1NH0.YdH5twU6-LGLtgvD2sktiw1j40MRUe_r4oPN565z4Ok" //nolint:gosec,lll // tests

// Set up expectations for AuthServiceClient.Authenticate()
mockAuthServiceClient.
Expand Down

0 comments on commit e6f975f

Please sign in to comment.