-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Show similar library names in lib search #598
Conversation
Hi @BigHeadGeorge thanks for you contribution! |
Hi @BigHeadGeorge It seems that your last commit passes all the tests, but the commit history has some problems, can you try a rebase again? Maybe a Thanks again for contributing! |
Sorry for the messy commit history! This is my first time rebasing. I'll get it cleaned up real quick. |
74f71c7
to
8ff1f28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job with the rebase 😉 thanks!
I want to ask you if you could be so nice to add a unit test for the new logic you added.
It could be something similar to what we did for the debug
command (https://github.com/arduino/arduino-cli/blob/master/commands/debug/debug_test.go). You could proceed like this:
-
Extracting a function
searchLibrary(req *rpc.LibrarySearchReq ,lm *librariesmanager.LibrariesManager)
containing all the search code, and placing it in the same file (commands/lib/search.go
). -
Create a test function in
commands/lib/search_test.go
that use thesearchLibrary
function defined above, passing a customLibrariesManager
built using:
- the NewLibraryManager function
- a fake
library_index.json
placed in acommands/lib/testdata
folder.
Here an example of the test structure, I hope it helps a bit:
// file commands/lib/search_test.go
// ..imports..
// This test expects to find a `commands/lib/testdata` folder containing a fake librery_index.json
var customIndexPath = paths.New("testdata", "custom_lib_index")
func TestSearchLibrary(t *testing.T) {
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
lm.LoadIndex()
req := &rpc.LibrarySearchReq{
Instance: &rpc.Instance{Id: 1},
Query: (strings.Join(args, "--your test query-- ")),
}
resp, err := searchLibrary(req, lm)
// ...your asserts on the `resp` object...
Thanks again for your time!
commands/lib/search.go
Outdated
if len(res) == 0 { | ||
status = rpc.LibrarySearchStatus_failed | ||
for _, lib := range lm.Index.Libraries { | ||
if godice.CompareString(req.GetQuery(), lib.Name) > 0.7 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this 0.7
as package variable (see what we did here for example https://github.com/arduino/arduino-cli/blob/master/telemetry/telemetry.go#L31).
I think keeping it as a variable is sufficient, as I'm afraid that having it in the configuration file could create confusion.
Just check that the library names have "Test" in them instead of checking the names at each index, which won't always be the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is High Quality Contributing ™️ !
FYI, I had to re-run tests for your last commit, because we have a flaky integration test in the telemetry
part that we need to take care of.
Excellent work with the testing part!
Thanks for the help throughout the process (especially the rebase, kinda panicked when I saw 20 unrelated commits in my PR) |
Closes #107
Small typos when searching for libraries will show similar library names instead of showing no results.
Emphasis on "small", though, because the similarity value check is hard-coded at a value that's a little strict (maybe this could be a config option?).