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

Added unit tests #83

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 0 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
github.com/opiproject/opi-api v0.0.0-20221212223617-4ab228a467f7 h1:iQS6+aIBIsWmNfcUmP40rrDrKsP+xgF2Z5nhOP33U/c=
github.com/opiproject/opi-api v0.0.0-20221212223617-4ab228a467f7/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221215155400-a49a4ea1d561 h1:0v2Lmm5zPK6Doz3cn9QCqX8vAfLw72Hvwcx1cqam6bM=
github.com/opiproject/opi-api v0.0.0-20221215155400-a49a4ea1d561/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221216134945-6078c7e2edf6 h1:QIJba6G9J9V0q58saN8Fs1OnF5pgUfbfXxMAQfpr7hY=
github.com/opiproject/opi-api v0.0.0-20221216134945-6078c7e2edf6/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221217125648-ab4bf01d6bfb h1:5v+9PmqslA6Sv0qr6WbSNPDhP1H8KzAjaxAmDalY+TA=
github.com/opiproject/opi-api v0.0.0-20221217125648-ab4bf01d6bfb/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221219195815-904f6730e136 h1:TI+8pDAIi+Ie7RhQ+fIcOQL4OAmxQ22ZtGXa2VlPEhY=
github.com/opiproject/opi-api v0.0.0-20221219195815-904f6730e136/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221220003855-844775ae0e14 h1:ZjzswIdvCpehv/QI86y5fdAf3YLrYEZGz13butIcYS0=
github.com/opiproject/opi-api v0.0.0-20221220003855-844775ae0e14/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -33,23 +23,11 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
99 changes: 48 additions & 51 deletions goopicsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package goopicsi

