forked from TrueCloudLab/frostfs-node
[#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 <d.stepanov@yadro.com>
This commit is contained in:
parent
b4e72a2dfd
commit
af82c2865e
2 changed files with 19 additions and 8 deletions
|
@ -147,16 +147,23 @@ func testForestTreeGetChildren(t *testing.T, s Forest) {
|
||||||
treeAdd(t, 2, 0)
|
treeAdd(t, 2, 0)
|
||||||
treeAdd(t, 7, 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)
|
actual, err := s.TreeGetChildren(context.Background(), cid, treeID, nodeID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.ElementsMatch(t, expected, actual)
|
require.ElementsMatch(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
testGetChildren(t, 0, []uint64{10, 2, 7})
|
testGetChildren(t, 0, []NodeInfo{
|
||||||
testGetChildren(t, 10, []uint64{3, 6})
|
{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, 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, 11, nil)
|
||||||
testGetChildren(t, 2, nil)
|
testGetChildren(t, 2, nil)
|
||||||
testGetChildren(t, 7, 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)
|
nodes, err := s.TreeGetChildren(ctx, cid, treeID, RootID)
|
||||||
require.NoError(t, err)
|
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)
|
nodes, err = s.TreeGetChildren(ctx, cid, treeID, 1)
|
||||||
require.NoError(t, err)
|
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) {
|
t.Run("expected", func(t *testing.T) {
|
||||||
|
|
|
@ -68,10 +68,14 @@ func (s *memoryTree) Apply(op *Move) error {
|
||||||
|
|
||||||
// do performs a single move operation on a tree.
|
// do performs a single move operation on a tree.
|
||||||
func (s *memoryTree) do(op *Move) move {
|
func (s *memoryTree) do(op *Move) move {
|
||||||
|
m := op.Meta
|
||||||
|
if m.Items == nil {
|
||||||
|
m.Items = []KeyValue{}
|
||||||
|
}
|
||||||
lm := move{
|
lm := move{
|
||||||
Move: Move{
|
Move: Move{
|
||||||
Parent: op.Parent,
|
Parent: op.Parent,
|
||||||
Meta: op.Meta,
|
Meta: m,
|
||||||
Child: op.Child,
|
Child: op.Child,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -91,7 +95,7 @@ func (s *memoryTree) do(op *Move) move {
|
||||||
p.Meta.Time = op.Time
|
p.Meta.Time = op.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Meta = op.Meta
|
p.Meta = m
|
||||||
p.Parent = op.Parent
|
p.Parent = op.Parent
|
||||||
s.tree.infoMap[op.Child] = p
|
s.tree.infoMap[op.Child] = p
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue