]> Sergey Matveev's repositories - btrtrc.git/commitdiff
dht: Revive the UnmarshalGetPeersResponse test
authorMatt Joiner <anacrolix@gmail.com>
Mon, 17 Aug 2015 16:08:08 +0000 (02:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 17 Aug 2015 16:08:08 +0000 (02:08 +1000)
dht/dht_test.go

index e158346024c48c676a94983e1823cfd2b173df8c..6636ad6f252a3a702744c564936f1764b505040a 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "github.com/anacrolix/missinggo"
+       "github.com/stretchr/testify/assert"
 )
 
 func TestSetNilBigInt(t *testing.T) {
@@ -104,25 +105,16 @@ func TestClosestNodes(t *testing.T) {
        }
 }
 
-// func TestUnmarshalGetPeersResponse(t *testing.T) {
-//     var gpr getPeersResponse
-//     if err != nil {
-//             t.Fatal(err)
-//     }
-//     err = dec.Decode(map[string]interface{}{
-//             "values": []string{"\x01\x02\x03\x04\x05\x06", "\x07\x08\x09\x0a\x0b\x0c"},
-//             "nodes":  "\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d",
-//     })
-//     if err != nil {
-//             t.Fatal(err)
-//     }
-//     if len(gpr.Values) != 2 {
-//             t.FailNow()
-//     }
-//     if len(gpr.Nodes) != 2 {
-//             t.FailNow()
-//     }
-// }
+func TestUnmarshalGetPeersResponse(t *testing.T) {
+       gpr := Msg{
+               "r": map[string]interface{}{
+                       "values": []interface{}{"\x01\x02\x03\x04\x05\x06", "\x07\x08\x09\x0a\x0b\x0c"},
+                       "nodes":  "\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x02\x03\x04\x05\x06\x07\x08\x09\x02\x03\x04\x05\x06\x07" + "\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x02\x03\x04\x05\x06\x07\x08\x09\x02\x03\x04\x05\x06\x07",
+               },
+       }
+       assert.EqualValues(t, 2, len(gpr.Values()))
+       assert.EqualValues(t, 2, len(gpr.Nodes()))
+}
 
 func TestDHTDefaultConfig(t *testing.T) {
        s, err := NewServer(nil)