From af82c2865ec1ce28f62fa928eeab98fd041e40cd Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 13 Jul 2023 11:50:13 +0300 Subject: [PATCH] [#335] treesvc: Fix inmemory unit tests and nil meta items Bolt forest saves empty slice of items. Now inmemory forest does it the same way. Signed-off-by: Dmitrii Stepanov --- .../pilorama/forest_test.go | 19 +++++++++++++------ pkg/local_object_storage/pilorama/inmemory.go | 8 ++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/local_object_storage/pilorama/forest_test.go b/pkg/local_object_storage/pilorama/forest_test.go index 9e8e9886..5c143d3e 100644 --- a/pkg/local_object_storage/pilorama/forest_test.go +++ b/pkg/local_object_storage/pilorama/forest_test.go @@ -147,16 +147,23 @@ func testForestTreeGetChildren(t *testing.T, s Forest) { treeAdd(t, 2, 0) treeAdd(t, 7, 0) - testGetChildren := func(t *testing.T, nodeID Node, expected []Node) { + testGetChildren := func(t *testing.T, nodeID Node, expected []NodeInfo) { actual, err := s.TreeGetChildren(context.Background(), cid, treeID, nodeID) require.NoError(t, err) require.ElementsMatch(t, expected, actual) } - testGetChildren(t, 0, []uint64{10, 2, 7}) - testGetChildren(t, 10, []uint64{3, 6}) + testGetChildren(t, 0, []NodeInfo{ + {ID: 10, Meta: Meta{Time: 1, Items: []KeyValue{}}}, + {ID: 2, Meta: Meta{Time: 5, Items: []KeyValue{}}}, + {ID: 7, Meta: Meta{Time: 6, Items: []KeyValue{}}}, + }) + testGetChildren(t, 10, []NodeInfo{ + {ID: 3, ParentID: 10, Meta: Meta{Time: 2, Items: []KeyValue{}}}, + {ID: 6, ParentID: 10, Meta: Meta{Time: 3, Items: []KeyValue{}}}, + }) testGetChildren(t, 3, nil) - testGetChildren(t, 6, []uint64{11}) + testGetChildren(t, 6, []NodeInfo{{ID: 11, ParentID: 6, Meta: Meta{Time: 4, Items: []KeyValue{}}}}) testGetChildren(t, 11, nil) testGetChildren(t, 2, nil) testGetChildren(t, 7, nil) @@ -495,11 +502,11 @@ func testForestApplySameOperation(t *testing.T, constructor func(t testing.TB, _ nodes, err := s.TreeGetChildren(ctx, cid, treeID, RootID) require.NoError(t, err) - require.Equal(t, []Node{1}, nodes) + require.Equal(t, []NodeInfo{{ID: 1, ParentID: RootID, Meta: meta[0]}}, nodes) nodes, err = s.TreeGetChildren(ctx, cid, treeID, 1) require.NoError(t, err) - require.Equal(t, []Node{2}, nodes) + require.Equal(t, []NodeInfo{{ID: 2, ParentID: 1, Meta: meta[1]}}, nodes) } t.Run("expected", func(t *testing.T) { diff --git a/pkg/local_object_storage/pilorama/inmemory.go b/pkg/local_object_storage/pilorama/inmemory.go index 1bde312a..c9f5df3b 100644 --- a/pkg/local_object_storage/pilorama/inmemory.go +++ b/pkg/local_object_storage/pilorama/inmemory.go @@ -68,10 +68,14 @@ func (s *memoryTree) Apply(op *Move) error { // do performs a single move operation on a tree. func (s *memoryTree) do(op *Move) move { + m := op.Meta + if m.Items == nil { + m.Items = []KeyValue{} + } lm := move{ Move: Move{ Parent: op.Parent, - Meta: op.Meta, + Meta: m, Child: op.Child, }, } @@ -91,7 +95,7 @@ func (s *memoryTree) do(op *Move) move { p.Meta.Time = op.Time } - p.Meta = op.Meta + p.Meta = m p.Parent = op.Parent s.tree.infoMap[op.Child] = p