Skip to content

Commit

Permalink
test(storage/nvme): add client create backend pcie path tests
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <artsiom.koltun@intel.com>
  • Loading branch information
artek-koltun committed Jan 22, 2024
1 parent 03bedcd commit 368fc65
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions storage/backend/nvme_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,98 @@ func TestCreateNvmeTCPPath(t *testing.T) {
}
}

func TestCreateNvmePciePath(t *testing.T) {
testControllerName := "remotenvme0Name"
testPathID := "remotepath0"
testBDF := "0000:64:00.0"
testPath := &pb.NvmePath{
Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TYPE_PCIE,
Traddr: testBDF,
}

tests := map[string]struct {
giveClientErr error
giveConnectorErr error
wantErr error
wantRequest *pb.CreateNvmePathRequest
wantResponse *pb.NvmePath
wantConnClosed bool
}{
"successful call": {
giveConnectorErr: nil,
giveClientErr: nil,
wantErr: nil,
wantRequest: &pb.CreateNvmePathRequest{
Parent: testControllerName,
NvmePathId: testPathID,
NvmePath: proto.Clone(testPath).(*pb.NvmePath),
},
wantResponse: proto.Clone(testPath).(*pb.NvmePath),
wantConnClosed: true,
},
"client err": {
giveConnectorErr: nil,
giveClientErr: errors.New("Some client error"),
wantErr: errors.New("Some client error"),
wantRequest: &pb.CreateNvmePathRequest{
Parent: testControllerName,
NvmePathId: testPathID,
NvmePath: proto.Clone(testPath).(*pb.NvmePath),
},
wantResponse: nil,
wantConnClosed: true,
},
"connector err": {
giveConnectorErr: errors.New("Some conn error"),
giveClientErr: nil,
wantErr: errors.New("Some conn error"),
wantRequest: nil,
wantResponse: nil,
wantConnClosed: false,
},
}

for testName, tt := range tests {
t.Run(testName, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

mockClient := mocks.NewNvmeRemoteControllerServiceClient(t)
if tt.wantRequest != nil {
toReturn := proto.Clone(tt.wantResponse).(*pb.NvmePath)
mockClient.EXPECT().CreateNvmePath(ctx, tt.wantRequest).
Return(toReturn, tt.giveClientErr)
}

connClosed := false
mockConn := mocks.NewConnector(t)
mockConn.EXPECT().NewConn().Return(
&grpc.ClientConn{},
func() { connClosed = true },
tt.giveConnectorErr,
).Maybe()

c, _ := NewWithArgs(
mockConn,
func(grpc.ClientConnInterface) pb.NvmeRemoteControllerServiceClient {
return mockClient
},
)

response, err := c.CreateNvmePciePath(
ctx,
testPathID,
testControllerName,
testBDF,
)

require.Equal(t, tt.wantErr, err)
require.True(t, proto.Equal(response, tt.wantResponse))
require.Equal(t, tt.wantConnClosed, connClosed)
})
}
}

func TestDeleteNvmePath(t *testing.T) {
testPathName := "path0"
testRequest := &pb.DeleteNvmePathRequest{
Expand Down

0 comments on commit 368fc65

Please sign in to comment.