Skip to content

Commit

Permalink
fix(tests): fix tests for ipld update
Browse files Browse the repository at this point in the history
This commit was moved from ipfs/go-fetcher@ef6ef50
  • Loading branch information
hannahhoward committed Aug 12, 2021
1 parent f066909 commit 49cba97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fetcher/helpers/block_visitor_test.go
Expand Up @@ -88,8 +88,8 @@ func TestFetchGraphToUniqueBlocks(t *testing.T) {
na.AssembleEntry("foo").AssignBool(true)
na.AssembleEntry("bar").AssignBool(false)
na.AssembleEntry("nested").CreateMap(2, func(na fluent.MapAssembler) {
na.AssembleEntry("link3").AssignLink(link3)
na.AssembleEntry("link2").AssignLink(link2)
na.AssembleEntry("link3").AssignLink(link3)
na.AssembleEntry("nonlink").AssignString("zoo")
})
}))
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestFetchGraphToUniqueBlocks(t *testing.T) {
}))
require.NoError(t, err)

assertBlocksInOrder(t, results, 3, map[int]ipld.Node{0: node1, 1: node3, 2: node2})
assertBlocksInOrder(t, results, 3, map[int]ipld.Node{0: node1, 1: node2, 2: node3})
}

func assertBlocksInOrder(t *testing.T, results []helpers.BlockResult, nodeCount int, nodes map[int]ipld.Node) {
Expand Down
9 changes: 8 additions & 1 deletion fetcher/testutil/testutil.go
Expand Up @@ -24,6 +24,9 @@ func EncodeBlock(n ipld.Node) (blocks.Block, ipld.Node, ipld.Link) {
MhType: 0x17,
MhLength: 20,
}}
ls.StorageReadOpener = func(ipld.LinkContext, ipld.Link) (io.Reader, error) {
return bytes.NewReader(b.RawData()), nil
}
ls.StorageWriteOpener = func(ipld.LinkContext) (io.Writer, ipld.BlockWriteCommitter, error) {
buf := bytes.Buffer{}
return &buf, func(lnk ipld.Link) error {
Expand All @@ -40,5 +43,9 @@ func EncodeBlock(n ipld.Node) (blocks.Block, ipld.Node, ipld.Link) {
if err != nil {
panic(err)
}
return b, n, lnk
ln, err := ls.Load(ipld.LinkContext{}, lnk, n.Prototype())
if err != nil {
panic(err)
}
return b, ln, lnk
}

0 comments on commit 49cba97

Please sign in to comment.