Commit 0ab9c70f authored by Eric Myhre's avatar Eric Myhre

Also test traversal.Get linkloader configuration.

This doesn't add much in the way of coverage, since it's internally
quickly convergenced with what the Focus tests cover, but in testing,
explicitness is good.
parent 5dfad59f
......@@ -180,3 +180,30 @@ func TestFocusWithLinkLoading(t *testing.T) {
Wish(t, err, ShouldEqual, nil)
})
}
func TestGetWithLinkLoading(t *testing.T) {
t.Run("link traversal with no configured loader should fail", func(t *testing.T) {
t.Run("terminal link should fail", func(t *testing.T) {
_, err := traversal.Get(middleMapNode, ipld.ParsePath("nested/alink"))
Wish(t, err.Error(), ShouldEqual, `error traversing node at "nested/alink": could not load link "`+leafAlphaLnk.String()+`": no LinkTargetNodePrototypeChooser configured`)
})
t.Run("mid-path link should fail", func(t *testing.T) {
_, err := traversal.Get(rootNode, ipld.ParsePath("linkedMap/nested/nonlink"))
Wish(t, err.Error(), ShouldEqual, `error traversing node at "linkedMap": could not load link "`+middleMapNodeLnk.String()+`": no LinkTargetNodePrototypeChooser configured`)
})
})
t.Run("link traversal with loader should work", func(t *testing.T) {
n, err := traversal.Progress{
Cfg: &traversal.Config{
LinkLoader: func(lnk ipld.Link, _ ipld.LinkContext) (io.Reader, error) {
return bytes.NewBuffer(storage[lnk]), nil
},
LinkTargetNodePrototypeChooser: func(_ ipld.Link, _ ipld.LinkContext) (ipld.NodePrototype, error) {
return basicnode.Prototype__Any{}, nil
},
},
}.Get(rootNode, ipld.ParsePath("linkedMap/nested/nonlink"))
Wish(t, err, ShouldEqual, nil)
Wish(t, n, ShouldEqual, basicnode.NewString("zoo"))
})
}
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