Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increasing UT coverage #346

Draft
wants to merge 76 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
b623e3c
added UT for utils.go
KshitijaKakde Feb 11, 2025
54e05f9
Updated provider.go file
karthikk92 Feb 12, 2025
6c80c94
Updated provider.go file
karthikk92 Feb 12, 2025
944f7fb
Add UT for k8sutils
AkshaySainiDell Feb 12, 2025
e37728d
Add UT for k8sutils
AkshaySainiDell Feb 12, 2025
7c3fb17
added UT for csiutils.go
KshitijaKakde Feb 13, 2025
6976cfa
added UT for utils.go
KshitijaKakde Feb 13, 2025
714e8c9
added UT for utils.go
KshitijaKakde Feb 13, 2025
ea54c33
Update UT coverage for semver.go
WilsonRadadia20 Feb 13, 2025
236b226
Adding UT for k8sutils.go
sakshi-garg1 Feb 13, 2025
3c26fe8
add ut for nodeConnectivitiychecker
panigs7 Feb 13, 2025
6fc3af6
test: Increased code coverage of controllerNodeToArrayConnectivity.go…
samihan-dell Feb 13, 2025
a901000
t pushMerge branches 'UT-coverage' and 'UT-coverage' of https://githu…
samihan-dell Feb 13, 2025
f453f0e
fix: Fixing linting issue
samihan-dell Feb 13, 2025
b0a3e6c
Updated UT for mount.go file
rajendraindukuri Feb 14, 2025
db40533
Improve UT Coverage for nodeconnectivitychecker
panigs7 Feb 14, 2025
608d40c
adding more UT for k8sutils (#348)
sakshi-garg1 Feb 14, 2025
dfe443b
added scenarios to increase UT for csi_extension_server.go
rishabhatdell Feb 14, 2025
09db0f4
Increasing UT coverage for service.go
sakshi-garg1 Feb 14, 2025
fb644e3
Updated code coverage for isiService
rajendraindukuri Feb 14, 2025
9e3770d
test csi-utils
atye Feb 14, 2025
0926fdd
test k8sutils
atye Feb 14, 2025
02e5d01
fix csiutils
atye Feb 14, 2025
69971d9
more coverage to service
atye Feb 14, 2025
11d73a8
Increased UT coverage for provider.go
WilsonRadadia20 Feb 17, 2025
d00006e
add more UT to service/nodeConnectivityChecker.go
panigs7 Feb 17, 2025
51794e9
Increase Ut coverage for service.go
sakshi-garg1 Feb 17, 2025
afff24e
Code coverage of nodeConnectivityChecker 91.3%
panigs7 Feb 17, 2025
b5de661
Fix for the semver.go failure
WilsonRadadia20 Feb 17, 2025
c6198f9
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
WilsonRadadia20 Feb 17, 2025
b05598d
added ut for replication.go
rishabhatdell Feb 17, 2025
1102c87
Improved coverage for errror scenarios isiService
rajendraindukuri Feb 17, 2025
60c7795
Increasing coverage of service.go
sakshi-garg1 Feb 18, 2025
682a1af
Further improved the coverage for isiservice file
rajendraindukuri Feb 18, 2025
a5dfaa3
increased coverage for controller.go
chaganti-rajitha Feb 18, 2025
d3f083e
Updated main test.go UT
karthikk92 Feb 19, 2025
7c4b2a2
Updated main test.go UT
karthikk92 Feb 19, 2025
d909061
test: Increased test coverage for node.go file
samihan-dell Feb 19, 2025
d3a3cbb
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
samihan-dell Feb 19, 2025
ac393db
increased coverage for controller.go
chaganti-rajitha Feb 19, 2025
90c228b
added test case in coverage.go
chaganti-rajitha Feb 19, 2025
3642f51
Updated main test.go UT and UT reached to 42.2%
karthikk92 Feb 19, 2025
5411134
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
karthikk92 Feb 19, 2025
f73f9f9
fixed race condition
rishabhatdell Feb 19, 2025
d6253c0
test: Increased test coverage for node.go file
samihan-dell Feb 19, 2025
08025d1
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
samihan-dell Feb 19, 2025
4b165f8
added some service tests
ChristianAtDell Feb 19, 2025
3448fd3
add replication test WIP, modify client to not return error all time,…
JacobGros Feb 19, 2025
bba13ca
Increasing UT for service.go
sakshi-garg1 Feb 20, 2025
1323f86
add UT for synchronize and suspend in replication_test.go
suryagupta4 Feb 20, 2025
e3f9bad
added test cases in coverage.go
chaganti-rajitha Feb 20, 2025
0996ff2
refactor: Refactored to include functions mocking in node_test.go
samihan-dell Feb 20, 2025
6200786
adding godog tests back to check coverage
JacobGros Feb 20, 2025
a18824a
test: Added UTs for node.go increases code coverage to 28%
samihan-dell Feb 20, 2025
2239802
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
samihan-dell Feb 20, 2025
a875b3b
testcase name change
samihan-dell Feb 20, 2025
756e4a8
This commit focuses only on main.go uni testing.
anathoodell Feb 20, 2025
2b9db8a
cleaned up some node tests
ChristianAtDell Feb 20, 2025
cae9f6d
ephemeral node publish tests
ChristianAtDell Feb 20, 2025
a28ba65
add more replication UT
JacobGros Feb 20, 2025
7e94dad
refactor: refactored UTs for node.go
samihan-dell Feb 21, 2025
93a7045
Update tc with leader election enabled
karthikk92 Feb 21, 2025
9f24796
Update tc with leader election enabled
karthikk92 Feb 21, 2025
db3ac67
added test case in coverage.go
chaganti-rajitha Feb 21, 2025
e355e59
test: Added UTs for node.go
samihan-dell Feb 21, 2025
feede53
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
samihan-dell Feb 21, 2025
bbb7030
add failure cases for replication
JacobGros Feb 21, 2025
8cdbdb6
added tests to node_test.go
ChristianAtDell Feb 21, 2025
5c0fa31
comment out failing tc
JacobGros Feb 21, 2025
9801355
comment out failing tc
JacobGros Feb 21, 2025
446d076
Need to reset the flag command line in order to reuse flag in subsequent
anathoodell Feb 21, 2025
a26ff34
comment out test w/ race error
JacobGros Feb 21, 2025
0c944fd
Merge branch 'UT-coverage' of https://github.com/dell/csi-powerscale …
JacobGros Feb 21, 2025
77811b4
comment out test w/ race error
JacobGros Feb 21, 2025
bf21539
NodeUnpublishVolume tests
ChristianAtDell Feb 21, 2025
76caab4
comment out test w/ race error
JacobGros Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions common/k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"k8s.io/client-go/tools/clientcmd"
)

