csi-addons: address golangci-lint issues

addressed golangci-lint issues in csi-addons
code.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-04-04 10:51:19 +02:00 committed by mergify[bot]
parent a362ef6bd4
commit 29a9114409
10 changed files with 48 additions and 41 deletions

View File

@ -66,7 +66,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
ctx context.Context,
req *fence.FenceClusterNetworkRequest,
) (*fence.FenceClusterNetworkResponse, error) {
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@ -77,7 +77,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
}
defer cr.DeleteCredentials()
nwFence, err := nf.NewNetworkFence(ctx, cr, req.Cidrs, req.GetParameters())
nwFence, err := nf.NewNetworkFence(ctx, cr, req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -95,7 +95,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
ctx context.Context,
req *fence.UnfenceClusterNetworkRequest,
) (*fence.UnfenceClusterNetworkResponse, error) {
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@ -106,7 +106,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
}
defer cr.DeleteCredentials()
nwFence, err := nf.NewNetworkFence(ctx, cr, req.Cidrs, req.GetParameters())
nwFence, err := nf.NewNetworkFence(ctx, cr, req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

View File

@ -21,7 +21,7 @@ import (
"testing"
"github.com/csi-addons/spec/lib/go/fence"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestFenceClusterNetwork is a minimal test for the FenceClusterNetwork()
@ -39,7 +39,7 @@ func TestFenceClusterNetwork(t *testing.T) {
}
_, err := controller.FenceClusterNetwork(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
@ -55,5 +55,5 @@ func TestUnfenceClusterNetwork(t *testing.T) {
Cidrs: nil,
}
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}

View File

@ -348,7 +348,7 @@ type Cidrs []*fence.CIDR
func GetCIDR(cidrs Cidrs) ([]string, error) {
var cidrList []string
for _, cidr := range cidrs {
cidrList = append(cidrList, cidr.Cidr)
cidrList = append(cidrList, cidr.GetCidr())
}
if len(cidrList) < 1 {
return nil, errors.New("the CIDR cannot be empty")

View File

@ -19,7 +19,7 @@ package networkfence
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetIPRange(t *testing.T) {
@ -47,10 +47,10 @@ func TestGetIPRange(t *testing.T) {
t.Run(ts.cidr, func(t *testing.T) {
t.Parallel()
got, err := getIPRange(ts.cidr)
assert.NoError(t, err)
require.NoError(t, err)
// validate if number of IPs in the range is same as expected, if not, fail.
assert.ElementsMatch(t, ts.expectedIPs, got)
require.ElementsMatch(t, ts.expectedIPs, got)
})
}
}

View File

@ -62,7 +62,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
ctx context.Context,
req *fence.FenceClusterNetworkRequest,
) (*fence.FenceClusterNetworkResponse, error) {
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@ -73,7 +73,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
}
defer cr.DeleteCredentials()
nwFence, err := nf.NewNetworkFence(ctx, cr, req.Cidrs, req.GetParameters())
nwFence, err := nf.NewNetworkFence(ctx, cr, req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -91,7 +91,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
ctx context.Context,
req *fence.UnfenceClusterNetworkRequest,
) (*fence.UnfenceClusterNetworkResponse, error) {
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@ -102,7 +102,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
}
defer cr.DeleteCredentials()
nwFence, err := nf.NewNetworkFence(ctx, cr, req.Cidrs, req.GetParameters())
nwFence, err := nf.NewNetworkFence(ctx, cr, req.GetCidrs(), req.GetParameters())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

View File

@ -17,9 +17,8 @@ import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/csi-addons/spec/lib/go/fence"
"github.com/stretchr/testify/require"
)
// TestFenceClusterNetwork is a minimal test for the FenceClusterNetwork()
@ -37,7 +36,7 @@ func TestFenceClusterNetwork(t *testing.T) {
}
_, err := controller.FenceClusterNetwork(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
@ -53,5 +52,5 @@ func TestUnfenceClusterNetwork(t *testing.T) {
Cidrs: nil,
}
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}

View File

@ -20,9 +20,8 @@ import (
"context"
"testing"
"github.com/stretchr/testify/assert"
rs "github.com/csi-addons/spec/lib/go/reclaimspace"
"github.com/stretchr/testify/require"
)
// TestControllerReclaimSpace is a minimal test for the
@ -39,7 +38,7 @@ func TestControllerReclaimSpace(t *testing.T) {
}
_, err := controller.ControllerReclaimSpace(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}
// TestNodeReclaimSpace is a minimal test for the NodeReclaimSpace() procedure.
@ -58,5 +57,5 @@ func TestNodeReclaimSpace(t *testing.T) {
}
_, err := node.NodeReclaimSpace(context.TODO(), req)
assert.Error(t, err)
require.Error(t, err)
}

View File

@ -709,7 +709,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
return nil, status.Errorf(codes.Internal, "failed to parse image creation time: %s", sErr.Error())
}
log.DebugLog(ctx, "image %s, savedImageTime=%v, currentImageTime=%v", rbdVol, st, creationTime.AsTime())
if req.Force && st.Equal(creationTime.AsTime()) {
if req.GetForce() && st.Equal(creationTime.AsTime()) {
err = rbdVol.ResyncVol(localStatus)
if err != nil {
return nil, getGRPCError(err)
@ -738,7 +738,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
// timestampToString converts the time.Time object to string.
func timestampToString(st *timestamppb.Timestamp) string {
return fmt.Sprintf("seconds:%d nanos:%d", st.Seconds, st.Nanos)
return fmt.Sprintf("seconds:%d nanos:%d", st.GetSeconds(), st.GetNanos())
}
// timestampFromString parses the timestamp string and returns the time.Time
@ -989,7 +989,7 @@ func checkVolumeResyncStatus(ctx context.Context, localStatus librbd.SiteMirrorI
if err != nil {
return fmt.Errorf("failed to get last sync info: %w", err)
}
if resp.LastSyncTime == nil {
if resp.GetLastSyncTime() == nil {
return errors.New("last sync time is nil")
}

View File

@ -30,7 +30,7 @@ import (
librbd "github.com/ceph/go-ceph/rbd"
"github.com/ceph/go-ceph/rbd/admin"
"github.com/csi-addons/spec/lib/go/replication"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"
@ -511,19 +511,29 @@ func TestValidateLastSyncInfo(t *testing.T) {
tt.expectedErr, err)
}
if teststruct != nil {
if teststruct.LastSyncTime.GetSeconds() != tt.info.LastSyncTime.GetSeconds() {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncTime, tt.info.LastSyncTime)
if teststruct.GetLastSyncTime().GetSeconds() != tt.info.GetLastSyncTime().GetSeconds() {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
tt.name,
teststruct.GetLastSyncTime(),
tt.info.GetLastSyncTime())
}
if tt.info.LastSyncDuration == nil && teststruct.LastSyncDuration != nil {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncDuration,
tt.info.LastSyncDuration)
if tt.info.GetLastSyncDuration() == nil && teststruct.GetLastSyncDuration() != nil {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
tt.name,
teststruct.GetLastSyncDuration(),
tt.info.GetLastSyncDuration())
}
if teststruct.LastSyncDuration.GetSeconds() != tt.info.LastSyncDuration.GetSeconds() {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncDuration,
tt.info.LastSyncDuration)
if teststruct.GetLastSyncDuration().GetSeconds() != tt.info.GetLastSyncDuration().GetSeconds() {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
tt.name,
teststruct.GetLastSyncDuration(),
tt.info.GetLastSyncDuration())
}
if teststruct.LastSyncBytes != tt.info.LastSyncBytes {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncBytes, tt.info.LastSyncBytes)
if teststruct.GetLastSyncBytes() != tt.info.GetLastSyncBytes() {
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
tt.name,
teststruct.GetLastSyncBytes(),
tt.info.GetLastSyncBytes())
}
}
})
@ -594,7 +604,7 @@ func TestGetGRPCError(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := getGRPCError(tt.err)
assert.Equal(t, tt.expectedErr, result)
require.Equal(t, tt.expectedErr, result)
})
}
}

View File

@ -19,7 +19,6 @@ package server
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -39,7 +38,7 @@ func TestNewCSIAddonsServer(t *testing.T) {
cas, err := NewCSIAddonsServer("")
require.Error(t, err)
assert.Nil(t, cas)
require.Nil(t, cas)
})
t.Run("no UDS endpoint", func(t *testing.T) {
@ -47,6 +46,6 @@ func TestNewCSIAddonsServer(t *testing.T) {
cas, err := NewCSIAddonsServer("endpoint at /tmp/...")
require.Error(t, err)
assert.Nil(t, cas)
require.Nil(t, cas)
})
}