Skip to content

Commit

Permalink
use test response check uniformly for Nvme path backend
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 Jul 14, 2023
1 parent 603aad2 commit 67c3cb5
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions pkg/backend/nvme_path_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 @@ -135,15 +135,9 @@ func TestBackEnd_CreateNvmePath(t *testing.T) {

request := &pb.CreateNvmePathRequest{NvmePath: tt.in, NvmePathId: tt.id}
response, err := testEnv.client.CreateNvmePath(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 @@ -450,15 +444,9 @@ func TestBackEnd_UpdateNvmePath(t *testing.T) {

request := &pb.UpdateNvmePathRequest{NvmePath: tt.in, UpdateMask: tt.mask, AllowMissing: tt.missing}
response, err := testEnv.client.UpdateNvmePath(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 @@ -657,14 +645,14 @@ func TestBackEnd_ListNvmePaths(t *testing.T) {

request := &pb.ListNvmePathsRequest{Parent: tt.in, PageSize: tt.size, PageToken: tt.token}
response, err := testEnv.client.ListNvmePaths(testEnv.ctx, request)
if response != nil {
if !reflect.DeepEqual(response.NvmePaths, tt.out) {
t.Error("response: expected", tt.out, "received", response.NvmePaths)
}
// 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.GetNvmePaths(), tt.out) {
t.Error("response: expected", tt.out, "received", response.GetNvmePaths())
}

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

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

request := &pb.GetNvmePathRequest{Name: tt.in}
response, err := testEnv.client.GetNvmePath(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 @@ -888,10 +871,9 @@ func TestBackEnd_NvmePathStats(t *testing.T) {

request := &pb.NvmePathStatsRequest{Id: &pc.ObjectKey{Value: tt.in}}
response, err := testEnv.client.NvmePathStats(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

0 comments on commit 67c3cb5

Please sign in to comment.