var buildConfigFromFlags = clientcmd.BuildConfigFromFlags

Check failure on line 34 in common/k8sutils/k8sutils.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
var newForConfig = kubernetes.NewForConfig
var inClusterConfig = rest.InClusterConfig

var fsInfo = func(ctx context.Context, path string) (int64, int64, int64, int64, int64, int64, error) {
return gofsutil.FsInfo(ctx, path)
}

type leaderElection interface {
Run() error
WithNamespace(namespace string)
Expand All @@ -41,22 +49,22 @@
var clientset *kubernetes.Clientset
if kubeconfig != "" {
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
config, err := buildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, err
}
// create the clientset
clientset, err = kubernetes.NewForConfig(config)
clientset, err = newForConfig(config)
if err != nil {
return nil, err
}
} else {
config, err := rest.InClusterConfig()
config, err := inClusterConfig()
if err != nil {
return nil, err
}
// creates the clientset
clientset, err = kubernetes.NewForConfig(config)
clientset, err = newForConfig(config)
if err != nil {
return nil, err
}
Expand All @@ -81,7 +89,7 @@

// GetStats - Returns the stats for the volume mounted on given volume path
func GetStats(ctx context.Context, volumePath string) (int64, int64, int64, int64, int64, int64, error) {
availableBytes, totalBytes, usedBytes, totalInodes, freeInodes, usedInodes, err := gofsutil.FsInfo(ctx, volumePath)
availableBytes, totalBytes, usedBytes, totalInodes, freeInodes, usedInodes, err := fsInfo(ctx, volumePath)
if err != nil {
return 0, 0, 0, 0, 0, 0, status.Error(codes.Internal, fmt.Sprintf(
"failed to get volume stats: %s", err))
Expand Down
220 changes: 220 additions & 0 deletions common/k8sutils/k8sutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package k8sutils

import (
"context"
"errors"
"fmt"
"os"
"testing"
"time"

"github.com/stretchr/testify/mock"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

var exitFunc = os.Exit

type MockLeaderElection struct {
mock.Mock
}

func (m *MockLeaderElection) Run() error {
args := m.Called()
return args.Error(0)
}

func TestCreateKubeClientSet(t *testing.T) {
// Test cases
tests := []struct {
name string
kubeconfig string
configErr error
clientErr error
wantErr bool
}{
{
name: "Valid kubeconfig",
kubeconfig: "valid_kubeconfig",
configErr: nil,
clientErr: nil,
wantErr: false,
},
{
name: "Invalid kubeconfig",
kubeconfig: "invalid_kubeconfig",
configErr: errors.New("config error"),
clientErr: nil,
wantErr: true,
},
{
name: "In-cluster config",
kubeconfig: "",
configErr: nil,
clientErr: nil,
wantErr: false,
},
{
name: "In-cluster config error",
kubeconfig: "",
configErr: errors.New("config error"),
clientErr: nil,
wantErr: true,
},
{
name: "New for config error",
kubeconfig: "",
configErr: nil,
clientErr: errors.New("client error"),
wantErr: true,
},
{
name: "New for config error",
kubeconfig: "invalid_kubeconfig",
configErr: nil,
clientErr: errors.New("client error"),
wantErr: true,
},
}

// Save original functions
origBuildConfigFromFlags := buildConfigFromFlags
origInClusterConfig := inClusterConfig
origNewForConfig := newForConfig

// Restore original functions after tests
defer func() {
buildConfigFromFlags = origBuildConfigFromFlags
inClusterConfig = origInClusterConfig
newForConfig = origNewForConfig
}()

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Mock functions
buildConfigFromFlags = func(_, _ string) (*rest.Config, error) {
return &rest.Config{}, tt.configErr
}
inClusterConfig = func() (*rest.Config, error) {
return &rest.Config{}, tt.configErr
}
newForConfig = func(_ *rest.Config) (*kubernetes.Clientset, error) {
if tt.clientErr != nil {
return nil, tt.clientErr
}
return &kubernetes.Clientset{}, nil
}

clientset, err := CreateKubeClientSet(tt.kubeconfig)
if (err != nil) != tt.wantErr {
t.Errorf("CreateKubeClientSet() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && clientset == nil {
t.Errorf("CreateKubeClientSet() = nil, want non-nil")
}
})
}
}

func TestGetStats(t *testing.T) {
// Set up the necessary dependencies
ctx := context.Background()
volumePath := "/path/to/volume"
availableBytes, totalBytes, usedBytes, totalInodes, freeInodes, usedInodes, _ := GetStats(ctx, volumePath)

expectedAvailableBytes := int64(0)
expectedTotalBytes := int64(0)
expectedUsedBytes := int64(0)
expectedTotalInodes := int64(0)
expectedFreeInodes := int64(0)
expectedUsedInodes := int64(0)
if availableBytes != expectedAvailableBytes {
t.Errorf("Expected availableBytes to be %d, but got %d", expectedAvailableBytes, availableBytes)
}
if totalBytes != expectedTotalBytes {
t.Errorf("Expected totalBytes to be %d, but got %d", expectedTotalBytes, totalBytes)
}
if usedBytes != expectedUsedBytes {
t.Errorf("Expected usedBytes to be %d, but got %d", expectedUsedBytes, usedBytes)
}
if totalInodes != expectedTotalInodes {
t.Errorf("Expected totalInodes to be %d, but got %d", expectedTotalInodes, totalInodes)
}
if freeInodes != expectedFreeInodes {
t.Errorf("Expected freeInodes to be %d, but got %d", expectedFreeInodes, freeInodes)
}
if usedInodes != expectedUsedInodes {
t.Errorf("Expected usedInodes to be %d, but got %d", expectedUsedInodes, usedInodes)
}
}

func TestGetStatsNoError(t *testing.T) {
// Set up the necessary dependencies
defaultFsInfo := fsInfo
fsInfo = func(ctx context.Context, path string) (int64, int64, int64, int64, int64, int64, error) {

Check failure on line 155 in common/k8sutils/k8sutils_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
return 1, 1, 1, 1, 1, 1, nil
}
defer func() {
fsInfo = defaultFsInfo
}()

ctx := context.Background()
volumePath := "/path/to/volume"
availableBytes, totalBytes, usedBytes, totalInodes, freeInodes, usedInodes, _ := GetStats(ctx, volumePath)

expectedAvailableBytes := int64(1)
expectedTotalBytes := int64(1)
expectedUsedBytes := int64(1)
expectedTotalInodes := int64(1)
expectedFreeInodes := int64(1)
expectedUsedInodes := int64(1)
if availableBytes != expectedAvailableBytes {
t.Errorf("Expected availableBytes to be %d, but got %d", expectedAvailableBytes, availableBytes)
}
if totalBytes != expectedTotalBytes {
t.Errorf("Expected totalBytes to be %d, but got %d", expectedTotalBytes, totalBytes)
}
if usedBytes != expectedUsedBytes {
t.Errorf("Expected usedBytes to be %d, but got %d", expectedUsedBytes, usedBytes)
}
if totalInodes != expectedTotalInodes {
t.Errorf("Expected totalInodes to be %d, but got %d", expectedTotalInodes, totalInodes)
}
if freeInodes != expectedFreeInodes {
t.Errorf("Expected freeInodes to be %d, but got %d", expectedFreeInodes, freeInodes)
}
if usedInodes != expectedUsedInodes {
t.Errorf("Expected usedInodes to be %d, but got %d", expectedUsedInodes, usedInodes)
}
}

func TestLeaderElection(t *testing.T) {
clientset := &kubernetes.Clientset{} // Mock or use a fake clientset if needed
runFunc := func(ctx context.Context) {

Check failure on line 194 in common/k8sutils/k8sutils_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
fmt.Println("Running leader function")
}

mockLE := new(MockLeaderElection)
mockLE.On("Run").Return(nil) // Mocking a successful run

// Override exitFunc to prevent test from exiting
exitCalled := false
oldExit := exitFunc
defer func() { recover(); exitFunc = oldExit }()
exitFunc = func(code int) { exitCalled = true; panic("exitFunc called") }

Check failure on line 205 in common/k8sutils/k8sutils_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

unused-parameter: parameter 'code' seems to be unused, consider removing or renaming it as _ (revive)

// Simulate LeaderElection function
func() {
defer func() {
if r := recover(); r != nil {
exitCalled = true
}
}()
LeaderElection(clientset, "test-lock", "test-namespace", time.Second, time.Second*2, time.Second*3, runFunc)
}()

if !exitCalled {
t.Errorf("exitFunc was called unexpectedly")
}
}
4 changes: 3 additions & 1 deletion common/utils/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func ParseLogLevel(lvl string) (logrus.Level, error) {
}

// UpdateLogLevel updates the log level
func UpdateLogLevel(lvl logrus.Level) {
func UpdateLogLevel(lvl logrus.Level, mu *sync.Mutex) {
mu.Lock()
defer mu.Unlock()
singletonLog.Level = lvl
}

Expand Down
2 changes: 1 addition & 1 deletion common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ParseInt64FromContext(ctx context.Context, key string) (int64, error) {
}

// RemoveExistingCSISockFile When the sock file that the gRPC server is going to be listening on already exists, error will be thrown saying the address is already in use, thus remove it first
func RemoveExistingCSISockFile() error {
var RemoveExistingCSISockFile = func() error {
log := GetLogger()
protoAddr := os.Getenv(constants.EnvCSIEndpoint)

Expand Down
Loading