Commit 76ca1050 authored by hannahhoward's avatar hannahhoward

feat(traversal): add LastBlock progress info

Properly record last block traversed
parent 2864b8df
...@@ -69,6 +69,9 @@ func (tp TraversalProgress) traverseAll(n ipld.Node, s selector.Selector, fn Adv ...@@ -69,6 +69,9 @@ func (tp TraversalProgress) traverseAll(n ipld.Node, s selector.Selector, fn Adv
tpNext := tp tpNext := tp
tpNext.Path = tp.Path.AppendSegment(ps.String()) tpNext.Path = tp.Path.AppendSegment(ps.String())
if v.ReprKind() == ipld.ReprKind_Link { if v.ReprKind() == ipld.ReprKind_Link {
lnk, _ := v.AsLink()
tpNext.LastBlock.Path = tpNext.Path
tpNext.LastBlock.Link = lnk
v, err = tpNext.loadLink(v, n) v, err = tpNext.loadLink(v, n)
if err != nil { if err != nil {
return err return err
...@@ -96,6 +99,9 @@ func (tp TraversalProgress) traverseSelective(n ipld.Node, attn []selector.PathS ...@@ -96,6 +99,9 @@ func (tp TraversalProgress) traverseSelective(n ipld.Node, attn []selector.PathS
tpNext := tp tpNext := tp
tpNext.Path = tp.Path.AppendSegment(ps.String()) tpNext.Path = tp.Path.AppendSegment(ps.String())
if v.ReprKind() == ipld.ReprKind_Link { if v.ReprKind() == ipld.ReprKind_Link {
lnk, _ := v.AsLink()
tpNext.LastBlock.Path = tpNext.Path
tpNext.LastBlock.Link = lnk
v, err = tpNext.loadLink(v, n) v, err = tpNext.loadLink(v, n)
if err != nil { if err != nil {
return err return err
......
...@@ -145,6 +145,9 @@ func TestTraverse(t *testing.T) { ...@@ -145,6 +145,9 @@ func TestTraverse(t *testing.T) {
case 4: case 4:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "nested/alink") Wish(t, tp.Path.String(), ShouldEqual, "nested/alink")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "nested/alink")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 5: case 5:
Wish(t, n, ShouldEqual, fnb.CreateString("zoo")) Wish(t, n, ShouldEqual, fnb.CreateString("zoo"))
Wish(t, tp.Path.String(), ShouldEqual, "nested/nonlink") Wish(t, tp.Path.String(), ShouldEqual, "nested/nonlink")
...@@ -170,12 +173,18 @@ func TestTraverse(t *testing.T) { ...@@ -170,12 +173,18 @@ func TestTraverse(t *testing.T) {
case 0: case 0:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "0") Wish(t, tp.Path.String(), ShouldEqual, "0")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "0")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 1: case 1:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "1") Wish(t, tp.Path.String(), ShouldEqual, "1")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "1")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 2: case 2:
Wish(t, n, ShouldEqual, fnb.CreateString("beta")) Wish(t, n, ShouldEqual, fnb.CreateString("beta"))
Wish(t, tp.Path.String(), ShouldEqual, "2") Wish(t, tp.Path.String(), ShouldEqual, "2")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "2")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafBetaLnk.String())
} }
order++ order++
return nil return nil
...@@ -206,24 +215,38 @@ func TestTraverse(t *testing.T) { ...@@ -206,24 +215,38 @@ func TestTraverse(t *testing.T) {
case 0: case 0:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedList/0") Wish(t, tp.Path.String(), ShouldEqual, "linkedList/0")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedList/0")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 1: case 1:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedList/1") Wish(t, tp.Path.String(), ShouldEqual, "linkedList/1")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedList/1")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 2: case 2:
Wish(t, n, ShouldEqual, fnb.CreateString("beta")) Wish(t, n, ShouldEqual, fnb.CreateString("beta"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedList/2") Wish(t, tp.Path.String(), ShouldEqual, "linkedList/2")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedList/2")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafBetaLnk.String())
case 3: case 3:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedList/3") Wish(t, tp.Path.String(), ShouldEqual, "linkedList/3")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedList/3")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
case 4: case 4:
Wish(t, n, ShouldEqual, fnb.CreateBool(true)) Wish(t, n, ShouldEqual, fnb.CreateBool(true))
Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/foo") Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/foo")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedMap")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, middleMapNodeLnk.String())
case 5: case 5:
Wish(t, n, ShouldEqual, fnb.CreateString("zoo")) Wish(t, n, ShouldEqual, fnb.CreateString("zoo"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/nested/nonlink") Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/nested/nonlink")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedMap")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, middleMapNodeLnk.String())
case 6: case 6:
Wish(t, n, ShouldEqual, fnb.CreateString("alpha")) Wish(t, n, ShouldEqual, fnb.CreateString("alpha"))
Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/nested/alink") Wish(t, tp.Path.String(), ShouldEqual, "linkedMap/nested/alink")
Wish(t, tp.LastBlock.Path.String(), ShouldEqual, "linkedMap/nested/alink")
Wish(t, tp.LastBlock.Link.String(), ShouldEqual, leafAlphaLnk.String())
} }
order++ order++
return nil return nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment