]> Sergey Matveev's repositories - btrtrc.git/commitdiff
metainfo: Ensure that nodes encode correctly
authorMatt Joiner <anacrolix@gmail.com>
Tue, 23 Feb 2016 11:37:38 +0000 (22:37 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 23 Feb 2016 11:37:38 +0000 (22:37 +1100)
metainfo/nodes_test.go

index 9a76e1377dc687a2a4c867166eb5860cc500e471..585120b76f23f9405fa13b071524c738252497da 100644 (file)
@@ -5,6 +5,8 @@ import (
 
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
+
+       "github.com/anacrolix/torrent/bencode"
 )
 
 func testFileNodesMatch(t *testing.T, file string, nodes []Node) {
@@ -38,3 +40,16 @@ func TestNodesListPairsBEP5(t *testing.T) {
                "83.128.223.71:23865",
        })
 }
+
+func testMarshalMetainfo(t *testing.T, expected string, mi MetaInfo) {
+       b, err := bencode.Marshal(mi)
+       assert.NoError(t, err)
+       assert.EqualValues(t, expected, string(b))
+}
+
+func TestMarshalMetainfoNodes(t *testing.T) {
+       testMarshalMetainfo(t, "d4:infod4:name0:12:piece lengthi0e6:piecesleee", MetaInfo{})
+       testMarshalMetainfo(t, "d4:infod4:name0:12:piece lengthi0e6:pieceslee5:nodesl12:1.2.3.4:555514:not a hostportee", MetaInfo{
+               Nodes: []Node{"1.2.3.4:5555", "not a hostport"},
+       })
+}