import (
"fmt"
"log"
"net"
"os"
"strings"
Expand Down Expand Up @@ -58,6 +57,8 @@ func RunServer() {
MockServer := grpc.NewServer()

pb.RegisterFrontendNvmeServiceServer(MockServer, &server.GoopCSI{})
pb.RegisterNVMfRemoteControllerServiceServer(MockServer, &server.GoopCSI{})
pb.RegisterNullDebugServiceServer(MockServer, &server.GoopCSI{})

fmt.Printf("Serving gRPC on %s\n", csiAddress)
errChan := make(chan error)
Expand All @@ -74,54 +75,50 @@ func (suite *GoopcsiTestSuite) TearDownTestSuite() {
suite.T().Log("Cleaning up resources..")
}

// TODO These test cases should be reverted with mock server implementation
// func TestNVMeControllerConnect(t *testing.T) {
// err := NVMeControllerConnect("12", "", "", 44565, "")
// if err != nil {
// log.Println(err)
// }
// assert.Error(t, err)
// }

// func TestNVMeControllerList(t *testing.T) {
// resp, err := NVMeControllerList()
// if err != nil {
// log.Println(err)
// }
// log.Printf("NVMf Remote Connections: %v", resp)
// }

// func TestNVMeControllerGet(t *testing.T) {
// resp, err := NVMeControllerGet("12")
// if err != nil {
// log.Println(err)
// }
// log.Printf("NVMf remote connection corresponding to the ID: %v", resp)
// }

// func TestNVMeControllerDisconnect(t *testing.T) {
// err := NVMeControllerDisconnect("12")
// if err != nil {
// log.Println(err)
// }
// }

// func TestCreateNVMeNamespace(t *testing.T) {
// resp, err := CreateNVMeNamespace("1", "nqn", "nguid", 1)
// if err != nil {
// log.Println(err)
// }
// log.Println(resp)
// }

// func TestExposeRemoteNVMe(t *testing.T) {
// subsystemID, controllerID, err := ExposeRemoteNVMe("nqn.2022-09.io.spdk:test", 10)
// if err != nil {
// log.Println(err)
// }
// log.Printf("Subsystem ID: %s", subsystemID)
// log.Printf("Controller Id: %s", controllerID)
// }
func (suite *GoopcsiTestSuite) TestExposeRemoteNVMe() {
// Negative scenario
subsystemID, controllerID, err := ExposeRemoteNVMe("nqn.2022-09.io.spdk:test", 10)
assert.Error(suite.T(), err)
assert.Empty(suite.T(), subsystemID, "ExposeRemoteNVMe failed")
assert.Empty(suite.T(), controllerID, "ExposeRemoteNVMe failed")
}

func (suite *GoopcsiTestSuite) TestCreateNVMeNamespace() {
// scenario: when volume ID not found
resp, err := CreateNVMeNamespace("1", "nqn", "nguid", 1)
assert.Error(suite.T(), err)
assert.Empty(suite.T(), resp, "CreateNVMeNamespace failed with invalid volume ID")
}

func (suite *GoopcsiTestSuite) TestNVMeControllerDisconnect() {
// scenario: when connection already exists
err := NVMeControllerDisconnect("12")
assert.NoError(suite.T(), err)
}

func (suite *GoopcsiTestSuite) TestNVMeControllerConnect() {
// scenario: when connection already exists
err := NVMeControllerConnect("12", "", "", 44565, "")
assert.NoError(suite.T(), err)
}

func (suite *GoopcsiTestSuite) TestNVMeControllerList() {
resp, err := NVMeControllerList()
assert.NoError(suite.T(), err)
assert.NotNil(suite.T(), resp, "ListControllers success")
}

func (suite *GoopcsiTestSuite) TestNVMeControllerGet() {
// positive scenario
resp, err := NVMeControllerGet("12")
assert.NoError(suite.T(), err)
assert.NotNil(suite.T(), resp, "GetController success")

// negative scenario
resp, err = NVMeControllerGet("invalid")
assert.Error(suite.T(), err, "GetController failed")
assert.Empty(suite.T(), resp, "GetController failed")
}

func (suite *GoopcsiTestSuite) TestDeleteNVMeNamespace() {
// positive scenario
Expand All @@ -133,9 +130,9 @@ func (suite *GoopcsiTestSuite) TestDeleteNVMeNamespace() {
assert.Error(suite.T(), err, "DeleteNVMeNamespace failed")
}

func TestGenerateHostNQN(t *testing.T) {
func (suite *GoopcsiTestSuite) TestGenerateHostNQN() {
hostNQN := GenerateHostNQN()
log.Println(hostNQN)
assert.NotNil(suite.T(), hostNQN, "GenerateHostNQN success")
}

func TestGoopcsiTestSuite(t *testing.T) {
Expand Down
99 changes: 93 additions & 6 deletions test/mock-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package server

import (
"bytes"
context2 "context"
"encoding/json"
"fmt"
"io"
Expand All @@ -34,12 +35,96 @@ import (
// GoopCSI mock gRPC server to implement mock service calls
type GoopCSI struct{}

// CreateNVMeSubsystem creates mock NVMe subsystem
func (s *GoopCSI) CreateNVMeSubsystem(ctx context.Context, request *pb.CreateNVMeSubsystemRequest) (*pb.NVMeSubsystem, error) {
// CreateNullDebug creates a mock NullDebug
func (s *GoopCSI) CreateNullDebug(ctx context2.Context, request *pb.CreateNullDebugRequest) (*pb.NullDebug, error) {
// TODO implement me
panic("implement me")
}

// DeleteNullDebug Deletes a mock NullDebug
func (s *GoopCSI) DeleteNullDebug(ctx context2.Context, request *pb.DeleteNullDebugRequest) (*emptypb.Empty, error) {
// TODO implement me
panic("implement me")
}

// UpdateNullDebug Updated mock NullDebug
func (s *GoopCSI) UpdateNullDebug(ctx context2.Context, request *pb.UpdateNullDebugRequest) (*pb.NullDebug, error) {
// TODO implement me
panic("implement me")
}

// ListNullDebugs Lists mock nullDebugs
func (s *GoopCSI) ListNullDebugs(ctx context2.Context, request *pb.ListNullDebugsRequest) (*pb.ListNullDebugsResponse, error) {
out := &pb.ListNullDebugsResponse{}
err := FindStub("NullDebugServiceServer", "ListNullDebugs", request, out)
return out, err
}

// GetNullDebug Gets mock NullDebug
func (s *GoopCSI) GetNullDebug(ctx context2.Context, request *pb.GetNullDebugRequest) (*pb.NullDebug, error) {
// TODO implement me
panic("implement me")
}

// NullDebugStats gets mock NullDebugStats
func (s *GoopCSI) NullDebugStats(ctx context2.Context, request *pb.NullDebugStatsRequest) (*pb.NullDebugStatsResponse, error) {
// TODO implement me
panic("implement me")
}

// CreateNVMfRemoteController creates a mock NVMf Remote controller
func (s *GoopCSI) CreateNVMfRemoteController(ctx context2.Context, request *pb.CreateNVMfRemoteControllerRequest) (*pb.NVMfRemoteController, error) {
out := &pb.NVMfRemoteController{}
err := FindStub("NVMfRemoteControllerServiceServer", "CreateNVMfRemoteController", request, out)
return out, err
}

// DeleteNVMfRemoteController deletes a mock NVMfRemote Controller
func (s *GoopCSI) DeleteNVMfRemoteController(ctx context2.Context, request *pb.DeleteNVMfRemoteControllerRequest) (*emptypb.Empty, error) {
out := &emptypb.Empty{}
err := FindStub("NVMfRemoteControllerServiceServer", "DeleteNVMfRemoteController", request, out)
return out, err
}

// UpdateNVMfRemoteController updates mock NVMf Remote Controller
func (s *GoopCSI) UpdateNVMfRemoteController(ctx context2.Context, request *pb.UpdateNVMfRemoteControllerRequest) (*pb.NVMfRemoteController, error) {
// TODO implement me
panic("implement me")
}

// ListNVMfRemoteControllers Lists mock NVMfRemote Controllers
func (s *GoopCSI) ListNVMfRemoteControllers(ctx context2.Context, request *pb.ListNVMfRemoteControllersRequest) (*pb.ListNVMfRemoteControllersResponse, error) {
out := &pb.ListNVMfRemoteControllersResponse{}
err := FindStub("NVMfRemoteControllerServiceServer", "ListNVMfRemoteControllers", request, out)
return out, err
}

// GetNVMfRemoteController Gets an NVMf Remote controller
func (s *GoopCSI) GetNVMfRemoteController(ctx context2.Context, request *pb.GetNVMfRemoteControllerRequest) (*pb.NVMfRemoteController, error) {
out := &pb.NVMfRemoteController{}
err := FindStub("NVMfRemoteControllerServiceServer", "GetNVMfRemoteController", request, out)
return out, err
}

// NVMfRemoteControllerReset Resets mock Remote Controller
func (s *GoopCSI) NVMfRemoteControllerReset(ctx context2.Context, request *pb.NVMfRemoteControllerResetRequest) (*emptypb.Empty, error) {
// TODO implement me
panic("implement me")
}

// NVMfRemoteControllerStats gets mock stats
func (s *GoopCSI) NVMfRemoteControllerStats(ctx context2.Context, request *pb.NVMfRemoteControllerStatsRequest) (*pb.NVMfRemoteControllerStatsResponse, error) {
// TODO implement me
panic("implement me")
}

// CreateNVMeSubsystem creates mock NVMe subsystem
func (s *GoopCSI) CreateNVMeSubsystem(ctx context.Context, request *pb.CreateNVMeSubsystemRequest) (*pb.NVMeSubsystem, error) {
out := &pb.NVMeSubsystem{}
err := FindStub("FrontendNvmeServiceServer", "CreateNVMeSubsystem", request, out)
return out, err
}

// DeleteNVMeSubsystem deletes mock NVMe subsystem
func (s *GoopCSI) DeleteNVMeSubsystem(ctx context.Context, request *pb.DeleteNVMeSubsystemRequest) (*emptypb.Empty, error) {
// TODO implement me
Expand All @@ -60,8 +145,9 @@ func (s *GoopCSI) ListNVMeSubsystems(ctx context.Context, request *pb.ListNVMeSu

// GetNVMeSubsystem gets a mock NVMe subsystem
func (s *GoopCSI) GetNVMeSubsystem(ctx context.Context, request *pb.GetNVMeSubsystemRequest) (*pb.NVMeSubsystem, error) {
// TODO implement me
panic("implement me")
out := &pb.NVMeSubsystem{}
err := FindStub("FrontendNvmeServiceServer", "GetNVMeSubsystem", request, out)
return out, err
}

// NVMeSubsystemStats gets mock subsystem stats
Expand Down Expand Up @@ -96,8 +182,9 @@ func (s *GoopCSI) ListNVMeControllers(ctx context.Context, request *pb.ListNVMeC

// GetNVMeController gets a mock NVMe controller
func (s *GoopCSI) GetNVMeController(ctx context.Context, request *pb.GetNVMeControllerRequest) (*pb.NVMeController, error) {
// TODO implement me
panic("implement me")
out := &pb.NVMeController{}
err := FindStub("FrontendNvmeServiceServer", "GetNVMeController", request, out)
return out, err
}

// NVMeControllerStats gets mock stats
Expand Down
28 changes: 28 additions & 0 deletions test/mock-server/stubs/CreateNVMeSubSystem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"service": "FrontendNvmeServiceServer",
"method": "CreateNVMeSubsystem",
"input": {
"contains": {
"CreateNVMeSubsystemRequest": {
"NvMeSubsystem":{
"Spec": {
"Id": {"value": "1"},
"Nqn": "nqn1"
}
}
}
}
},
"output": {
"data": {
"NVMeSubsystem": {
"spec": {
"NVMeSubsystemSpec": {
"Id": {"value": "1"},
"Nqn": "nqn1"
}
}
}
}
}
}
22 changes: 22 additions & 0 deletions test/mock-server/stubs/CreateNVMfRemoteControllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"service": "NVMfRemoteControllerServiceServer",
"method": "CreateNVMfRemoteController",
"input": {
"contains": {
"CreateNVMfRemoteControllerRequest":{
"NVMfRemoteController":
{
"id": {"value": "12"}
}
}
}
},
"output": {
"data": {
"NVMfRemoteController":
{
"id": {"value": "12"}
}
}
}
}
12 changes: 12 additions & 0 deletions test/mock-server/stubs/DisconnectConnection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"service": "NVMfRemoteControllerServiceServer",
"method": "DeleteNVMfRemoteController",
"input": {
"contains": {
"name": "12"
}
},
"output": {
"data": {}
}
}
23 changes: 23 additions & 0 deletions test/mock-server/stubs/GetNVMeController.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"service": "FrontendNvmeServiceServer",
"method": "GetNVMeController",
"input": {
"contains": {
"GetNVMeControllerRequest": {
"Name": "name1"
}
}
},
"output": {
"data": {
"NVMeController": {
"spec": {
"NVMeSubsystemSpec": {
"Id": {"value": "1"},
"NvmeControllerId": "s1"
}
}
}
}
}
}
Loading