From 88c05033e3bb7a82976e83c93e05df3744256e8d Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Fri, 17 Apr 2020 13:31:51 +0300 Subject: [PATCH] fix copy struct --- core/block/meta/pubsub.go | 4 ++-- util/pbtypes/copy.go | 5 ----- util/pbtypes/copy_test.go | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 util/pbtypes/copy_test.go diff --git a/core/block/meta/pubsub.go b/core/block/meta/pubsub.go index e54db16a2..cd1cbcdc7 100644 --- a/core/block/meta/pubsub.go +++ b/core/block/meta/pubsub.go @@ -367,9 +367,9 @@ func (c *collector) close() { } func copyMeta(m Meta) Meta { - var d *types.Struct + d := m.Details if d != nil { - d = pbtypes.CopyStruct(m.SmartBlockMeta.Details) + d = pbtypes.CopyStruct(m.Details) } return Meta{ BlockId: diff --git a/util/pbtypes/copy.go b/util/pbtypes/copy.go index 91a29b476..536b0fbab 100644 --- a/util/pbtypes/copy.go +++ b/util/pbtypes/copy.go @@ -13,11 +13,6 @@ var bytesPool = &sync.Pool{ }, } -type Type interface { - Size() int - MarshalToSizedBuffer(data []byte) (int, error) -} - func CopyBlock(in *model.Block) (out *model.Block) { buf := bytesPool.Get().([]byte) size := in.Size() diff --git a/util/pbtypes/copy_test.go b/util/pbtypes/copy_test.go new file mode 100644 index 000000000..8dbd2987a --- /dev/null +++ b/util/pbtypes/copy_test.go @@ -0,0 +1,19 @@ +package pbtypes + +import ( + "testing" + + "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/assert" +) + +func TestCopyStruct(t *testing.T) { + s := &types.Struct{ + Fields: map[string]*types.Value{ + "string": String("string"), + "bool": Bool(true), + }, + } + c := CopyStruct(s) + assert.True(t, s.Equal(c)) +}