forked from libp2p/go-libp2p-kad-dht
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlookup_test.go
36 lines (30 loc) · 831 Bytes
/
lookup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
}
}
}