diff --git a/internal/csi-addons/cephfs/network_fence.go b/internal/csi-addons/cephfs/network_fence.go index 9ae22c8d4..ecef1a4e0 100644 --- a/internal/csi-addons/cephfs/network_fence.go +++ b/internal/csi-addons/cephfs/network_fence.go @@ -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()) } diff --git a/internal/csi-addons/cephfs/network_fence_test.go b/internal/csi-addons/cephfs/network_fence_test.go index e2e97891a..e24c33fab 100644 --- a/internal/csi-addons/cephfs/network_fence_test.go +++ b/internal/csi-addons/cephfs/network_fence_test.go @@ -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) } diff --git a/internal/csi-addons/networkfence/fencing.go b/internal/csi-addons/networkfence/fencing.go index 5554a0cd3..d49c621e3 100644 --- a/internal/csi-addons/networkfence/fencing.go +++ b/internal/csi-addons/networkfence/fencing.go @@ -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") diff --git a/internal/csi-addons/networkfence/fencing_test.go b/internal/csi-addons/networkfence/fencing_test.go index 26aab00f6..2b5425aa4 100644 --- a/internal/csi-addons/networkfence/fencing_test.go +++ b/internal/csi-addons/networkfence/fencing_test.go @@ -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) }) } } diff --git a/internal/csi-addons/rbd/network_fence.go b/internal/csi-addons/rbd/network_fence.go index 57199747e..b7f4d6bba 100644 --- a/internal/csi-addons/rbd/network_fence.go +++ b/internal/csi-addons/rbd/network_fence.go @@ -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()) } diff --git a/internal/csi-addons/rbd/network_fence_test.go b/internal/csi-addons/rbd/network_fence_test.go index 80ab82130..260a854d6 100644 --- a/internal/csi-addons/rbd/network_fence_test.go +++ b/internal/csi-addons/rbd/network_fence_test.go @@ -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) } diff --git a/internal/csi-addons/rbd/reclaimspace_test.go b/internal/csi-addons/rbd/reclaimspace_test.go index 49bba48aa..6effbc0fa 100644 --- a/internal/csi-addons/rbd/reclaimspace_test.go +++ b/internal/csi-addons/rbd/reclaimspace_test.go @@ -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) } diff --git a/internal/csi-addons/rbd/replication.go b/internal/csi-addons/rbd/replication.go index e3e1d4365..f8daa72ce 100644 --- a/internal/csi-addons/rbd/replication.go +++ b/internal/csi-addons/rbd/replication.go @@ -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") } diff --git a/internal/csi-addons/rbd/replication_test.go b/internal/csi-addons/rbd/replication_test.go index 433c53956..5ed186259 100644 --- a/internal/csi-addons/rbd/replication_test.go +++ b/internal/csi-addons/rbd/replication_test.go @@ -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) }) } } diff --git a/internal/csi-addons/server/server_test.go b/internal/csi-addons/server/server_test.go index 3f31070bd..720d4d5e9 100644 --- a/internal/csi-addons/server/server_test.go +++ b/internal/csi-addons/server/server_test.go @@ -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) }) }