Skip to content

Commit

Permalink
test: check global test objects not changed
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun authored and glimchb committed Aug 30, 2023
1 parent 5969e86 commit f7c8e52
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 54 deletions.
5 changes: 5 additions & 0 deletions pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ var (
PciOperState: 1,
},
}
checkGlobalTestProtoObjectsNotChanged = server.CheckTestProtoObjectsNotChanged(
&testSubsystem,
&testController,
&testNamespace,
)
)
47 changes: 29 additions & 18 deletions pkg/frontend/nvme_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

func TestFrontEnd_CreateNvmeController(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
spec := &pb.NvmeControllerSpec{
SubsystemNameRef: testSubsystemName,
PcieId: &pb.PciEndpoint{
Expand Down Expand Up @@ -192,13 +193,15 @@ func TestFrontEnd_CreateNvmeController(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
if tt.exist {
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Controllers[testControllerName].Name = testControllerName
// testEnv.opiSpdkServer.Controllers[testControllerID].Spec.Id = &pc.ObjectKey{Value: testControllerID}
}
if tt.out != nil {
tt.out = server.ProtoClone(tt.out)
tt.out.Name = testControllerName
}

Expand All @@ -224,6 +227,7 @@ func TestFrontEnd_CreateNvmeController(t *testing.T) {
}

func TestFrontEnd_DeleteNvmeController(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *emptypb.Empty
Expand Down Expand Up @@ -312,9 +316,10 @@ func TestFrontEnd_DeleteNvmeController(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Controllers[testControllerName].Name = testControllerName
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)

request := &pb.DeleteNvmeControllerRequest{Name: tt.in, AllowMissing: tt.missing}
response, err := testEnv.client.DeleteNvmeController(testEnv.ctx, request)
Expand Down Expand Up @@ -347,6 +352,9 @@ func TestFrontEnd_UpdateNvmeController(t *testing.T) {
Sqes: 7,
Cqes: 8,
}
t.Cleanup(server.CheckTestProtoObjectsNotChanged(spec)(t, t.Name()))
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))

tests := map[string]struct {
mask *fieldmaskpb.FieldMask
in *pb.NvmeController
Expand Down Expand Up @@ -471,9 +479,9 @@ func TestFrontEnd_UpdateNvmeController(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)

request := &pb.UpdateNvmeControllerRequest{NvmeController: tt.in, UpdateMask: tt.mask}
response, err := testEnv.client.UpdateNvmeController(testEnv.ctx, request)
Expand All @@ -497,6 +505,7 @@ func TestFrontEnd_UpdateNvmeController(t *testing.T) {
}

func TestFrontEnd_ListNvmeControllers(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out []*pb.NvmeController
Expand Down Expand Up @@ -651,9 +660,9 @@ func TestFrontEnd_ListNvmeControllers(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
testEnv.opiSpdkServer.Pagination["existing-pagination-token"] = 1

request := &pb.ListNvmeControllersRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
Expand Down Expand Up @@ -683,6 +692,7 @@ func TestFrontEnd_ListNvmeControllers(t *testing.T) {
}

func TestFrontEnd_GetNvmeController(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *pb.NvmeController
Expand Down Expand Up @@ -760,9 +770,9 @@ func TestFrontEnd_GetNvmeController(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)

request := &pb.GetNvmeControllerRequest{Name: tt.in}
response, err := testEnv.client.GetNvmeController(testEnv.ctx, request)
Expand All @@ -786,6 +796,7 @@ func TestFrontEnd_GetNvmeController(t *testing.T) {
}

func TestFrontEnd_StatsNvmeController(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *pb.VolumeStats
Expand Down Expand Up @@ -864,9 +875,9 @@ func TestFrontEnd_StatsNvmeController(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)

request := &pb.StatsNvmeControllerRequest{Name: tt.in}
response, err := testEnv.client.StatsNvmeController(testEnv.ctx, request)
Expand Down
45 changes: 27 additions & 18 deletions pkg/frontend/nvme_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func TestFrontEnd_CreateNvmeNamespace(t *testing.T) {
Nguid: "1b4e28ba-2fa1-11d2-883f-b9a761bde3fb",
Eui64: 1967554867335598546,
}
t.Cleanup(server.CheckTestProtoObjectsNotChanged(spec)(t, t.Name()))
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))

tests := map[string]struct {
id string
in *pb.NvmeNamespace
Expand Down Expand Up @@ -213,14 +216,15 @@ func TestFrontEnd_CreateNvmeNamespace(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Subsystems[testSubsystemName].Name = testSubsystemName
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
if tt.exist {
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
testEnv.opiSpdkServer.Namespaces[testNamespaceName].Name = testNamespaceName
}
if tt.out != nil {
tt.out = server.ProtoClone(tt.out)
tt.out.Name = testNamespaceName
}

Expand All @@ -246,6 +250,7 @@ func TestFrontEnd_CreateNvmeNamespace(t *testing.T) {
}

func TestFrontEnd_DeleteNvmeNamespace(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *emptypb.Empty
Expand Down Expand Up @@ -342,9 +347,9 @@ func TestFrontEnd_DeleteNvmeNamespace(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
request := &pb.DeleteNvmeNamespaceRequest{Name: tt.in, AllowMissing: tt.missing}
response, err := testEnv.client.DeleteNvmeNamespace(testEnv.ctx, request)

Expand All @@ -367,6 +372,7 @@ func TestFrontEnd_DeleteNvmeNamespace(t *testing.T) {
}

func TestFrontEnd_UpdateNvmeNamespace(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
mask *fieldmaskpb.FieldMask
in *pb.NvmeNamespace
Expand Down Expand Up @@ -427,9 +433,9 @@ func TestFrontEnd_UpdateNvmeNamespace(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
request := &pb.UpdateNvmeNamespaceRequest{NvmeNamespace: tt.in, UpdateMask: tt.mask}
response, err := testEnv.client.UpdateNvmeNamespace(testEnv.ctx, request)

Expand All @@ -452,6 +458,7 @@ func TestFrontEnd_UpdateNvmeNamespace(t *testing.T) {
}

func TestFrontEnd_ListNvmeNamespaces(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out []*pb.NvmeNamespace
Expand Down Expand Up @@ -630,9 +637,9 @@ func TestFrontEnd_ListNvmeNamespaces(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
testEnv.opiSpdkServer.Pagination["existing-pagination-token"] = 1

request := &pb.ListNvmeNamespacesRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
Expand Down Expand Up @@ -662,6 +669,7 @@ func TestFrontEnd_ListNvmeNamespaces(t *testing.T) {
}

func TestFrontEnd_GetNvmeNamespace(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *pb.NvmeNamespace
Expand Down Expand Up @@ -749,11 +757,11 @@ func TestFrontEnd_GetNvmeNamespace(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Subsystems[testSubsystemName].Name = testSubsystemName
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Controllers[testControllerName].Name = testControllerName
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)
testEnv.opiSpdkServer.Namespaces[testNamespaceName].Name = testNamespaceID

request := &pb.GetNvmeNamespaceRequest{Name: tt.in}
Expand All @@ -778,6 +786,7 @@ func TestFrontEnd_GetNvmeNamespace(t *testing.T) {
}

func TestFrontEnd_StatsNvmeNamespace(t *testing.T) {
t.Cleanup(checkGlobalTestProtoObjectsNotChanged(t, t.Name()))
tests := map[string]struct {
in string
out *pb.VolumeStats
Expand Down Expand Up @@ -856,9 +865,9 @@ func TestFrontEnd_StatsNvmeNamespace(t *testing.T) {
testEnv := createTestEnvironment(tt.spdk)
defer testEnv.Close()

testEnv.opiSpdkServer.Subsystems[testSubsystemName] = &testSubsystem
testEnv.opiSpdkServer.Controllers[testControllerName] = &testController
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = &testNamespace
testEnv.opiSpdkServer.Subsystems[testSubsystemName] = server.ProtoClone(&testSubsystem)
testEnv.opiSpdkServer.Controllers[testControllerName] = server.ProtoClone(&testController)
testEnv.opiSpdkServer.Namespaces[testNamespaceName] = server.ProtoClone(&testNamespace)

request := &pb.StatsNvmeNamespaceRequest{Name: tt.in}
response, err := testEnv.client.StatsNvmeNamespace(testEnv.ctx, request)
Expand Down
Loading

0 comments on commit f7c8e52

Please sign in to comment.