From 404ea4168ea19fb62822667a12ce57766cb7dbed Mon Sep 17 00:00:00 2001 From: mactep Date: Fri, 29 Sep 2023 08:45:48 -0300 Subject: [PATCH 1/2] Make `StringifySnapshot` use cupaloy format --- pkg/grpc/snapshot.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/grpc/snapshot.go b/pkg/grpc/snapshot.go index 90faebe..2da5ada 100644 --- a/pkg/grpc/snapshot.go +++ b/pkg/grpc/snapshot.go @@ -1,6 +1,10 @@ package grpc -import "strings" +import ( + "fmt" + "reflect" + "strings" +) type ProtoMessage interface { String() string @@ -9,8 +13,9 @@ type ProtoMessage interface { // StringifySnapshot converts a protobuf response to a string and removes all double spaces. // This is needed because of a pseudo-random effect https://github.com/golang/protobuf/issues/1121 func StringifySnapshot(resp ProtoMessage) string { + respType := reflect.TypeOf(resp).String() respStr := resp.String() respStr = strings.ReplaceAll(respStr, " ", " ") - return respStr + return fmt.Sprintf("(%s)(%s)", respType, respStr) } From f1f2e4c7df3fd47c7192d9ff120231dff1e2c962 Mon Sep 17 00:00:00 2001 From: mactep Date: Mon, 2 Oct 2023 09:48:41 -0300 Subject: [PATCH 2/2] Add `nil` case --- pkg/grpc/snapshot.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/grpc/snapshot.go b/pkg/grpc/snapshot.go index 2da5ada..3a806fc 100644 --- a/pkg/grpc/snapshot.go +++ b/pkg/grpc/snapshot.go @@ -13,6 +13,10 @@ type ProtoMessage interface { // StringifySnapshot converts a protobuf response to a string and removes all double spaces. // This is needed because of a pseudo-random effect https://github.com/golang/protobuf/issues/1121 func StringifySnapshot(resp ProtoMessage) string { + if resp == nil { + return "(interface {}) " + } + respType := reflect.TypeOf(resp).String() respStr := resp.String() respStr = strings.ReplaceAll(respStr, " ", " ")