From 1305bc750e7f3590e8fb2dd0b04d4ca4fc528cc1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 30 Sep 2020 20:21:32 +0300 Subject: [PATCH] [#164] sdk/object: Add HasParent method Signed-off-by: Leonard Lyubich --- pkg/object/raw.go | 5 +++++ pkg/object/raw_test.go | 12 ++++++++++++ pkg/object/rw.go | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/pkg/object/raw.go b/pkg/object/raw.go index f29e001..2615530 100644 --- a/pkg/object/raw.go +++ b/pkg/object/raw.go @@ -148,3 +148,8 @@ func (o *RawObject) CutPayload() *RawObject { func (o *RawObject) ResetRelations() { o.resetRelations() } + +// InitRelations initializes relation field. +func (o *RawObject) InitRelations() { + o.initRelations() +} diff --git a/pkg/object/raw_test.go b/pkg/object/raw_test.go index 3931adb..2e39322 100644 --- a/pkg/object/raw_test.go +++ b/pkg/object/raw_test.go @@ -275,3 +275,15 @@ func TestRawObject_ResetRelations(t *testing.T) { require.Nil(t, obj.GetPreviousID()) } + +func TestRwObject_HasParent(t *testing.T) { + obj := NewRaw() + + obj.InitRelations() + + require.True(t, obj.HasParent()) + + obj.ResetRelations() + + require.False(t, obj.HasParent()) +} diff --git a/pkg/object/rw.go b/pkg/object/rw.go index 0e8e621..0aab2c7 100644 --- a/pkg/object/rw.go +++ b/pkg/object/rw.go @@ -296,6 +296,12 @@ func (o *rwObject) setParent(v *Object) { }) } +func (o *rwObject) initRelations() { + o.setHeaderField(func(h *object.Header) { + h.SetSplit(new(object.SplitHeader)) + }) +} + func (o *rwObject) resetRelations() { o.setHeaderField(func(h *object.Header) { h.SetSplit(nil) @@ -340,3 +346,9 @@ func (o *rwObject) cutPayload() *rwObject { return (*rwObject)(ov2) } + +func (o *rwObject) HasParent() bool { + return (*object.Object)(o). + GetHeader(). + GetSplit() != nil +}