Skip to content

Commit

Permalink
Adds unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
delldubey committed Jan 25, 2024
1 parent 05b6ca2 commit d2b9a28
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 39 deletions.
11 changes: 11 additions & 0 deletions pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ func TestGetISCSITargetsInfoFromStorage(t *testing.T) {
})
}

func TestGetNVMETCPTargetsInfoFromStorage(t *testing.T) {
t.Run("api error", func(t *testing.T) {
e := errors.New("some error")
clientMock := new(gopowerstoremock.Client)
clientMock.On("GetCluster", context.Background()).Return(gopowerstore.Cluster{}, e)
clientMock.On("GetStorageNVMETCPTargetAddresses", context.Background()).Return([]gopowerstore.IPPoolAddress{}, e)
_, err := common.GetNVMETCPTargetsInfoFromStorage(clientMock, "A1")
assert.EqualError(t, err, e.Error())
})
}

func TestGetFCTargetsInfoFromStorage(t *testing.T) {
t.Run("api error", func(t *testing.T) {
e := errors.New("some error")
Expand Down
86 changes: 62 additions & 24 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,13 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)

clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{
{
Expand All @@ -1902,13 +1908,15 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(res).To(gomega.Equal(&csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"NVMEFCPORTAL0": "nn-0x58ccf090c9200c22:pn-0x58ccf091492b0c22",
"NVMEFCTARGET0": "nqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"FCWWPN0": "58ccf09348a003a3",
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"NVMEFCPORTAL0": "nn-0x58ccf090c9200c22:pn-0x58ccf091492b0c22",
"NVMEFCTARGET0": "nqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"FCWWPN0": "58ccf09348a003a3",
"NVMETCPTARGET0": "nqn",
"NVMETCPPORTAL0": "192.168.1.1:4420",
},
}))
})
Expand Down Expand Up @@ -2073,7 +2081,13 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)

clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{
{
Expand All @@ -2092,10 +2106,12 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(res).To(gomega.Equal(&csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"NVMETCPPORTAL0": "192.168.1.1:4420",
"NVMETCPTARGET0": "",
},
}))
})
Expand Down Expand Up @@ -2183,7 +2199,13 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)

clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{
{
Expand All @@ -2202,10 +2224,12 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(res).To(gomega.Equal(&csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "1",
"NVMETCPPORTAL0": "192.168.1.1:4420",
"NVMETCPTARGET0": "",
},
}))
})
Expand All @@ -2229,7 +2253,13 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)

clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{
{
Expand Down Expand Up @@ -2276,7 +2306,13 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)

clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
IPPort: gopowerstore.IPPortInstance{TargetIqn: "iqn"},
},
}, nil)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{
{
Expand All @@ -2295,10 +2331,12 @@ var _ = ginkgo.Describe("CSIControllerService", func() {
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(res).To(gomega.Equal(&csi.ControllerPublishVolumeResponse{
PublishContext: map[string]string{
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "2",
"PORTAL0": "192.168.1.1:3260",
"TARGET0": "iqn",
"DEVICE_WWN": "68ccf098003ceb5e4577a20be6d11bf9",
"LUN_ADDRESS": "2",
"NVMETCPPORTAL0": "192.168.1.1:4420",
"NVMETCPTARGET0": "",
},
}))
})
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func TestVolumePublisher_Publish(t *testing.T) {
Return([]gopowerstore.HostVolumeMapping{}, nil).Once()
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{}, e)
clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{}, e)
clientMock.On("GetFCPorts", mock.Anything).
Return([]gopowerstore.FcPort{}, nil)
clientMock.On("GetCluster", mock.Anything).
Expand Down
Loading

0 comments on commit d2b9a28

Please sign in to comment.