aboutsummaryrefslogtreecommitdiff
path: root/dht/infohash_test.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2018-02-09 08:42:22 +0000
committerFelix Hanley <felix@userspace.com.au>2018-02-09 08:42:22 +0000
commit2ded0704c8f675c3d92cf2b4874a32c65faf2553 (patch)
treec3b437cbe7129ea300d7a98e438b0f5fd3fd8344 /dht/infohash_test.go
parentbe4f4b36cc7fb46c70364d524d64c7188c1ae0f3 (diff)
downloaddhtsearch-2ded0704c8f675c3d92cf2b4874a32c65faf2553.tar.gz
dhtsearch-2ded0704c8f675c3d92cf2b4874a32c65faf2553.tar.bz2
Basic DHT functions
Diffstat (limited to 'dht/infohash_test.go')
-rw-r--r--dht/infohash_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/dht/infohash_test.go b/dht/infohash_test.go
new file mode 100644
index 0000000..b3223f4
--- /dev/null
+++ b/dht/infohash_test.go
@@ -0,0 +1,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))
+ }
+}