Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traversal.Get function #65

Merged
merged 2 commits into from
Aug 22, 2020
Merged

Add traversal.Get function #65

merged 2 commits into from
Aug 22, 2020

Conversation

warpfork
Copy link
Collaborator

Add traversal.Get (and traversal.Progress.Get), two methods which take a Node and a Path, do a little walk, and return the reached Node.

This is a (long-overdue) helper function. It's the same functionality as has already been available through traversal.Focus, but returns values rather than taking a callback parameter, which is more convenient in some cases.

This new method also doesn't bother to accumulate Path and LastBlock info into an updated Progress object, because it doesn't return one. If the user wants the Progress info, they should continue to use Focus and a callback -- using a callback encourages clear handling of the scope of the Progress object, which should be desirable anyway.

traversal.Get doesn't quite work for call-chaining on its own, because it potentially needs to return an error, but composes nicely with other error-redirection systems like the must package: must.Node(traversal.Get(startNode, ipld.ParsePath("foo/bar"))).Kind() works, for example (substitute any call you wish to chain in place of .Kind()).

@@ -123,6 +123,26 @@ func TestFocusSingleTree(t *testing.T) {
})
}

// covers Get used on one already-loaded Node; no link-loading exercised.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test that exercises an attempt to traverse through a link might be good, it would at least show what would be expected to occur in such a situation, I imagine it's some error that bubbles up from the bowels of Link#Load()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll add another block of tests for that. It doesn't really increase coverage, because the Focus tests that do cover link traversal hit the same spot. But it's good to be explicit in tests. And it will serve as regression testing if we ever refactored the internals in such a way that the coverage wasn't redundant, which is imaginable.

Tests for the unhappy path... uuf. I think the error handling in this whole area is overdue for some review, honestly. It's very fmt.Errorf'y at the moment, which I do not much like.

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.
@warpfork
Copy link
Collaborator Author

Note/confession: The tests that cover the error paths here are asserting on the strings in the error message, rather than any well-typed information. I'd like to improve this soon -- In addition to the sheer principle of the matter, I'm writing some other tests today at an even higher level that use this package, and it's turning out deeply irritating to not have a more specific error type than *errors.errorString that I can either compose nor assert on -- but improving on this can be the subject of another PR.

@warpfork warpfork merged commit 46f2852 into master Aug 22, 2020
@warpfork warpfork deleted the traversal-get branch August 27, 2020 07:53
@warpfork warpfork mentioned this pull request Aug 27, 2020
@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants