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

Uniformly check nil responses in backend tests #534

Merged
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
60 changes: 21 additions & 39 deletions pkg/backend/aio_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (C) 2023 Intel Corporation

// Package backend implememnts the BackEnd APIs (network facing) of the storage Server
package backend

import (
"bytes"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -130,15 +130,9 @@ func TestBackEnd_CreateAioController(t *testing.T) {

request := &pb.CreateAioControllerRequest{AioController: tt.in, AioControllerId: tt.id}
response, err := testEnv.client.CreateAioController(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)

// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -324,15 +318,9 @@ func TestBackEnd_UpdateAioController(t *testing.T) {

request := &pb.UpdateAioControllerRequest{AioController: tt.in, UpdateMask: tt.mask, AllowMissing: tt.missing}
response, err := testEnv.client.UpdateAioController(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)

// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -519,14 +507,14 @@ func TestBackEnd_ListAioControllers(t *testing.T) {

request := &pb.ListAioControllersRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
response, err := testEnv.client.ListAioControllers(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.AioControllers, tt.out) {
t.Error("response: expected", tt.out, "received", response.AioControllers)
}
// Empty NextPageToken indicates end of results list
if tt.size != 1 && response.NextPageToken != "" {
t.Error("Expected end of results, receieved non-empty next page token", response.NextPageToken)
}

if !server.EqualProtoSlices(response.GetAioControllers(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetAioControllers())
}

// Empty NextPageToken indicates end of results list
if tt.size != 1 && response.GetNextPageToken() != "" {
t.Error("Expected end of results, received non-empty next page token", response.GetNextPageToken())
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -628,14 +616,9 @@ func TestBackEnd_GetAioController(t *testing.T) {

request := &pb.GetAioControllerRequest{Name: tt.in}
response, err := testEnv.client.GetAioController(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)
// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -744,10 +727,9 @@ func TestBackEnd_AioControllerStats(t *testing.T) {

request := &pb.AioControllerStatsRequest{Handle: &pc.ObjectKey{Value: tt.in}}
response, err := testEnv.client.AioControllerStats(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.Stats, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(tt.out, response.GetStats()) {
t.Error("response: expected", tt.out, "received", response.GetStats())
}

if er, ok := status.FromError(err); ok {
Expand Down
59 changes: 20 additions & 39 deletions pkg/backend/null_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (C) 2023 Intel Corporation

// Package backend implememnts the BackEnd APIs (network facing) of the storage Server
package backend

import (
"bytes"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -129,15 +129,9 @@ func TestBackEnd_CreateNullDebug(t *testing.T) {

request := &pb.CreateNullDebugRequest{NullDebug: tt.in, NullDebugId: tt.id}
response, err := testEnv.client.CreateNullDebug(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)

// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -320,15 +314,9 @@ func TestBackEnd_UpdateNullDebug(t *testing.T) {

request := &pb.UpdateNullDebugRequest{NullDebug: tt.in, UpdateMask: tt.mask, AllowMissing: tt.missing}
response, err := testEnv.client.UpdateNullDebug(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)

// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -521,14 +509,13 @@ func TestBackEnd_ListNullDebugs(t *testing.T) {

request := &pb.ListNullDebugsRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
response, err := testEnv.client.ListNullDebugs(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.NullDebugs, tt.out) {
t.Error("response: expected", tt.out, "received", response.NullDebugs)
}
// Empty NextPageToken indicates end of results list
if tt.size != 1 && response.NextPageToken != "" {
t.Error("Expected end of results, receieved non-empty next page token", response.NextPageToken)
}

if !server.EqualProtoSlices(response.GetNullDebugs(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetNullDebugs())
}

if tt.size != 1 && response.GetNextPageToken() != "" {
t.Error("Expected end of results, received non-empty next page token", response.GetNextPageToken())
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -635,14 +622,9 @@ func TestBackEnd_GetNullDebug(t *testing.T) {

request := &pb.GetNullDebugRequest{Name: tt.in}
response, err := testEnv.client.GetNullDebug(testEnv.ctx, request)
if response != nil {
// Marshall the request and response, so we can just compare the contained data
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)
// Compare the marshalled messages
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -751,10 +733,9 @@ func TestBackEnd_NullDebugStats(t *testing.T) {

request := &pb.NullDebugStatsRequest{Handle: &pc.ObjectKey{Value: tt.in}}
response, err := testEnv.client.NullDebugStats(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.Stats, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response.GetStats(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetStats())
}

if er, ok := status.FromError(err); ok {
Expand Down
54 changes: 20 additions & 34 deletions pkg/backend/nvme_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package backend

import (
"bytes"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -83,13 +82,9 @@ func TestBackEnd_CreateNvmeRemoteController(t *testing.T) {

request := &pb.CreateNvmeRemoteControllerRequest{NvmeRemoteController: tt.in, NvmeRemoteControllerId: tt.id}
response, err := testEnv.client.CreateNvmeRemoteController(testEnv.ctx, request)
if response != nil {
// if !reflect.DeepEqual(response, tt.out) {
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -133,13 +128,9 @@ func TestBackEnd_NvmeRemoteControllerReset(t *testing.T) {

request := &pb.NvmeRemoteControllerResetRequest{Id: &pc.ObjectKey{Value: tt.in}}
response, err := testEnv.client.NvmeRemoteControllerReset(testEnv.ctx, request)
if response != nil {
// if !reflect.DeepEqual(response, tt.out) {
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -273,14 +264,14 @@ func TestBackEnd_ListNvmeRemoteControllers(t *testing.T) {

request := &pb.ListNvmeRemoteControllersRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
response, err := testEnv.client.ListNvmeRemoteControllers(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.NvmeRemoteControllers, tt.out) {
t.Error("response: expected", tt.out, "received", response.NvmeRemoteControllers)
}
// Empty NextPageToken indicates end of results list
if tt.size != 1 && response.NextPageToken != "" {
t.Error("Expected end of results, receieved non-empty next page token", response.NextPageToken)
}

if !server.EqualProtoSlices(response.GetNvmeRemoteControllers(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetNvmeRemoteControllers())
}

// Empty NextPageToken indicates end of results list
if tt.size != 1 && response.GetNextPageToken() != "" {
t.Error("Expected end of results, received non-empty next page token", response.GetNextPageToken())
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -337,13 +328,9 @@ func TestBackEnd_GetNvmeRemoteController(t *testing.T) {

request := &pb.GetNvmeRemoteControllerRequest{Name: tt.in}
response, err := testEnv.client.GetNvmeRemoteController(testEnv.ctx, request)
if response != nil {
// if !reflect.DeepEqual(response, tt.out) {
mtt, _ := proto.Marshal(tt.out)
mResponse, _ := proto.Marshal(response)
if !bytes.Equal(mtt, mResponse) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if er, ok := status.FromError(err); ok {
Expand Down Expand Up @@ -408,10 +395,9 @@ func TestBackEnd_NvmeRemoteControllerStats(t *testing.T) {

request := &pb.NvmeRemoteControllerStatsRequest{Id: &pc.ObjectKey{Value: tt.in}}
response, err := testEnv.client.NvmeRemoteControllerStats(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.Stats, tt.out) {
t.Error("response: expected", tt.out, "received", response)
}

if !proto.Equal(response.GetStats(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetStats())
}

if er, ok := status.FromError(err); ok {
Expand Down
Loading
Loading