Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
test: add test that ResolveToLastNode does not perform unncessary fet…
Browse files Browse the repository at this point in the history
…ches
  • Loading branch information
aschmahmann committed Aug 26, 2020
1 parent ac811c4 commit 6d87ec0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 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 6d87ec0

Please sign in to comment.