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 acc3a89 commit 5cb05e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/ipfs/go-path

go 1.14

require (
github.com/ipfs/go-cid v0.0.2
github.com/ipfs/go-ipld-format v0.0.2
Expand Down
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 5cb05e7

Please sign in to comment.