aboutsummaryrefslogtreecommitdiff
path: root/krpc/krpc_test.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2018-02-21 04:20:06 +0000
committerFelix Hanley <felix@userspace.com.au>2018-02-21 04:21:39 +0000
commite9adf3a2bf8b81615275a6705b7957e43753f0ec (patch)
tree1eaeb5081f3914a8ffa936d96ad1f1548c9aeb2f /krpc/krpc_test.go
parent020a8f9ec7e541d284ddb65111aafe42547927e5 (diff)
downloaddhtsearch-e9adf3a2bf8b81615275a6705b7957e43753f0ec.tar.gz
dhtsearch-e9adf3a2bf8b81615275a6705b7957e43753f0ec.tar.bz2
Seperate shared packages
Diffstat (limited to 'krpc/krpc_test.go')
-rw-r--r--krpc/krpc_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/krpc/krpc_test.go b/krpc/krpc_test.go
new file mode 100644
index 0000000..c46d70c
--- /dev/null
+++ b/krpc/krpc_test.go
@@ -0,0 +1,30 @@
+package krpc
+
+import (
+ "encoding/hex"
+ "testing"
+)
+
+func TestCompactNodeAddr(t *testing.T) {
+
+ tests := []struct {
+ in string
+ out string
+ }{
+ {in: "192.168.1.1:6881", out: "c0a801011ae1"},
+ {in: "[2001:9372:434a:800::2]:6881", out: "20019372434a080000000000000000021ae1"},
+ }
+
+ for _, tt := range tests {
+ r := encodeCompactNodeAddr(tt.in)
+ out, _ := hex.DecodeString(tt.out)
+ if r != string(out) {
+ t.Errorf("encodeCompactNodeAddr(%s) => %x, expected %s", tt.in, r, tt.out)
+ }
+
+ s := decodeCompactNodeAddr(r)
+ if s != tt.in {
+ t.Errorf("decodeCompactNodeAddr(%x) => %s, expected %s", r, s, tt.in)
+ }
+ }
+}