mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
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:
parent
a362ef6bd4
commit
29a9114409
@ -66,7 +66,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *fence.FenceClusterNetworkRequest,
|
req *fence.FenceClusterNetworkRequest,
|
||||||
) (*fence.FenceClusterNetworkResponse, error) {
|
) (*fence.FenceClusterNetworkResponse, error) {
|
||||||
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
|
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
|
|||||||
}
|
}
|
||||||
defer cr.DeleteCredentials()
|
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 {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *fence.UnfenceClusterNetworkRequest,
|
req *fence.UnfenceClusterNetworkRequest,
|
||||||
) (*fence.UnfenceClusterNetworkResponse, error) {
|
) (*fence.UnfenceClusterNetworkResponse, error) {
|
||||||
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
|
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
|
|||||||
}
|
}
|
||||||
defer cr.DeleteCredentials()
|
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 {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/csi-addons/spec/lib/go/fence"
|
"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()
|
// TestFenceClusterNetwork is a minimal test for the FenceClusterNetwork()
|
||||||
@ -39,7 +39,7 @@ func TestFenceClusterNetwork(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := controller.FenceClusterNetwork(context.TODO(), req)
|
_, err := controller.FenceClusterNetwork(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
|
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
|
||||||
@ -55,5 +55,5 @@ func TestUnfenceClusterNetwork(t *testing.T) {
|
|||||||
Cidrs: nil,
|
Cidrs: nil,
|
||||||
}
|
}
|
||||||
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
|
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ type Cidrs []*fence.CIDR
|
|||||||
func GetCIDR(cidrs Cidrs) ([]string, error) {
|
func GetCIDR(cidrs Cidrs) ([]string, error) {
|
||||||
var cidrList []string
|
var cidrList []string
|
||||||
for _, cidr := range cidrs {
|
for _, cidr := range cidrs {
|
||||||
cidrList = append(cidrList, cidr.Cidr)
|
cidrList = append(cidrList, cidr.GetCidr())
|
||||||
}
|
}
|
||||||
if len(cidrList) < 1 {
|
if len(cidrList) < 1 {
|
||||||
return nil, errors.New("the CIDR cannot be empty")
|
return nil, errors.New("the CIDR cannot be empty")
|
||||||
|
@ -19,7 +19,7 @@ package networkfence
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetIPRange(t *testing.T) {
|
func TestGetIPRange(t *testing.T) {
|
||||||
@ -47,10 +47,10 @@ func TestGetIPRange(t *testing.T) {
|
|||||||
t.Run(ts.cidr, func(t *testing.T) {
|
t.Run(ts.cidr, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
got, err := getIPRange(ts.cidr)
|
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.
|
// 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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *fence.FenceClusterNetworkRequest,
|
req *fence.FenceClusterNetworkRequest,
|
||||||
) (*fence.FenceClusterNetworkResponse, error) {
|
) (*fence.FenceClusterNetworkResponse, error) {
|
||||||
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
|
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func (fcs *FenceControllerServer) FenceClusterNetwork(
|
|||||||
}
|
}
|
||||||
defer cr.DeleteCredentials()
|
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 {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *fence.UnfenceClusterNetworkRequest,
|
req *fence.UnfenceClusterNetworkRequest,
|
||||||
) (*fence.UnfenceClusterNetworkResponse, error) {
|
) (*fence.UnfenceClusterNetworkResponse, error) {
|
||||||
err := validateNetworkFenceReq(req.GetCidrs(), req.Parameters)
|
err := validateNetworkFenceReq(req.GetCidrs(), req.GetParameters())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(
|
|||||||
}
|
}
|
||||||
defer cr.DeleteCredentials()
|
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 {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
"github.com/csi-addons/spec/lib/go/fence"
|
"github.com/csi-addons/spec/lib/go/fence"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestFenceClusterNetwork is a minimal test for the FenceClusterNetwork()
|
// TestFenceClusterNetwork is a minimal test for the FenceClusterNetwork()
|
||||||
@ -37,7 +36,7 @@ func TestFenceClusterNetwork(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := controller.FenceClusterNetwork(context.TODO(), req)
|
_, err := controller.FenceClusterNetwork(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
|
// TestUnfenceClusterNetwork is a minimal test for the UnfenceClusterNetwork()
|
||||||
@ -53,5 +52,5 @@ func TestUnfenceClusterNetwork(t *testing.T) {
|
|||||||
Cidrs: nil,
|
Cidrs: nil,
|
||||||
}
|
}
|
||||||
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
|
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
rs "github.com/csi-addons/spec/lib/go/reclaimspace"
|
rs "github.com/csi-addons/spec/lib/go/reclaimspace"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestControllerReclaimSpace is a minimal test for the
|
// TestControllerReclaimSpace is a minimal test for the
|
||||||
@ -39,7 +38,7 @@ func TestControllerReclaimSpace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := controller.ControllerReclaimSpace(context.TODO(), req)
|
_, err := controller.ControllerReclaimSpace(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNodeReclaimSpace is a minimal test for the NodeReclaimSpace() procedure.
|
// TestNodeReclaimSpace is a minimal test for the NodeReclaimSpace() procedure.
|
||||||
@ -58,5 +57,5 @@ func TestNodeReclaimSpace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := node.NodeReclaimSpace(context.TODO(), req)
|
_, err := node.NodeReclaimSpace(context.TODO(), req)
|
||||||
assert.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
@ -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())
|
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())
|
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)
|
err = rbdVol.ResyncVol(localStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, getGRPCError(err)
|
return nil, getGRPCError(err)
|
||||||
@ -738,7 +738,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
|
|||||||
|
|
||||||
// timestampToString converts the time.Time object to string.
|
// timestampToString converts the time.Time object to string.
|
||||||
func timestampToString(st *timestamppb.Timestamp) 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
|
// 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get last sync info: %w", err)
|
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")
|
return errors.New("last sync time is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
librbd "github.com/ceph/go-ceph/rbd"
|
librbd "github.com/ceph/go-ceph/rbd"
|
||||||
"github.com/ceph/go-ceph/rbd/admin"
|
"github.com/ceph/go-ceph/rbd/admin"
|
||||||
"github.com/csi-addons/spec/lib/go/replication"
|
"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/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"google.golang.org/protobuf/types/known/durationpb"
|
"google.golang.org/protobuf/types/known/durationpb"
|
||||||
@ -511,19 +511,29 @@ func TestValidateLastSyncInfo(t *testing.T) {
|
|||||||
tt.expectedErr, err)
|
tt.expectedErr, err)
|
||||||
}
|
}
|
||||||
if teststruct != nil {
|
if teststruct != nil {
|
||||||
if teststruct.LastSyncTime.GetSeconds() != tt.info.LastSyncTime.GetSeconds() {
|
if teststruct.GetLastSyncTime().GetSeconds() != tt.info.GetLastSyncTime().GetSeconds() {
|
||||||
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncTime, tt.info.LastSyncTime)
|
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
|
||||||
|
tt.name,
|
||||||
|
teststruct.GetLastSyncTime(),
|
||||||
|
tt.info.GetLastSyncTime())
|
||||||
}
|
}
|
||||||
if tt.info.LastSyncDuration == nil && teststruct.LastSyncDuration != nil {
|
if tt.info.GetLastSyncDuration() == nil && teststruct.GetLastSyncDuration() != nil {
|
||||||
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncDuration,
|
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
|
||||||
tt.info.LastSyncDuration)
|
tt.name,
|
||||||
|
teststruct.GetLastSyncDuration(),
|
||||||
|
tt.info.GetLastSyncDuration())
|
||||||
}
|
}
|
||||||
if teststruct.LastSyncDuration.GetSeconds() != tt.info.LastSyncDuration.GetSeconds() {
|
if teststruct.GetLastSyncDuration().GetSeconds() != tt.info.GetLastSyncDuration().GetSeconds() {
|
||||||
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncDuration,
|
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v",
|
||||||
tt.info.LastSyncDuration)
|
tt.name,
|
||||||
|
teststruct.GetLastSyncDuration(),
|
||||||
|
tt.info.GetLastSyncDuration())
|
||||||
}
|
}
|
||||||
if teststruct.LastSyncBytes != tt.info.LastSyncBytes {
|
if teststruct.GetLastSyncBytes() != tt.info.GetLastSyncBytes() {
|
||||||
t.Errorf("name: %v, getLastSyncInfo() %v, expected %v", tt.name, teststruct.LastSyncBytes, tt.info.LastSyncBytes)
|
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.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
result := getGRPCError(tt.err)
|
result := getGRPCError(tt.err)
|
||||||
assert.Equal(t, tt.expectedErr, result)
|
require.Equal(t, tt.expectedErr, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package server
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ func TestNewCSIAddonsServer(t *testing.T) {
|
|||||||
|
|
||||||
cas, err := NewCSIAddonsServer("")
|
cas, err := NewCSIAddonsServer("")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Nil(t, cas)
|
require.Nil(t, cas)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("no UDS endpoint", func(t *testing.T) {
|
t.Run("no UDS endpoint", func(t *testing.T) {
|
||||||
@ -47,6 +46,6 @@ func TestNewCSIAddonsServer(t *testing.T) {
|
|||||||
|
|
||||||
cas, err := NewCSIAddonsServer("endpoint at /tmp/...")
|
cas, err := NewCSIAddonsServer("endpoint at /tmp/...")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Nil(t, cas)
|
require.Nil(t, cas)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user