mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-25 06:42:13 +00:00
37 lines
831 B
Go
37 lines
831 B
Go
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|