forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ipfs#108 from libp2p/fix/loggable-key
handle paths as DHT keys
- Loading branch information
Showing
3 changed files
with
67 additions
and
6 deletions.
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,36 @@ | ||
package dht | ||
|
||
import ( | ||
"testing" | ||
|
||
cid "github.com/ipfs/go-cid" | ||
) | ||
|
||
func TestLoggableKey(t *testing.T) { | ||
c, err := cid.Decode("QmfUvYQhL2GinafMbPDYz7VFoZv4iiuLuR33aRsPurXGag") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
k, err := tryFormatLoggableKey("/proto/" + string(c.Bytes())) | ||
if err != nil { | ||
t.Errorf("failed to format key 1: %s", err) | ||
} | ||
if k != "/proto/"+c.String() { | ||
t.Error("expected path to be preserved as a loggable key") | ||
} | ||
|
||
k, err = tryFormatLoggableKey(string(c.Bytes())) | ||
if err != nil { | ||
t.Errorf("failed to format key 2: %s", err) | ||
} | ||
if k != "/provider/"+c.String() { | ||
t.Error("expected cid to be formatted as a loggable key") | ||
} | ||
|
||
for _, s := range []string{"bla bla", "/bla", "/bla/asdf", ""} { | ||
if _, err := tryFormatLoggableKey(s); err == nil { | ||
t.Errorf("expected to fail formatting: %s", s) | ||
} | ||
} | ||
} |