Skip to content

Commit

Permalink
test: add test that ResolveToLastNode does not perform unncessary fet…
Browse files Browse the repository at this point in the history
…ches

This commit was moved from ipfs/go-path@6d87ec0
  • Loading branch information
aschmahmann committed Aug 26, 2020
1 parent 2aa5ac6 commit 35e8ffb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions path/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,43 @@ func TestRecurivePathResolution(t *testing.T) {
p.String(), rCid.String(), cKey.String()))
}
}

func TestResolveToLastNode_NoUnnecessaryFetching(t *testing.T) {
ctx := context.Background()
dagService := dagmock.Mock()

a := randNode()
b := randNode()

err := a.AddNodeLink("child", b)
if err != nil {
t.Fatal(err)
}

err = dagService.Add(ctx, a)
if err != nil {
t.Fatal(err)
}

aKey := a.Cid()

segments := []string{aKey.String(), "child"}
p, err := path.FromSegments("/ipfs/", segments...)
if err != nil {
t.Fatal(err)
}

resolver := resolver.NewBasicResolver(dagService)
resolvedCID, remainingPath, err := resolver.ResolveToLastNode(ctx, p)
if err != nil {
t.Fatal(err)
}

if len(remainingPath) > 0 {
t.Fatal("cannot have remaining path")
}

if !resolvedCID.Equals(b.Cid()) {
t.Fatal("resolved to the wrong CID")
}
}

0 comments on commit 35e8ffb

Please sign in to comment.