blob: b3223f4b4b313999adb0e47a43b90338fa2759c3 (
plain)
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
|
package dht
import (
"encoding/hex"
"testing"
)
func TestInfohashImport(t *testing.T) {
var ih Infohash
idHex := "5a3ce1c14e7a08645677bbd1cfe7d8f956d53256"
err := ih.FromString(idHex)
if err != nil {
t.Errorf("FromString failed with %s", err)
}
idBytes, err := hex.DecodeString(idHex)
ih2 := Infohash(idBytes)
if !ih.Equal(ih2) {
t.Errorf("expected %s to equal %s", ih, ih2)
}
}
func TestInfohashLength(t *testing.T) {
ih := randomInfoHash()
if len(ih) != 20 {
t.Errorf("%s as string should be length 20, got %d", ih, len(ih))
}
}
|