-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Swarm discovery on the gateway (readonly) interface #3540
Closed
wigy-opensource-developer
wants to merge
2
commits into
ipfs:master
from
Fermat-ORG:feat/swarm_discover
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package commands | ||
|
||
import ( | ||
"testing" | ||
"sort" | ||
) | ||
|
||
func TestShuffleEmpty(t *testing.T) { | ||
actual := shuffle(0, 3) | ||
assertLen(t, actual, 0) | ||
} | ||
|
||
func TestShuffleSingle(t *testing.T) { | ||
actual := shuffle(1, 3) | ||
assertLen(t, actual, 1) | ||
if actual[0] != 0 { | ||
t.Errorf("Expected 0 as the only value, but got %d", actual[0]) | ||
} | ||
} | ||
|
||
func TestShuffleUnique(t *testing.T) { | ||
actual := shuffle(100, 100) | ||
assertLen(t, actual, 100) | ||
sort.Ints(actual) | ||
for i, v := range actual { | ||
if i != v { | ||
t.Fatalf("Not each value is present exactly once") | ||
} | ||
} | ||
} | ||
|
||
func assertLen(t *testing.T, actual []int, expected int) { | ||
actualLen := len(actual) | ||
if actualLen != expected { | ||
t.Error("Expected a slice with %d items, but got %d", expected, actualLen) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should probably be
getOnlineNode
or something, and lets go ahead and return the errors and handle them in the caller.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.
When I see copy-paste, I have the urge to extract and name the thing. Since all commands in this file wanted an online node and handled the error the same way, this seemed to be the logical step to reduce coupling. I even played with the idea to look further into other commands and introduce a middle-man on the req itself, but I stopped myself.
I can get rid of the res parameter, but then I would return
(*core.IpfsNode, *commands.Error)
and add afunc (*commands.response) SetError(*Error)
if that is fine with you.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.
just use a regular error for that.
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.
I cannot. The 2 errors need different commands.ErrorType set. So I either
(*core.IpfsNode, commands.ErrorType, error)
.Alternatively I inline this method back and wash my hands in innocence.