Skip to content

Commit

Permalink
added test for populateTargetsInCache
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasha-dell committed Nov 15, 2024
1 parent d6124a4 commit fc5bf9b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/node/node_connectivity_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"github.com/dell/csi-powerstore/v2/pkg/common"
"github.com/dell/gopowerstore"
"github.com/stretchr/testify/mock"
)

func TestApiRouter2(t *testing.T) {
Expand Down Expand Up @@ -118,3 +120,30 @@ func TestMarshalSyncMapToJSON(t *testing.T) {
})
}
}

func TestPopulateTargetsInCache(t *testing.T) {
setVariables()

t.Run("no error", func(t *testing.T) {
arrays := getTestArrays()
nodeSvc.SetArrays(arrays)
nodeSvc.SetDefaultArray(arrays[firstValidIP])
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetCluster", mock.Anything).
Return(gopowerstore.Cluster{
Name: validClusterName,
NVMeNQN: validNVMEInitiators[0],
}, nil)
// Call the function to populate targets in cache
nodeSvc.populateTargetsInCache(arrays[firstValidIP])
// Validate the cache content
if len(nodeSvc.iscsiTargets[arrays[firstValidIP].GlobalID]) == 0 {
t.Errorf("Expected targets to be populated for GlobalID")
}
})
}

0 comments on commit fc5bf9b

Please sign in to comment.